LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
LinkBack Search this Thread
Old 02-08-2007, 05:45 AM   #1
babysnake
Member
 
Registered: May 2006
Posts: 37

Rep: Reputation: 15
Question compare folder contents


can anyone throw together a quick script/command that simply outputs the differences between the contents (hidden files included) of 2 folders (recursively so that i can say compare quickly /home to /copyof/home without doing all the individual sub-folders) ?

a 'no difference found' ouput option would also be nice

i sort of think what i need to ls -aR one folder, ls -aR the other, then diff the 2 outputs, with a 'no diference' condition if there is none - but i'm a bit new to all this and can't hang it all together !

any help much appreciated

thanks

 
Old 02-08-2007, 06:11 AM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
You want:

diff -r directory1 directory2

If you want "no difference found", then write a script. In that script, send the output to a scratch file. Then test whether the file contains any bytes (use the -s conditional expression in bash), and if it doesn't, then echo no difference found. For further details on the -s conditional expression, see the man page:

man bash

Don't confuse it with the -s switch! In the man page, search for

^CONDITIONAL EXPRESSIONS

and then search for -s.

For help with conditional expressions and general help on writing bash scripts, see

http://tldp.org/LDP/abs/html/

Hope this helps.
 
Old 02-08-2007, 08:50 AM   #3
babysnake
Member
 
Registered: May 2006
Posts: 37

Original Poster
Rep: Reputation: 15
Thumbs up folder differences

thanks very much for that

i had it in my head that diff only worked on files not folders

i'll give that a go and maybe even tinker with a small script

 
Old 02-08-2007, 08:55 AM   #4
wahming
Member
 
Registered: Jan 2007
Posts: 133

Rep: Reputation: 15
Just to point out - directories ARE files. In Linux, everything is a file. You just have to deal with permissions.
 
Old 02-09-2007, 07:04 AM   #5
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
Yes, wahming, but babysnake would not be interested in directories at that level. In the case of directories, he would be interested in comparing all the files in those directories. And so on.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script to compare dir contents Boffy Programming 2 08-02-2005 06:08 AM
How to compare two folders contents? rvoigt Linux - Newbie 6 01-07-2005 12:35 AM
Cannot see contents of my folder nr4g3d Linux - Newbie 6 02-09-2004 03:01 PM
to compare the contents of 2 files MaleWithBrains Linux - Newbie 3 01-27-2004 06:39 PM
samba does not show folder contents Goma_2 Linux - Networking 0 12-10-2003 04:54 AM


All times are GMT -5. The time now is 08:25 PM.

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
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration