LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Thread Tools
Old 12-26-2008, 08:05 PM   #1
corteplaneta
Member
 
Registered: Jul 2007
Distribution: slackware, gentoo
Posts: 55
Thanked: 0
Shell Script Compare Folders


[Log in to get rid of this advertisement]
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
corteplaneta is offline     Reply With Quote
Old 12-26-2008, 08:15 PM   #2
billymayday
Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678
Thanked: 126
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
billymayday is offline     Reply With Quote
Thanked by:
Old 12-26-2008, 08:36 PM   #3
corteplaneta
Member
 
Registered: Jul 2007
Distribution: slackware, gentoo
Posts: 55
Thanked: 0

Original Poster
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!

Last edited by corteplaneta; 12-26-2008 at 08:41 PM..
corteplaneta is offline     Reply With Quote
Old 12-26-2008, 08:37 PM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 1,814
Blog Entries: 5
Thanked: 115
include sorting would be good.
ghostdog74 is offline     Reply With Quote
Old 12-26-2008, 08:43 PM   #5
colucix
Guru
 
Registered: Sep 2003
Location: Bologna, Italia
Distribution: OpenSUSE 11.1 CentOS 5.4 VectorLinux 6.0
Posts: 5,133
Thanked: 464
Or eventually
Code:
diff -rq dir_1 dir_2 | grep Only
colucix is online now     Reply With Quote
Old 12-26-2008, 08:43 PM   #6
billymayday
Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678
Thanked: 126
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
       nor --sort.
billymayday is offline     Reply With Quote
Thanked by:

Reply

Bookmarks


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I compare floating number in a shell script? abefroman Programming 12 09-15-2008 08:53 AM
How to Compare Two files using shell script pooppp Linux - Networking 14 08-05-2008 04:35 AM
shell script: compare 2 files anhtt Programming 6 08-29-2007 03:39 AM
Shell script to compare blocks of strings? bruno buys Programming 10 04-15-2006 03:16 PM
How to compare records in two tables in seperate My Sql database using shell script sumitarun Programming 5 04-14-2005 10:45 AM


All times are GMT -5. The time now is 04:17 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration