diff different subdirectories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting diff different subdirectories
# 1  
Old 03-13-2011
diff different subdirectories

I have 2 directories a/ and b/,

they have different subdirectories, how to diff with missing file, or missing subdirectory

and if i have in a/ directory "a/ACD/DEF" DEF is a file, but in b/ directory "b/ACD/DEF is a SUBDIRECTORY, how to diff it, thanks

my solution for directories,

Code:
find a/ -type d | sed 's/a\///g' > file
find b/ -type d | sed 's/b\//g' >> file

  for a in  `sort file | uniq`
   do
     mkdir -p c/$a
    done

after diff, I will remove empty subdirectories

Thanks
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 03-13-2011 at 07:46 PM.. Reason: code tags, please!
# 2  
Old 03-13-2011
Code:
cd a/ && find ./ | sort >/tmp/list_a
cd b/ && find ./ | sort >/tmp/list_b
cd /tmp && diff list_a list_b

?

---------- Post updated at 10:05 PM ---------- Previous update was at 10:04 PM ----------

Code:
cd a/ && find ./ | sort >/tmp/list_a
cd b/ && find ./ | sort >/tmp/list_b
cd /tmp && diff list_a list_b

?

Last edited by radoulov; 03-15-2011 at 08:30 AM.. Reason: Fixed code tags.
# 3  
Old 03-13-2011
i think Knajta's problem is to distinguish the directory and file, if they have exactly the same name.
e.g.
Code:
file : a/foo
dir :  b/foo

and "find" doesn't tell it, or I missed somthing?

Last edited by radoulov; 03-15-2011 at 08:30 AM.. Reason: Code tags, please!
# 4  
Old 03-13-2011
Then you could use the -F option of ls command (so that directory name are displayed with a trailing slash)

Code:
cd a/ && find ./ -exec ls -Fd {} \; >/tmp/list_a
cd b/ && find ./ -exec ls -Fd {} \; >/tmp/list_b
sort /tmp/list_a >/tmp/list_a.s && rm /tmp/list_a
sort /tmp/list_b >/tmp/list_b.s && rm /tmp/list_b
cd /tmp && diff list_a.s list_b.s


Last edited by radoulov; 03-15-2011 at 08:30 AM.. Reason: Fixed code tags.
This User Gave Thanks to ctsgnb For This Post:
# 5  
Old 03-13-2011
thx. good to know it.
-F I have never used this option... Smilie
# 6  
Old 03-13-2011
But what are you trying to achieve ? copy a full tree a/* to b/* ?
cp -R ?
or recreate only the same directory tree a/* to b/* ?
or compare name of dir and file under tree a/* and b/* ?

---------- Post updated at 11:12 PM ---------- Previous update was at 11:09 PM ----------

At least on my FreeBSD version, the ls option that add trailing / to the display of directory name is the option -F, maybe it can vary depending on what OS you run.
# 7  
Old 03-13-2011
i guess he want to compare stuffs under two directories.
regarding the -F. I just found out that ...... I have these in my .zshrc:
Code:
alias -g l='ls -lhF --color=auto'
alias -g la='ls -ahF --color=auto'
alias -g ll='ls -lahF --color=auto'

actually I am using -F everyday, I don't even know it .... OMG!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Diff 3 files, but diff only their 2nd column

Guys i have 3 files, but i want to compare and diff only the 2nd column path=`/home/whois/doms` for i in `cat domain.tx` do whois $i| sed -n '/Registry Registrant ID:/,/Registrant Email:/p' > $path/$i.registrant whois $i| sed -n '/Registry Admin ID:/,/Admin Email:/p' > $path/$i.admin... (10 Replies)
Discussion started by: kenshinhimura
10 Replies

2. Shell Programming and Scripting

sed through all subdirectories?

I found this awesome sed script here: https://www.unix.com/shell-programming-scripting/48228-perl-search-string-line-then-search-replace-text.html sed -i '/MatchText/ s/ReplaceMe/REPLACED/' filename Question though to save me manually doing this. How do I do this from a root directory... (6 Replies)
Discussion started by: Astrocloud
6 Replies

3. Shell Programming and Scripting

serach diff filename in diff location using shell scripting

Hi, I am new to shell scripting. please help me to find out the solution. I need a script where we need to read the text file(consists of all file names) and get the file names one by one and append the date suffix for each file name as 'yyyymmdd' . Then search each file if exists... (1 Reply)
Discussion started by: Lucky123
1 Replies

4. Linux

Stats on subdirectories

Please help me with a shell script to get the stats on many subdirectories (sub1), (sub2) etc under a mother directory (big) /big | |_______sub1 |_______sub2 |_______sub3 --------- I want to know 1. What is the last file accessed in each subdirectory with date and by whom 2.... (2 Replies)
Discussion started by: digipak
2 Replies

5. Shell Programming and Scripting

.procmailrc and uudeview (put attachments from diff senders to diff folders)

Moderator, please, delete this topic (1 Reply)
Discussion started by: optik77
1 Replies

6. Shell Programming and Scripting

Simulate SVN diff using plain diff

Hi, svn diff does not work very well with 2 local folders, so I am trying to do this diff using diff locally. since there's a bunch of meta files in an svn directory, I want to do a diff that excludes everything EXCEPT *.java files. there seems to be only an --exclude option, so I'm not sure... (3 Replies)
Discussion started by: ackbarr
3 Replies

7. UNIX for Dummies Questions & Answers

Compare/Diff between directories and subdirectories?

Hi, Does anybody know the cmd to compare two areas and print out the different files w/ path? I tried cmp and diff and dircmp but with no luck. Should I grep and print? For example: /aa/images/jan ..../images/feb /bb/images/jan ..../images/feb i want to print the compare,... (5 Replies)
Discussion started by: andylee80
5 Replies

8. Solaris

/home Subdirectories

Hello: Could someone please explain to me how to create a subdirectory in the /home directory. I have tried creating a new user but the default path for a new user is /export/home. I am running Unix 5.8 on a Sun Blade 100. Thanks. (8 Replies)
Discussion started by: mawalton
8 Replies

9. UNIX for Dummies Questions & Answers

How to search all subdirectories?

Dear All, I want to write the Unix command that searches through all subdirectories, finds the files named ''core'' and deletes them. I will very much appreciate your help. David (4 Replies)
Discussion started by: david_wang
4 Replies

10. Shell Programming and Scripting

diff 2 files; output diff's to 3rd file

Hello, I want to compare two files. All records in file 2 that are not in file 1 should be output to file 3. For example: file 1 123 1234 123456 file 2 123 2345 23456 file 3 should have 2345 23456 I have looked at diff, bdiff, cmp, comm, diff3 without any luck! (2 Replies)
Discussion started by: blt123
2 Replies
Login or Register to Ask a Question