Tag Info

Hot answers tagged

6

The glob * can be used to match not only plain files, but also directories, so the command you are looking for is mv ./*/*.avi .


5

To go back by one level of directory based on the directory path rather than the .. link: cd $PWD:h Or the portable method: cd "${PWD%/*}" (quotes optional in zsh; quotes optional in other shells if the directory name doesn't contain whitespace or \[*?) Repeat the :h or /* as many times as desired to go further up in the directory hierarchy. ...


4

On a GNU system, you can use this: sed -i '/^#[[:blank:]]Person/{n;s/#root:[[:blank:]]\+marc/root:\tsomeone@something.tld/;}' file It searches for a line beginning with # Person. Then switches to the next line and replaces #root:<blanks>marc with root:<tab> .... The -i flag edits the file inplace. -i, \+ and \t are GNU extensions. The ...


3

Assuming PWD is correct, one can back out in ZShell thusly. % cd ~/tmp % mkdir -p a/a/a/a/a/a/a/a/a/a/a % cd !$ cd a/a/a/a/a/a/a/a/a/a/a % rm -rf ~/tmp/a % undir % pwd /Users/jmates/tmp % The custom undir function does the walk-back-out-the-path-chain loop: function undir { local dir dir=$PWD:h while [[ $dir != / ]]; do builtin cd -q $dir ...


3

A passphrase specified by -pass is different from the actual key for encryption specified by -K. openssl processes a passphrase with hash functions to derive an actual key with specific bit length. So passphrases are usually short and memorable strings using only printable characters. You can see actual keys, IVs, and salts by -P. Note that your key gets ...


2

-exec indeed can be used as a predicate. find(1): Execute command; true if 0 status is returned. So this example would be: find . -type f -exec sh -c 'file "$0" | grep -q Matroska' '{}' ';' -and -delete Obviously, instead of -delete there can be -ls or -print0 or more predicates.


2

Assuming: hour=09 Just use that: grep "\.$hour" file With the single quotes in your example, the variable is not interpreted as variable. Therefore the pattern searches for $hour. Also the dot has to be escaped, else it would match any character.


2

The simplest way is to run: getconf LONG_BIT which will return 64 or 32 depending on whether it is 32 or 64 bits. eg: dannyw@dannyw-redhat:~$ getconf LONG_BIT 64


2

Do you have to use awk for this? The paste utility was designed exactly for this sort of thing. Assuming array is a shell array: array=(100 200) printf "%s\n" "${array[@]}" | paste -d, input.csv - > output.csv The printf is simply to put each array member on a new line. paste then pastes together input lines from input.csv and - (i.e. the piped ...


2

Screen is a full-screen software program that can be used to multiplexes a physical console between several processes (typically interactive shells). It offers a user to open several separate terminal instances inside a one single terminal window manager. The screen application is very useful, if you are dealing with multiple programs from a command line ...


1

If you want to open a new xterm and run a sequence of commands in that window, you can use the -e option. If you want the xterm to remain open after the command is executed, you can include the -hold option. For example: xterm -hold -e 'pwd; ls'


1

You can create a recursive script. eg in file /tmp/run #!/bin/bash depth=${1:-5} f(){ let depth-- if [ $depth -gt 0 ] then $0 $depth else sleep 10 fi } f then chmod +x /tmp/run and do /tmp/run 10.


1

I would suggest to use perl: perl -p0e 's/(.*\n)(.*\n)(.*Fail\n)/#\1#\2#\3#/g' file Here is how it works: -p: print program in the loop over all input lines -0: assume null as record separator -e: execute program from the command line s/x/y/g: substitute y for x anywhere in the file (): group together regular expressions .*: any character except newline ...


1

You can use the shuf command to get a random number between a a range Numbers. Ex: $ shuf -i 70-100 -n 1 79 $ shuf -i 70-100 -n 1 72 $ shuf -i 70-100 -n 1 95 $ shuf -i 70-100 -n 1 96 $ shuf -i 70-100 -n 1 81 $ shuf -i 70-100 -n 1 78 $ shuf -i 70-100 -n 1 94 $ shuf -i 70-100 -n 1 78 $ shuf -i 70-100 -n 1 89 $ shuf -i 70-100 -n 1 81 $ shuf -i 70-100 -n 1 97 ...


1

With zsh, to remove the regular files other than the .bmp, .png, .wav (case insensitively) ones: setopt extendedglob # best in ~/.zshrc rm -- *.^(#i)(png|bmp|wav)(D.) (remove the D above if you want to preserve hidden files regardless of their extension).


1

As mentioned before you can try picocom. The latest release (2.0) can also be used (safely) to set-up a "terminal server" since it does no longer permit shell commands injection. See: https://github.com/npat-efault/picocom/releases



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