Notes: useful shell commands
Mon 03 June 2024 #technical #notes #linux #bash #devopsDiffing 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
Jakub Olczyk