moving files prior to 2 days


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers moving files prior to 2 days
# 1  
Old 05-09-2006
moving files prior to 2 days

Hi All,

I have a question.
i have a directory say /home/pavi/logs

ls -ltr gives all the files in the /home/pavi/logs directory.

i am trying to move only those files existing in this
folder prior to 2 days.

i.e files exiting say May 9th and May 8th remain in this directory
but all the remaining files should be moved to a destination dir
say /hom/pavi

can anyone please suggest me with some ideas.

thanks
pavi
# 2  
Old 05-09-2006
Bug

This works for moving the files more than 2 days old (2 * 24 hours Change the number accordingly after mtime parameter)
mv `find /home/pavi/logs/*.* -mtime +2 -exec ls {} \;` /home/pavi

Gopinath
# 3  
Old 05-09-2006
When I use this for my script I get a bunch of errors. I thought I could use Xargs but I get this:

usage: mv [-f | -i | -n] [-v] source target
mv [-f | -i | -n] [-v] source ... directory

Here's my code:

find /home/pavi/logs/ -mtime +21 -exec ls {} \; | xargs mv /home/pavi

Any thoughts? Thanks.
# 4  
Old 05-10-2006
Did you put the quote in front of find command and close the quote after the semicolon? This statement works fine and move all the files prior to 2 days old.
# 5  
Old 05-10-2006
Do I need to use the quotes? I thought I didn't since I was piping to xargs? Thanks!

UPDATE: After putting the backquotes in here's the error I get:

-sh: ./.DS_Store: cannot execute binary file
# 6  
Old 05-10-2006
Please post exactly what you are typing to move the files.

Try to Copy or make changes to the paths and execute the command below and it should move the files older than 2 days old.

mv `find /home/pavi/logs/*.* -mtime +2 -exec ls {} \;` /home/pavi
# 7  
Old 05-10-2006
Hi, gthokala.

Here's the exact line I'm using:

(first I cd to the directory I want to 'find' in)

find . -mtime +21 -exec ls {} \; | xargs mv /Volumes/FTP_drive/FTP/temp_save

When I run this I get:

usage: mv [-f | -i | -n] [-v] source target
mv [-f | -i | -n] [-v] source ... directory
usage: mv [-f | -i | -n] [-v] source target
mv [-f | -i | -n] [-v] source ... directory
xargs: unterminated quote

and no files moved.

I'll try your code right now. Thanks!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to create zip/gz/tar files for if the files are older than particular days in UNIX or Linux?

I need a script file for backup (zip or tar or gz) of old log files in our unix server (causing the space problem). Could you please help me to create the zip or gz files for each log files in current directory and sub-directories also? I found one command which is to create gz file for the... (4 Replies)
Discussion started by: Mallikgm
4 Replies

2. AIX

Moving Hidden files to normal files

I have a bunch of hidden files in a directory in AIX. I would like to move these hidden files as regular files to another directory. Say i have the following files in directory /x .test~1234~567 .report~5678~123 .find~9876~576 i would like to move them to directory /y as test~1234~567... (10 Replies)
Discussion started by: umesh.narain
10 Replies

3. Shell Programming and Scripting

Finding files with wc -l results = 1 then moving the files to another folder

Hi guys can you please help me with a script to find files with one row/1 line of content then move the file to another directory my script below runs but nothing happens to the files....Alternatively Ca I get a script to find the *.csv files with "wc -1" results = 1 then create a list of those... (5 Replies)
Discussion started by: Dj Moi
5 Replies

4. UNIX for Dummies Questions & Answers

Need Help in reading N days files from a Directory & combining the files

Hi All, Request your expertise in tackling one requirement in my project,(i dont have much expertise in Shell Scripting). The requirement is as below, 1) We store the last run date of a process in a file. When the batch run the next time, it should read this file, get the last run date from... (1 Reply)
Discussion started by: dsfreddie
1 Replies

5. UNIX for Dummies Questions & Answers

Moving Multiple files to destination files

I am running a code like this foreach list ($tmp) mv *_${list}.txt ${chart}_${list}.txt #mv: when moving multiple files, last argument must be a directory mv *_${list}.doc ${chart}_${list}.doc #mv: when moving multiple files, last argument must be a... (3 Replies)
Discussion started by: animesharma
3 Replies

6. Shell Programming and Scripting

Shell Script for moving 3 days old file to Archive Folder

Hi Experts, I have a "Source" folder which may contain some files. I need a shell script which should move all files which are older than 3 days to "Archive" folder. Thanks in Advance... (4 Replies)
Discussion started by: phani333
4 Replies

7. UNIX for Advanced & Expert Users

File disk utilization for 10 days prior

Hi I have a requirement to list the files & the total disk utilization they have which are 10 prior to current date. I tried couple of options in combinations of find mtime, ctime with du -m, but no luck. Could you please help me in this ? (2 Replies)
Discussion started by: videsh77
2 Replies

8. Shell Programming and Scripting

List files created before Noon 2 days prior

Our nightly updates run in the evening and finish around 8am. My boss wants the current log files kept on the server for 2 days, but wants anything created before noon, 2 days prior archived. I was thinking of using touch to set a temporary file with a date of today-2 and a time of noon, then... (3 Replies)
Discussion started by: prismtx
3 Replies

9. Shell Programming and Scripting

ls latest 4 days or specify days of files in the directory

Hi, I would like to list latest 2 days, 3 days or 4 days,etc of files in the directory... how? is it using ls? (3 Replies)
Discussion started by: happyv
3 Replies
Login or Register to Ask a Question