Notes: useful shell commands

Diffing two directories

Useful for when you have some changes that should be copied over to another directory.

Options to use:

       -q, --brief
              report only when files differ
       -s, --report-identical-files
              report when two files are the same
       -r, --recursive
              recursively compare any subdirectories found

Example

$ diff -qsr left/ right/
Only in right/: anotherfile.txt
Files left/file0.txt and right/file0.txt are identical
Files left/file.txt and right/file.txt differ
Only in left/: secondfile.txt

Running bash function with xargs

I sometime use bash functions as a more complex alias mechanism in Bash. It is useful to use them with xargs when passing arguments through a pipe.

Here's an example of this concept:

echo_var(){
    echo $1
    return 0
}
export -f echo_var;
echo 1 2 3 | xargs -n 1 -P 10 bash -c 'echo_var "$@"' _

I found this solution on StackOverflow

WARNING! This article has been written a long time ago. It may no longer represent the current views of the author!


Consider commenting via e-mail

Newest in technical