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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ls, mv, & rm of two weeks old files 2

Status
Not open for further replies.

gatetec

MIS
Mar 22, 2007
420
US
I need to ls, mv, and rm if files are more than two weeks old.
There are many of archive log files with the file extension, ".arc". I want to ls, mv, and rm if 14 days have passed "as of today", and will put it onto the crontab.

Pls let me know the command (ls, mv, and rm) for the files, 14 days old.

thx much
 
The commands are below. It is better to creat a list and work on the list if you need to do all the three operations instead running find command three times.

List
find /<dir> -name '*.arc' -mtime +14 |xargs ls

Move
find /<dir> -name '*.arc' -mtime +14 |xargs mv /<destdir>/.

Remove
find /<dir> -name '*.arc' -mtime +14 |xargs rm
 
ls works really well.
I will run each command separate.
This mv command returns an error. Pls let me know how to correct it. I am on 5.2.8.

# find /u02/oracle/arch/ -name '*.arc' -mtime +14 |xargs mv /backup/.

Usage: mv [-i | -f] [-E{force|ignore|warn}] [--] src target
or: mv [-i | -f] [-E{force|ignore|warn}] [--] src1 ... srcN directory
Usage: mv [-i | -f] [-E{force|ignore|warn}] [--] src target
or: mv [-i | -f] [-E{force|ignore|warn}] [--] src1 ... srcN directory
 
Have a look into this site:


This command should work! but in case use the exec:

Code:
Then to move the files somewhere either use xargs (if available):

    find /u02/oracle/arch/ -name '*.arc' -mtime +14 -print | xargs mv /my/save/place

  or the -exec option to find:

    find /u02/oracle/arch/ -name '*.arc' -mtime +14 -print -exec mv '{}' /my/save/place ';'

  [here the quotes are used to protect the special characters {}; from
  the shell]

Regards,
Khalid
 
The following should work

for OLDFILE in `find /u02/oracle/arch/ -name '*.arc' -mtime +14`
do
mv $OLDFILE /backup/.
done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top