![]() |
Shell Script Compare Folders
Hey,
I've attempted to learn shell scripting but haven't found any good resources..does anyone know of a way to compare two folders to see what folders one contains and the other does not? Any help would be greatly appreciated!! Thanks :) -corte |
You could do something very simple like
ls -1 dir_1 > dir_1.txt ls -1 dir_2 > dir_2.txt diff dir_1.txt dir_2.txt |
Great solution..but how do I exclude all files with .mp3 extension?
Nevermind.... figured this out by... diff dir_1.txt dir_2.txt > differences cat differences | grep -v .mp3 > removed_mp3 gave the result I was searching for! |
include sorting would be good.
|
Or eventually
Code:
diff -rq dir_1 dir_2 | grep Only |
ls -1 dir_1 | sed -e '/.*\.mp3/d' > dir_1.txt
etc. ls sorts by default - from man ls Code:
List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX |
Quote:
Quote:
|
You can also try this one:
Code:
find <first dir> <second dir> -maxdepth 1 -type f -printf "%p\\t%f\\n" | sort | uniq -f 1 -u [| cut -f 1] |
My mistake. The above is really not working.
Code:
find <first dir> <second dir> -maxdepth 1 -type f -printf "%f\\t%p\\t%f\\n" | sort | uniq -f 2 -u | cut -f 2 |
All times are GMT -5. The time now is 08:10 PM. |