Sponsored Content
Top Forums Shell Programming and Scripting How to backup latest date files? Post 302459649 by smr_rashmy on Tuesday 5th of October 2010 06:53:31 AM
Old 10-05-2010
Quote:
Originally Posted by rdcwayx
1. find out the old files.

Code:
ls XX*.dat | sort -t_ -k2nr |sed -n '3,$p'

if it is fine, backup them.

Code:
ls XX*.dat | sort -t_ -k2nr |sed -n '3,$p' |xargs -i cp {} /OTHER_DIR

2.
Code:
cd /CURRENT_DIR

diff <(sort XX123) <(ls XX*.dat|sort)

Thank you. The command is not exactly fetching the old files. Check the below,
$ ll XX*
-rw-r--r-- 1 fp015362 user 0 Oct 5 19:45 XX111_20101005010203.dat
-rw-r--r-- 1 fp015362 user 0 Oct 5 19:44 XX121_20101003010101.dat
-rw-r--r-- 1 fp015362 user 0 Oct 5 19:44 XX122_20101002010101.dat
-rw-r--r-- 1 fp015362 user 0 Oct 5 19:44 XX123_20101004010101.dat
-rw-r--r-- 1 fp015362 user 0 Oct 5 19:44 XX124_20101004010201.dat
$ ls XX*.dat | sort -t_ -k2nr |sed -n '3,$p'
XX123_20101004010101.dat
XX121_20101003010101.dat
XX122_20101002010101.dat

---------- Post updated at 05:53 AM ---------- Previous update was at 05:48 AM ----------

Quote:
Originally Posted by Chubler_XL
for files in dir but not in listfile use:
Code:
 ( cd dir ; ls ) | fgrep -vf listfile

For files in listfile but not in dir use:
Code:
 fgrep -v "$( cd dir; ls )" listfile

Thank you very much it is working fine Smilie Smilie
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Copying files with the latest date

Hi All, I have a situation where I need to copy the files having the latest date. For example I have a file by name bas100e1_jun05. I need to copy it to bas100e1. But when a file by name bas100e1_jul05 is put in the same directory the script should copy the file having the latest month which... (34 Replies)
Discussion started by: shashi_kiran_v
34 Replies

2. Shell Programming and Scripting

Loop through files in dir, omit file with latest date

I want to loop through files in a directory but omit the file with the latest date in my list of files. How would I accomplish this? Thanks (2 Replies)
Discussion started by: stringzz
2 Replies

3. Shell Programming and Scripting

Backup files per Date String

Guys, I've got a quick logic question. I'm pretty savvy when it comes to shell scripting, however, I'm at a loss when it comes to writing a simple shell script to backup only certain files out of the month. I have a directory, for example, /data/backups/websites/domain. In each "domain"... (5 Replies)
Discussion started by: drewrockshard
5 Replies

4. Shell Programming and Scripting

backup of files for a specific date

I want to write script for backing up archive logs files for specific date. please give me idea for that. (2 Replies)
Discussion started by: akm9999
2 Replies

5. Shell Programming and Scripting

shell script to find latest date and time of the files

Hi everyone, Please help:) I have a list of 1000 different files which comes daily to the directory.Some of the files are not coming to the directory now. I need to write a shell script to find the latest date and time of the files they came to the directory. The files should be unique.... (1 Reply)
Discussion started by: karthicss
1 Replies

6. Filesystems, Disks and Memory

backup of files for a specific date

In Linux Advance server I want to write one script for backing up files for a specific date like 24/07/2008. (3 Replies)
Discussion started by: akm9999
3 Replies

7. UNIX for Dummies Questions & Answers

get the latest file by reading the date in the filename.

Hi, I grep for a pattern in a list of files. "grep -i -l $pattern *.datx*" it may give me n number of files. say for eg, it gives me 2 files. lock_eicu_20071228_00000000.dat_20071228_05343100 lock_eicu_20080501_00000000.dat_20080501_05343900 out of these 2 files I need to get the... (7 Replies)
Discussion started by: prsshini
7 Replies

8. Shell Programming and Scripting

grep latest file based on date.

hi all, not sure if this has been posted b4 but i try to search but not valid. this is my question: when i do a ls -ltr there will be a list generated as follows: -rw-r--r-- 1 root sys 923260 Jan 10 04:38 FilePolling.41025.083TL021.xml -rw-r--r-- 1 root sys 1761337 Jan 10 04:40... (12 Replies)
Discussion started by: lweegp
12 Replies

9. UNIX for Dummies Questions & Answers

Selecting the file of latest Date

Hi Folks, I have one query that there is a folder in which daily several logs files are getting created , I reached to that location through putty but what I observer that 10 files of different date are been created with same name , what I need to see is the latest file ...let say the location is ... (5 Replies)
Discussion started by: KAREENA18
5 Replies

10. Shell Programming and Scripting

Find latest date in folder

HI I have folder in home dir. /home/kpp/07222013 /home/kpp/07212013 /home/kpp/07202013 Output :-- /home/kpp/07222013 Just find latest date (5 Replies)
Discussion started by: pareshkp
5 Replies
All times are GMT -4. The time now is 02:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy