Results 1 to 4 of 4
May i know how to check two arguments whether it is a file and the other is a directory, check if files exist in directory and copy it if it ...
- 06-30-2011 #1Banned
- Join Date
- Jun 2011
- Location
- Malaysia
- Posts
- 5
URGENT need help!~
May i know how to check two arguments whether it is a file and the other is a directory, check if files exist in directory and copy it if it is a newer version. Seriously i need idea to do tis, jst some simple sample wil do
- 06-30-2011 #2Just Joined!
- Join Date
- Jun 2011
- Location
- US
- Posts
- 2
There may be a single command method to do this, but here's how I would do it:
First use the find command:
This will list the pathname to the file if it exists in the directory or any sub-directories.Code:find [directory to search through] -name [file searched for] -print
Next use the cp command to copy the file to whatever directory you would like:
Code:cp [found file] [new directory to place file]
- 07-01-2011 #3Banned
- Join Date
- Jun 2011
- Location
- Malaysia
- Posts
- 5
Code:hey..reli thx for ur hlp, nw i get some idea to do it, bt for the find and cp, i jst wn to use if-else to do it, im nt sure hw to do it,so here what i get: if [ find $2 -name $1 -print ] then cp $1 $2 echo"File copied" else echo"Error!" fi
- 07-01-2011 #4Banned
- Join Date
- Jun 2011
- Location
- Malaysia
- Posts
- 5
ops, sory for my mistake above, bt the code is wat i want to write, $1 wil be my file 1(f1) and $2 wil be directory 1(d1)


Reply With Quote