LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 02-07-2005, 03:20 AM   #1
alice95089
Member
 
Registered: Dec 2004
Location: hong kong
Posts: 44

Rep: Reputation: 15
How can i find the difference for directory


Hi all,

We will use diff file1 file2 usually to find the diffreence for the files.
I would like to ask, if i want to find the difference for directory instead of file, any suggested command? sdiff?

Thanks
Alice
 
Old 02-07-2005, 03:40 AM   #2
__J
Senior Member
 
Registered: Dec 2004
Distribution: Slackware, ROCK
Posts: 1,973

Rep: Reputation: 46
did you try man diff?

try diff directory1 directory2

is that what you're looking for or something different?
 
Old 02-07-2005, 04:05 AM   #3
alice95089
Member
 
Registered: Dec 2004
Location: hong kong
Posts: 44

Original Poster
Rep: Reputation: 15
diff directory1 directory2 don't work as what i want is to compare the difference of directory instead of file content, for example. are there addition file or lack of some file?

Alice
 
Old 02-07-2005, 06:28 AM   #4
scuzzman
Senior Member
 
Registered: May 2004
Location: Hilliard, Ohio, USA
Distribution: Slackware, Kubuntu
Posts: 1,851

Rep: Reputation: 47
Try this script:

Code:
#! /bin/bash

# dirdiff - diff 2 directories

DIR1=/path/to/directory/1
DIR2=/path/to/directory/2

ls $DIR1 | sort > dir1.ls.tmp
       # list files in dir1, sort them alphabetically, and store in temp file
ls $DIR2 | sort > dir2.ls.tmp
      # same as dir 1, but for dir 2

echo "Differences are:"
diff dir1.ls.tmp dir2.ls.tmp

#Clean up time:
rm dir1.ls.tmp
rm dir2.ls.tmp

#EOF
*note: change this:
Code:
DIR1 = /path/to/directory/1
DIR2 = /path/to/directory/2
where /path/to/directory/1 is the path for the 1st dir, and same for the second.

Also - be sure to make it executable:
Code:
chmod 755 dirdiff
dirdiff was just an arbitrary name I chose - replace with a name you feel appropriate.

Also - make sure you're not in one of the directories when executing this, otherwise the diff will report the temp files as differences before they're deleted.

Last edited by scuzzman; 02-07-2005 at 06:37 AM.
 
Old 02-07-2005, 09:49 AM   #5
zulfilee
Member
 
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430

Rep: Reputation: 39
A simple
diff -rq Dir1 Dir2

will tell you which files are lacking or more in each dir.

Cheers
Z
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
reqd to find the difference between two files Prasun1 Linux - General 7 09-09-2005 06:16 PM
find size of directory naijaguy Linux - Newbie 3 03-04-2005 12:11 PM
exclude directory from find ebasi Linux - Software 8 07-17-2004 03:12 AM
Difference between directory and folder in windows? Squall General 7 02-03-2004 09:10 PM
How to find the directory of a binary (in C) DiscoStoo Programming 1 03-22-2002 04:29 PM


All times are GMT -5. The time now is 06:51 AM.

Main Menu
Advertisement
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