RE:backup files older then 24hrs to a new directory .


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting RE:backup files older then 24hrs to a new directory .
# 1  
Old 04-03-2006
RE:backup files older then 24hrs to a new directory .

How do you move (mv) files to a backup directory from a particular directory when the files are
older the 24hrs copied from a batch script run every 24 hrs.
Would you use find or some kind of timestamp.timestamp="$(date +'%m%d%I%M')"
# 2  
Old 04-03-2006
try find maybe like this: -mtime +1 means older than one day (24 hours)
Code:
find /particular/directory -mtime +1  | \
  while read file
  do
       b=`basename "$file"`
       mv $file /path/to/new/directory/"$b"
  done

# 3  
Old 04-03-2006
Jim, I believe there is some confusion regarding the mtime parameter. +0 stands for older than one day, +1 would stand for older than 2 days. Check this out:
Code:
# date
Tue Apr  4 04:28:16 IST 2006
# ls -ltr
:
:
-rw-r--r--   1 root       sys              0 Apr  3 04:20 testfile
-rw-r--r--   1 root       sys           1300 Apr  3 23:58 fs.c
-rw-r--r--   1 root       sys            583 Apr  4 04:08 freesp.c
-rw-r--r--   1 root       sys            971 Apr  4 04:11 daemon.c
-rwxr-xr-x   1 root       sys          28672 Apr  4 04:11 a.out
-rwxr-xr-x   1 root       sys          24576 Apr  4 04:11 daemon
-rw-r--r--   1 root       sys            139 Mar 22 12:56 ./t1.c
-rwxr-xr-x   1 root       sys             38 Mar 31 08:05 ./shell/test.sh
drwxr-xr-x   2 root       sys           8192 Mar 31 08:05 ./shell
-rw-r--r--   1 root       sys              0 Apr  3 04:20 ./testfile
# find . -mtime +0 |xargs ls -ldtr|more
:
-rw-r--r--   1 root       sys            139 Mar 22 12:56 ./t1.c
-rwxr-xr-x   1 root       sys             38 Mar 31 08:05 ./shell/test.sh
drwxr-xr-x   2 root       sys           8192 Mar 31 08:05 ./shell
-rw-r--r--   1 root       sys              0 Apr  3 04:20 ./testfile
# find . -mtime +1 |xargs ls -ldtr|more
:
-rw-r--r--   1 root       sys            139 Mar 22 12:56 ./t1.c
-rwxr-xr-x   1 root       sys             38 Mar 31 08:05 ./shell/test.sh
drwxr-xr-x   2 root       sys           8192 Mar 31 08:05 ./shell

Note that the file testfile shows up on using +0 and not on using +1. Check Perderabo's last post in this thread.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Finding files older than x days within directory with spaces

Hi, I am trying to run a command that finds all files over x amount of days, issue is one of the directories has spaces within it. find /files/target directory/*/* -type f -mtime +60 When running the above the usual error message is thrown back + find '/files/target\' 'directory/*/*' -type... (1 Reply)
Discussion started by: Ads89
1 Replies

2. Shell Programming and Scripting

How to move the files older than x days with similar directory structure?

Hello, I need to move all the files inside /XYZ (has multi-depth sub directories) that are older than 14 days to/ABC directory but with retaining the SAME directory structure. for example: /XYZ/1/2/3/A/b.txt should be moved as /ABC/1/2/3/A/b.txt I know about find /XYZ -type f -mtime +14... (3 Replies)
Discussion started by: prvnrk
3 Replies

3. Shell Programming and Scripting

Deleting files and directory's older than 3 months

I have a qnap TS259 that is running ubuntu. Have successfully setup back scripts that are initiated by cron. I would like to create a couple scrypts that would operate on the recycle bins for both drives. Just want to be able to run the script manually that would walk through both directories... (13 Replies)
Discussion started by: mackconsult
13 Replies

4. AIX

Want to delete directory, subdirectories and all files which are older than 7 days

how do i remove sub directories of a directory and all files which are older than 7 days by a single command in AIX. pls help me. I am using command as #find /gpfs1/home/vinod/hpc/ -depth -type d -mtime +7 -exec rm -rf {} \; so i want to delete all sub directories and all files from the... (1 Reply)
Discussion started by: vinodkmpal
1 Replies

5. Shell Programming and Scripting

Delete files older than 10 Days in a directory

Hi All I want to remove the files with name like data*.csv from the directory older than 10 days. If there is no files exists to remove older than 10 days, It should not do anything. Thanks Jo (9 Replies)
Discussion started by: rajeshjohney
9 Replies

6. Shell Programming and Scripting

Delete the files older than 3 weeks in a particular directory.

Hi, Friends, I am writing a script to delete all the files which are there for more than 3 weeks. I have tried this : find /home/appl/backup -type f -mtime +21 -exec rm -f {} \; But i am not sure if it deletes only the files in specified directory or all the directorinies in the provieded... (3 Replies)
Discussion started by: rajsharma
3 Replies

7. Shell Programming and Scripting

Removing files older than one week in a directory

Hi, I need a shell script to remove the files older than a week in a directoy and if necessary to zip the files. (2 Replies)
Discussion started by: sudhakaryadav
2 Replies

8. Shell Programming and Scripting

Find files in a directory which are older than 2 hrs

hi all, I need to find files in a directory which are older than N hrs... n can be 1,2,3,.. etc when tried using -mtime option it gives all the files in the last 24hrs from the current time . please help me out on this .. thanks (8 Replies)
Discussion started by: sparks
8 Replies

9. Shell Programming and Scripting

delete files older than 5 minutes in directory (recursively)

sorry guys can some please give me a hint how to achieve this in a slick oneliner? delete files older than 5 minutes in specified directory (recursively) peace (3 Replies)
Discussion started by: scarfake
3 Replies

10. Shell Programming and Scripting

unix command/s to find files older than 2 hours in a directory

I need to write a script to find files older than 2 hours in set of direcotries and list them ina mail. I know find command ti list files greater/lesser than days but i need to do it for hours. Any input. (6 Replies)
Discussion started by: Presanna
6 Replies
Login or Register to Ask a Question