comparing 2 directories

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions comparing 2 directories
# 1  
Old 11-03-2009
comparing 2 directories

i have been asked to write a bash shell script comparing two directories and sed or awk should not be used in this assignment. compdir will compare filenames in two directories, and list information about filenames that are in one directory but not the other. The information listed will be a long listing of each file, similar to the "ls -l" command. The directory names must be specified, including any required absolute or relative paths.

Usage: compdir dir-name1 dir-name2

compdir will work for all kinds of files, including directories that are contained in the specified directories. The script will print an appropriate error message if the number of arguments passed to it is something other than 2, or if the directory names specified are not names of valid existing directories. If an error message is issued, then the script should end with an exit status of 1 (one). Otherwise, it should end with an exit status of 0 (zero).

Here are examples of compdir error messages (directory d1 exists, d2 and d3 do not exist):
$ compdir
Usage: compdir dir-name1 dir-name2
$ compdir d1
Usage: compdir dir-name1 dir-name2
$ compdir d1 d2 d3
Usage: compdir dir-name1 dir-name2
$ compdir d1 d2
d2 is not a valid existing directory
$ compdir d2 d1
d2 is not a valid existing directory
$ compdir d2 d3
d2 is not a valid existing directory
$ compdir d3 d2
d3 is not a valid existing directory

anyone has any tips on how i should do this. im a begginer in scripting. thanks.
# 2  
Old 11-03-2009
https://www.unix.com/homework-coursew...ons-forum.html

read the special rules for homework and repost...
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparing two directories with diff

Hi all, I have 2 directories on two different servers. I am trying to find out what is missing from directory X and what is missing from directory Y. they should both have the same exact files in them. I understand some files may be missing from both directories on each server. I am not sure... (8 Replies)
Discussion started by: jeffs42885
8 Replies

2. Shell Programming and Scripting

Comparing 2 UNIX directories

Hello, I'd want to compare the content of 2 directories in unix. I use the diff command like this: diff /home/user/AAAAA /home/user/BBBBB It works fine, but when a same file is in both directories and they are diferents, I'd want to see only that it is diferent and not all... (4 Replies)
Discussion started by: nolo41
4 Replies

3. Shell Programming and Scripting

Comparing the pattern of the file names in 2 different directories

Hi, I have got a requirement for which i need your help. The following problem is required to get solved in PERL SCRIPT. Here is the requirement. There are 4 folders say SRC_DIR1, SRC_DIR2 and TGT_DIR_1,TGT_DIR_2 (Note: both path of SRC_DIR1 & SRC_DIR2 are different but both path of... (4 Replies)
Discussion started by: shadow_fawkes
4 Replies

4. Shell Programming and Scripting

**URGENT ** : Comparing the pattern of the file names in 2 different directories

Hi, I have got a requirement for which i need your help. The following problem is required to get solved in PERL SCRIPT. Here is the requirement. There are 4 folders say SRC_DIR1, SRC_DIR2 and TGT_DIR_1,TGT_DIR_2 (Note: both path of SRC_DIR1 & SRC_DIR2 are different but both path of... (1 Reply)
Discussion started by: shadow_fawkes
1 Replies

5. Shell Programming and Scripting

Script for Comparing directories and file from a text file

Hello all, I need to write a script which has following requirement: Need to read the filenames from text file and then search for the above read files in the required directory and if match found backup them in a backup folder. And also need to compare and verify whether the files in the... (7 Replies)
Discussion started by: saurau
7 Replies

6. Shell Programming and Scripting

Comparing the modified dates of files in two directories

Hi Is it possible to compare the modified dates of all the files in two directories using shell script? I would like to take a backup of a directory in production server regularly. Instead of copying all the files in the directory, is it possible to list only the files that are... (2 Replies)
Discussion started by: ashok.k
2 Replies

7. Shell Programming and Scripting

Comparing directories on different unix servers

Is it possible to use the diff command to compare two directories on different Unix (AIX) servers? We have two regions set up and we want to be able to compare if the scripts directory in both regions contain the same files? I want to figure out if its possible.. Have been messing around by... (10 Replies)
Discussion started by: Jazmania
10 Replies

8. UNIX for Dummies Questions & Answers

comparing the content of two directories

Hello I want to compare the content of two directories recursively to check if the two directories have the same files. How can I do that? (2 Replies)
Discussion started by: xyzt
2 Replies

9. UNIX for Dummies Questions & Answers

Comparing directories via ftp

Hello! I am trying to compare a list of files in 2 directories - one on our unix server (I'll call it 'ours') and one on a site we ftp to (I'll call it 'ftp'). I need to make sure that after we ftp, the names that we put out there match the names we have on our side. I was thinking to create a... (1 Reply)
Discussion started by: tekster757
1 Replies
Login or Register to Ask a Question