Tag Info

New answers tagged

0

You can do this with cp and rm, but without copying the massive amount of data you are (presumably) trying to avoid transferring. @mattdm alluded to this in his comment, and an answer for another question has a more complete discussion about various options. cp -rl source destination rm -r source Essentially, the -l option for the cp command creates hard ...


0

If your number 4 is place always on 5th field then with awk you can add newline it: $ awk 'BEGIN{FS=OFS="|"}$5="\n"$5' file John|freshman|seatle|math| 4|fulltime Bob|senior|Tacoma|biology| 4|part-time


1

You could use sed: sed -i 's/|4|/|\n4|/' file.txt This will replace |4| with |\n4| (i.e. a vertical bar, a newline, and then 4|).


2

Use [!x]txt to list all files ending in txt but exclude the ones ending in xtxt: ls *[!x]txt or use ASCII code for dot, e.g.: ls *$'\x2E'txt or ls *$'\056'txt


2

If you are using the Bash shell: shopt -s extglob ls !(*xtxt|*bak|*bat)


1

Extremely ugly, since this could be achieved using find . -type f -name "*.txt" easily, but if you don't want to put an . in there, and the only file extensions you are going to find in that directory are .bat, .bak, .txt, and .xtxt, then you can try this: ls *txt | grep -v "xtxt$" ls *txt will bring anything ending with txt, and grep -v "xtxt$" will ...


2

I don't understand why you don't want to use .. Anyway you can use some character class instead where . is included, but other chars from your directory not, good candidate for this purpose can be [[:punct:]]: LC_ALL=C ls -- *[[:punct:]]txt I changed locale to C as character classes depend on that, and added -- to ls option in order to list all files ...


-1

To search $Id$ in a file : you can use : grep '\$id*' filename


0

Assuming your are on a Linux system, or at least that you have GNU touch and GNU date, you can do (in bash): $ shopt globstar $ for f in **; do touch -d "$(date -d "$(stat -c '%y' "$f") +3 months")" "$f" done That, however, will ignore hidden files. To match those as well, run shopt -s dotglob before the above commands. Explanation shopt -s ...


0

From the description of the problem I believe you are looking for the tool which can get time of last file modification and then add 3 months to it. You can do it with stat + touch + some shell arithmetic evaluation. For example to add 90 days to file timestamp you can write touch -d "@$(( $(stat -c '%Y' file) + 90*24*3600 ))" file Then just loop over all ...


0

I would use the -exec of find - a oneliner. find $HIGHEST_FOLDER -type f -name '*.*' -exec touch -ram {} -F 7776000 {} \; Quote *.*, otherwise find will take filenames from the current directory and fail. Finally, you MUST specify \;, backslash followed by semi-colon, -exec mandates this. the {} is the current file find found. In your loop above, you ...


3

I think your executable file just prints a to the screen. When you write $COMMAND, file executed and the output tried to be executed again.Because it cannot execute a command, it gives an error. You can use just simply $COMMAND or echo `$COMMAND`


2

With zsh: vi ./**/*_test.mov(.s:_test.mov:_info.txt:)


1

You can use cut to remove unwanted columns. From the man page: -d, --delimiter=DELIM use DELIM instead of TAB for field delimiter -f, --fields=LIST select only these fields; also print any line that contains no delimiter character, unless the -s option is specified --complement complement the set of ...


0

You need something like find . -name "*.mov" -exec grep test {} + | sed -n 's/^\([^:]*\):.*$/\1/p' | xargs -d \\n -n 1 $EDITOR for opening one file at a time or find . -name "*.mov" -exec grep test {} + | sed -n 's/^\([^:]*\):.*$/\1/p' | xargs -d \\n $EDITOR for opening them simultaneously (assuming the file names do not contain a colon)


2

A simple loop will do the trick. cd working for dir in */*/; do [ -e "$dir/files.zip" ] || # skip directories where the zip already exists ( cd -- "$dir" && zip -r files.zip .) done Note that zip is smart enough to skip the zip file that is being built when recursing in that directory. Some other archiving programs would attempt to stuff the ...


4

Should I output to a temporary file, then copy it over the final file only if the backup works? Not copy but rename. But this is impossible for the backup script if it writes to stdout. It cannot even prevent the empty file from being created as that has already happened when the script starts. This must be done from the outside. if ./script.sh ...


0

what grep :0:0: /etc/passwd | sudo sed 's_/bin/bash_/sbin/nologin_' /etc/passwd do ? grep :0:0: /etc/passwd search for line(s ?) with uid/gid being 0, this usualy give the line with root, this line is feeded to STDOUT (standard output ) | output from grep is feed to sudo sed which is discarded due to a file being specified in command line. sed ...


1

1. get a acount which is a sudoer su - echo 'YOU ALL=(ALL:ALL) ALL'>/etc/sudoers exit 2. disable the root account sudo usermod --expiredate 1 root 3. test it $ su - Password: <correct password> Your account is expired. Tested on Debian GNU/Linux


2

There is nothing wrong with that syntax if the shell supports arrays. Most likely the script starts with #!/bin/sh and wrongly uses specific shell features such as bash. If the shebang is #!/bin/sh, change it to #!/bin/bash and report the problem to the CINT developers.


1

From wget manual: ‘--user=user’ ‘--password=password’ Specify the username user and password password for both FTP and HTTP file retrieval. These parameters can be overridden using the ‘--ftp-user’ and ‘--ftp-password’ options for FTP connections and the ‘--http-user’ and ‘--http-password’ options for HTTP connections. So what you ...


4

The fc built-in command allows you to extract commands from the history using a number of criteria (see man zshbuiltins for details). fc stands for “fix command”, and when invoked with no parameters it opens an editor with the last command entered. You can use all your editor’s features to change the command, and when you save and exit zsh runs the fixed ...


0

Correction by @jimmij originally I wrote this with the wrong shell in mind (bash instead of zsh). the below reflects the corrected code From this stackoverflow answer: history | cut -c 8- And further, to restrict history back a certain number of lines, run history -<number of lines> (history -20 prints the last 20 entries) Finally: history -20 ...


1

With awk, it's awk -F '|' -v OFS='|' '{sub(/^.../, "& ", $4); print}' file But that cannot edit in-place, so you have to: t=$(mktemp) awk -F '|' -v OFS='|' '{sub(/^.../, "& ", $4); print}' file > "$t" && mv "$t" file With sed, sed -i 's/^[^|]*|[^|]*|[^|]*|.../& /' file If you want to validate the postal code, then sed -i ...


1

Hmm... Seems like you could take better advantage of the --format argument here to use --printf instead and just pass the lot over a pipe. Also, your if...fi is a compound command - it can take a redirect which all contained commands will inherit, so maybe you don't need to nest the heredoc at all. if [ "$diffLines" = 1 ] then stat --printf "Last ...


0

The other method would be herestrings: mail_content="Last Change: $dateLastChanged This is an automated warning of stale data for the UNC-G Blackboard Snapshot process." mailx -r "Systems and Operations <sysadmin@[redacted].edu>" -s "Warning Stale BB Data" jadavis6@[redacted].edu <<<"$mail_content"


2

I'm afraid there's no portable solution especially if you want to consider variables with no value part or duplicate variables. On a recent GNU system: env -0 | grep -z '^T' | tr '\0' '\n'


1

You don't need to use any >> Just type env | grep ^T.


1

super - execute commands setuid root.


1

You should use the serial device much like a normal file. The only difference is that it needs some ioctl()s to do the speed and control line setup. So don't use os.system("echo ... but f = open('/dev/ttyUSB3', 'rw') and then f.write() and f.read(). In theory you could use ioctl() to set the speed and so on, but at that stage it's simply easier to use ...


0

The general approach is to read the file names from the archive (unless they are always the same) and then have tar extract only one file at a time. GNU tar has the option --to-stdout which prevents it from writing a file. Without that you would need a FIFO for each file name. > tar -tf subdir.tar.gz R1.fastq R1.fastq tar -xf subdir.tar.gz --to-stdout ...


0

Assuming you have to permissions to (or can convince your SysAdmin), I suggest looking into tmux which is a terminal multiplexer. Tmux allows you to do everything you are talking about and more. You can have it manage all your windows and just detach your session when done. Picking up were you left off is as easy as reattaching to your detached session (one ...


0

The $f/*.fastq doesn't match anything by the time that line gets invoked. But the major problem is that tar doesn't extract to stdout, it creates files (there would need to be some way to tell the 'receiving' on the other end of the pipe that one file ends and the other starts, and there isn't at least not with tar). So when using tar you have to let tar ...


2

The code in question doesn't actually depend on /dev/tcp existing on a filesystem. Rather, it is a feature of Bash itself. For example, if you write a simple HTTP request to file descriptor 3 in your example, you should get a response: > ls /dev/tcp ls: /dev/tcp: No such file or directory > exec 3<>/dev/tcp/google.com/80 > echo -e "GET / ...


3

Here is a solution using extremely simple bash commands. find . -maxdepth 1 -type f | sort | tail -n 4 | while read -r file; do cp "$file" ~/; done Explanation: find . -maxdepth 1 -type f Finds all files in current directory. sort Sorts alphabetically. tail -n 4 Only show last 4 lines. while read -r file; do cp "$file" ~/; done Loops over each ...


2

If you are using the console ttys (/dev/tty1 through /dev/tty7) in text mode you can read the screen buffer directly from the corresponding /dev/vcsN device. You have to know that there are 80 characters per line, so simple maths to convert an (x,y) coordinate to offset (y*80 + x) will get you the desired character. #!/bin/bash # Ranges are 1-80, 1-24 # ...


-1

Create the string as a variable and pass that variable to curl. string="${WEBSITE_URL}/ACTION_NAME/ACTION1;id=${ID}?Command=TEST&id1=${ID1}&id2=${ID2}&id3=${ID3}" echo $string #this should get the right string to be passed to curl curl -X GET $string


1

Due to all help, I could find out how to fix this. The main issue is due to the UTF-8 encoding, the server didn't have it configured as said in comments. Quoting comments: [@Rmano]: In UTF-8 ñ is a two-bytes char [@jimmij]: backspace character for some reason deletes only one of them [@aecolley]: Try setting the environment variable LANG to C.UTF-8 ...


0

read modem_output < /dev/ttyUSB3


0

bash uses all characters after $ which are valid in a variable name to determine the name i.e. the first illegal char limits the name string. In case of doubt ${Variable} should be used. You already mention that so your problem must be something different.


5

So long as you find the shell sort agreeable, you can just do: set -- /path/to/source/dir/* [ "$#" -le 4 ] || shift "$(($#-4))" cp "$@" /path/to/target/dir This is very similar to the bash-specific array solution offered, but should be portable to any POSIX-compatible shell. Some notes about both methods: It is important that you lead your cp arguments ...


7

If you are using zsh you can enclose in parenthesis () a list of so called glob qualifiers which select desired files. In your case, that would be cp *(On[1,4]) ~/ Here On sorts file names alphabetically in reverse order and [1,4] takes only first 4 of them. You can make this more robust by selecting only plain files (excluding directories, pipes etc.) ...


19

This can be easily done with bash/ksh93/zsh arrays: a=(*) cp -- "${a[@]: -4}" ~/ This works for all non-hidden file names even if they contain spaces, tabs, newlines, or other difficult characters (assuming there are at least 4 non-hidden files in the current directory with bash). How it works a=(*) This creates an array a with all the file names. ...


3

If there are only files and their names do not contain whitespace or newline (and you've not modified $IFS) or glob characters (or some non-printable characters with some implementations of ls), and don't start with ., then you can do this: cp -- $(ls | tail -n 4) ~/


10

Sometimes an alias isn't powerful enough to easily do what you want, so here's a way without using them. In some file that is sourced when your shell starts (e.g. .bashrc), add the following function: ls () { echo "Hello world!" command ls } Unlike an alias, a function can recurse. That's why command ls is used instead of ls; it tells your shell ...


8

The machine in this picture is a (video) terminal, more specifically a VT100 by Digital Research. Decades ago when computers were big, instead of having personal computers for each user, they could have had a terminal, a dummy device with display and keyboard, that is connected to a main computer via a cable. A VT100 is not a computer, but just a keyboard ...


8

You must not forget to call ls: alias ls='echo "Hello World!"; ls'


3

Compare also: echo '.*[s]' file with echo .*[s] file This outputs the arguments as seen by the command. In your first example you pass your grep command exactly two arguments: the pattern and the file. In your second example your shell will handle the first argument and replace it with all the files starting with a dot and ending in "s". Therefore ...


4

Quotes (either single or double) around an argument inhibit glob expansion. Your first example passes a Regular Expression as an argument to grep. Your second example contains a glob pattern which the shell itself expands, passing filenames that fit that pattern as arguments to grep.



Top 50 recent answers are included