Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 02-08-2007, 05:45 AM   #1
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


Old 02-08-2007, 06:11 AM   #2
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
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


and then search for -s.

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

Hope this helps.
Old 02-08-2007, 08:50 AM   #3
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
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
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
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.


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

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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:44 PM.

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