#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    147
    Rep Power
    15

    Question Comparing directory structures


    I would like to compare 2 directory structions & get a list of the files that are different from eachother.

    For ex. if /dir1/sub/file.php is different from /dir2/sub/file.php, I want this command to output "sub/file.php" . Then I will run a script to get the actual differences in the files that are outputted.

    What is the quickest way to do this?

    I tried looping through the files in one structure and comparing them with the same files in the other structure. But I'm stuck because I can't figure out how to get the filename out of a full path.
    Basically, how can I get "file.php" from the string "/dir1/sub/file.php" ?
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,782
    Rep Power
    4301
    You could do something like this:
    ls -1 /path/to/dir1 | sort > /path/to/dirlist1.txt
    ls -1 /path/to/dir2 | sort > /path/to/dirlist2.txt
    diff /path/to/dirlist1.txt /path/to/dirlist2.txt | less
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2005
    Posts
    164
    Rep Power
    17
    it is not very clear what you want, what Scorpions4ever said it's to compare just the filenames, not content..
    you need for content? and can those sub/ have other sub-directories?

IMN logo majestic logo threadwatch logo seochat tools logo