Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if filename is in directory

Status
Not open for further replies.

omoo

Programmer
May 30, 2005
87
0
0
US
Hi,

I have 2 directories, 1st dir with actual files and the 2nd dir with files with zero contents. What command in unix can I use to check for every file in 2nd dir, whether there is a matching filename in 1st dir.If no matching, delete it; if yes, go to next file.

For example,
1st dir:
abc.txt
def.zip
ghi.gds.pgp

2nd dir:
xyz.zip
abc.txt
stu.zip
ghi.gds.pgp

The resulting files in 2nd dir shd be:
abc.txt
ghi.gds.pgp

 
Hi feherke,

I got this error msg when I tried to use your script:

test: argument expected
 
Hi

Hmm... Try with bracket ( [ ) instead of [tt]type[/tt].
Code:
cd dir2
for f in *; do [red][[/red] ! -e "dir1/$f" [red]][/red] && rm "$f"; done
I use Bash 2.05b, and the [tt]test[/tt] I used is a shell builtin. ( The bracket also. ) But works also with [tt]/usr/bin/test[/tt].

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top