diff -rq path_to_dir1 path_to_dir2
AWK function taken from here:
http://stackoverflow.com/questions/2912224/find-duplicates-lines-based-on-some-delimited-fileds-on-line
215 1320 ./hwebcam048.kopija 215 1320 ./hwebcam048 24 16 ./ac3dlx/lib/tk8.5/ttk/CVS 24 16 ./ac3dlx/lib/tk8.4/CVS 24 16 ./ac3dlx/tcl/CVS
Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?
You must be signed in to comment.
commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for:
sort -sn -k1,2
You're echoing the results of ls and du, therefore the numbers will be space-delimited. So: awk -F space is OKawk -F' '
I mentioned the index being risky, so this is safer:{ idx=$1"."$2;
A simple dot to separate the two numbers. awk doesn't care about the type of idx. Now the rest of the awk program. It looks like it was copied from the awk one-liner to "uniq" the input. It's storing every line in array, when it only needs to keep the previous one (the input is sorted).{ new=$1"."$2; if (new == old) { if (oldline) { print oldline; oldline = ""; } print; } else { old = new; oldline = $0; } }
This does the same thing, but using less memory. new = numbers from current line old = number from previous line (empty to start) oldline = copy of previous entire line (in case the new one matches) To save space :-) it can be condensed to:{n=$1"."$2;if(n==o){if(l){print l;l="";}print;}else{o=n;l=$0;}}
Leaving the new command:find . -type d|while read i; do echo $(ls -1 "$i"|wc -m) $(du -s "$i"); done|sort -sn -k1,2^Cwk -F' ' '{n=$1"."$2;if(n==o){if(l){print l;l="";}print;}else{o=n;l=$0;}}'
Enjoy :-)diff -rq path_to_dir1 path_to_dir2
if disk space is going to be exhausted (=some hard links being considered).