Tag Info

Hot answers tagged

33

You should use the at command: $ sudo at 6:45 [sudo] password for root: warning: commands will be executed using /bin/sh at> poweroff at> <EOT> Don't type the <EOT>, but press Ctrl+D at the second at> prompt. The significant advantage of using at over using shutdown with a TIME argument, is that it involves real, persistent, ...


19

You can use shutdown: sudo shutdown -h 06:45 & And to check it: ps -aux | grep shutdown If you want to cancel it: sudo shutdown -c This assumes of course that the shutdown time has already passed.


9

I think this should do it: tar -xzf file.tar.gz -C ~/locationX folder1 -C ~/locationY folder2 The -C option means to change to the specified directory before doing the extraction. Specifying filename arguments after the tarfile name restricts the extraction to just those files or directories. And you can repeat this -Changing directories as you do. Note ...


4

There is a --max-size option to rsync which will exclude files from over a certain size from being copied from one directory to another. From the man page; --max-size=SIZE This tells rsync to avoid transferring any file that is larger than the specified SIZE. The SIZE value can be suffixed with a string to indicate a size multiplier, and may be a ...


4

Using ImageMagick: $ convert -crop 800x1000 image.png cropped_%d.png Will create a sequence of files named cropped_1.png, cropped_2.png, and so on. References Tile Cropping, sub-dividing one image into multiple images ImageMagick v6 Examples -- Cutting and Bordering


4

If you have two zip files a.zip and b.zip in your current directory, then $ cp *.zip destination/ expands to $ cp a.zip b.zip destination/ The semantics for cp is to copy both a.zip and b.zip to destination. If you type $ cp \*.zip destination/ it simply "expands" to $ cp '*.zip' destination/ i.e. it will try to copy a single file named "*.zip" ...


4

No, it's not correct. I have no idea what the \1{3} is supposed to be but that's what is causing you problems. If you want to find lines that contain three repeated characters followed by three other repeated characters, you can use this: grep -E '([a-z])\1{2}([a-z])\2{2}' The \1 refers to the first captured group. You can capture groups by using ...


3

NAME chvt - change foreground virtual terminal SYNOPSIS chvt N DESCRIPTION The command chvt N makes /dev/ttyN the foreground terminal. (The corresponding screen is created if it did not exist yet. To get rid of unused VTs, use deallocvt(1).) The key combination (Ctrl-)LeftAlt-FN (with N in the range 1-12) usually has a similar effect.


3

If you want to use grep, you can do: grep -av '^.*$' file in UTF-8 locales to get the lines that have at least an invalid UTF-8 sequence (this works with GNU Grep at least).


3

I find uconv (in icu-devtools package in Debian) useful to inspect UTF-8 data: $ print '\\xE9 \xe9 \u20ac \ud800\udc00 \U110000' | uconv --callback escape-c -t us \xE9 \xE9 \u20ac \xED\xA0\x80\xED\xB0\x80 \xF4\x90\x80\x80 (The \xs help spotting the invalid characters (except for the false positive voluntarily introduced with a literal \xE9 above)). ...


2

I like using an easy to use unix command line bash script called VCS - Video Contact Sheet. Their official page: http://p.outlyer.net/vcs/ Its a lot easier to use even easier than a GUI ''It is a bash script meant to create video contact sheets (previews) aka thumbnails or previews of videos. Any video supported by mplayer and ffmpeg can be used by this ...


2

To squash multiple hyphens (one hyphen followed by one or more hyphens) into a single one for all files in the current directory use: rename 's/--+/-/g' -- * The -- is important if files start with a hyphen, otherwise they would be interpreted as command line arguments. The * expands to the list of files in the current directory.


2

find(1): -newerXY reference Compares the timestamp of the current file with reference. The reference argument is normally the name of a file (and one of its timestamps is used for the comparison) but it may also be a string describing an absolute time. X and Y are placeholders for other letters, ...


2

| sort | uniq -c As stated in the comments. Piping the output into sort, organises the output into alphabetical/numerical order. This is a requirement because uniq only matches on repeated lines, ie a b a If you use uniq on this text file, it will return the following. This is because the a is separated by the b - they are not repeating lines. a b a ...


2

You need double quotes to make the shells don't perform field splitting: XX="$(ls -l)"; echo "$XX" But it's not good to use echo with variable that you don't know its content, you should use printf (read this answer) instead: XX="$(ls -l)"; printf '%s\n' "$XX"


2

You could use a bash or ksh function added in your shell rc file : mymv(){ echo mv "$1" "$2/${1##*/}_$3"; } mymv file.csv /home/user backup1 remove the echo when tests are done


2

On the contrary, unzip does too much. cp doesn't need to parse the filenames, all it needs to do is loop over them. Unzip, on the other hand, needs to see if an argument is a wildcard, check the directory listing to see what matches the wildcard and then loop over those. And note that the shell already is capable of matching and expanding wildcards, so ...


2

String interpolation causes this. There are a number of ways to selectively prevent this from happening. The bash hackers wiki has some good examples, though the specifics may vary if you're not actually using bash. In short, you can prevent interpolation with single quotes, or you can escape the characters. [me:~/work]$ export foo=bar [me:~/work]$ echo ...


1

A few things: As derobert notes, the language and the Unix platform are case-sensitive. The then keyword is used only with an accompanying if. To simply run on command after another, either: Keep them in different lines: diff workfile1.txt workfile2.txt wc workfile1.txt workfile2.txt Or separate with semicolons: diff workfile1.txt workfile2.txt; wc ...


1

cd INPUTDIR find . -name \*1.fastq.gz > list1 find . -name \*2.fastq.gz > list2 The paths in the "list" files will be relative to the current directory. If you want absolute paths, use find "$PWD" -name \*1.fastq.gz > list1


1

The behaviour you're looking for is a special case: cp -R [-H|-L|-P] [-fip] source_file... target [This] form is denoted by two or more operands where the -R option is specified. The cp utility shall copy each file in the file hierarchy rooted in each source_file to a destination path named as follows: If target exists and names an existing ...


1

Also this(for slightly shorter and more readability): grep -Ff <(awk '{print $1}' Cell_cycle.txt) filename.fasta


1

Use process substitution <(): fgrep -A 1 -f <(cut -d " " -f 1 Cell_cycle.txt) filename.fasta


1

To expand parameter, arithmetic and command substitutions (and not aliases and other forms of expansions), you could do: my-expand() BUFFER=${(e)BUFFER} CURSOR=$#BUFFER zle -N my-expand bindkey '\e^E' my-expand (it would have similar limitations and could be almost as dangerous as bash's one though).


1

You can set up compinit to expand parameters in your ~/.zshrc: zstyle ':completion:*' completer _expand _complete autoload -Uz compinit compinit This is a minimal setting, if you have compinit already enabled, it should be sufficient to add _expand to the settings of completer There is also the expand-word widget that is by default bound to ^X* (Ctrl+x ...


1

The simplest route, IMHO, is to use a variable: a=file.csv; mv "$a" ~user/"$a"_backup You can avail of tab completion with variables, both while setting them and while using them.


1

In bash, you could try the following: Type mv file1. Press Ctrl-w enough times to delete file1. Press Ctrl-y to paste file1 back. Type /home/user/. Press Ctrl-y to paste file1. Type the rest: _backup


1

It is important to understand that sed works on a line by line basis. What sed does is basically : read a line into its buffer without the newline, execute your commands on the buffer, print the buffer (provided you haven't specified the -n flag), read the next line into its buffer, etc. So to merge two lines with sed requires that you explicitly force sed ...


1

I don't think it'd be common to interpret tool -f BAR | --foo BAR as «pipe the output of tool -f BAR into the command --foo BAR». So I'd use simply tool -f BAR | --foo BAR There's other possibilities in the wild using additional markup, specially if the invocation is more complex, to make it more obvious. Unlike with optional arguments and [] though, none ...


1

A better way to get local users might be to see if the user has a valid login shell: getent passwd | grep -f /etc/shells Here's something that should work: getent passwd | grep -f /etc/shells | tr ',' ':' | \ awk -F: '{print $1, $5}' | while read USER NAME do echo $NAME:$(chage -l $USER| awk -F': ' '/Password expires/{print $2}') ...



Only top voted, non community-wiki answers of a minimum length are eligible