how to tar with date criteria?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how to tar with date criteria?
# 1  
Old 08-23-2010
how to tar with date criteria?

I would like to tar (compress) all the files with some date criteria.
I tried :
tar -cvwf 20_08_2010.tar | ls -la | grep "Aug 20"

but it's not working. How should I type?
# 2  
Old 08-23-2010
This is not the recommended way of doing it .. anyway.

Code:
 
 tar -cvf a.tar  $(stat -c"%n %y" * | grep -- "08-20" | cut -f1 -d' ' )

Best method is to use find command, and executing tar for the files returned by it.
# 3  
Old 08-23-2010
but, I'm using aix OS with bash shell
# 4  
Old 08-23-2010
thegeek shows you whats wrong in your command line:
The pipes arent going to feed your tar...
Using your syntax:
Code:
 ls -la | grep "Aug 20"|awk '{print $9}' # will give you the names of the files to tar
#so as I have no bash to test with here is the ksh command line
tar -cvf 20_08_2010.tar $(ls -la | grep "Aug 20"|awk '{print $9}')
# I let you sort out for bash

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Tar with variable date in separate shell

Hi, I am trying to Zip a folder inside a shell script like below. It successfully taring but it only returns Null inside the variables. Searched a lot but no clue to finding the root cause. testno=1; date=20171128; DIR=/root/ sh -c 'cd $DIR; tar cvf "AWS.${testno.${date}.tar" "./AWS"' ... (5 Replies)
Discussion started by: pradyumnajpn10
5 Replies

2. Shell Programming and Scripting

Searching a file inside a .tar.gz file by date

Hi, I would like to ask if there is a way to search for a file inside a .tar.gz file without extracting it? If there is, is there a way to search for that file by date? Thanks! (4 Replies)
Discussion started by: erin00
4 Replies

3. Red Hat

Tar with particular date files

I need to find out only Jun 10 created and modified file with tar command ,, I am using Linux red hat x86_64 GNU/Linux. ls -lrt -rw-r--r-- 1 nova nova 2757 Jun 7 11:00 feed.ctl -rwxrwxr-x 1 nova nova 457 Jun 7 11:00 acc_feed.csh -rwxr-xr-x 1 nova nova 473 Jun 7 12:11... (2 Replies)
Discussion started by: balajikalai
2 Replies

4. Shell Programming and Scripting

[Solved] How to tar data along with current system date and time.?

Hi all, Following is my small script:- #!/bin/ksh for i in `cat /users/jack/mainfile-dr.txt` do sudo cp -r $i /users/jack/DR01/. done cd /users/jack/DR01/ sudo tar cvf system1-DR.tar * scp system1-DR.tar backupserver:/DRFiles/system1 sudo rm -rf system1-DR.tar In this script I... (10 Replies)
Discussion started by: manalisharmabe
10 Replies

5. Shell Programming and Scripting

Need help to tar and gzip files per date

hi, I have multiple files created per date every day. I want to be able to tar all the files older than 7 days into a single file and then gzip that tarred file and move it to a separate partition. Then delete the actual files. Eg - "ls -l" shows Dec 8 has 6-8 files created. I want to tar... (4 Replies)
Discussion started by: vishal7
4 Replies

6. Shell Programming and Scripting

tar command to explore multiple layers of tar and tar.gz files

Hi all, I have a tar file and inside that tar file is a folder with additional tar.gz files. What I want to do is look inside the first tar file and then find the second tar file I'm looking for, look inside that tar.gz file to find a certain directory. I'm encountering issues by trying to... (1 Reply)
Discussion started by: bashnewbee
1 Replies

7. Shell Programming and Scripting

tar files by date

Hi, I have a solaris 10, I would like to tar log files by date, or by range of hours into one tar file. All I coud do is by name (very simple...:cool:). (4 Replies)
Discussion started by: pointer
4 Replies

8. UNIX for Dummies Questions & Answers

tar -cvf test.tar `find . -mtime -1 -type f` only tar 1 file

Hi all, 4 files are returned when i issue 'find . -mtime -1 -type f -ls'. ./ora_475244.aud ./ora_671958.aud ./ora_934052.aud ./ora_934050.aud However, when I issued the below command: tar -cvf test.tar `find . -mtime -1 -type f`, the tar file only contains the 1st file -... (2 Replies)
Discussion started by: ahSher
2 Replies

9. Shell Programming and Scripting

shell script to selectively tar directory based on date

hye everybody :) , i'm new to the scripting world.. hope you guys can help me out with this one.. i'm trying to identify any directory under /tmp/saya that is created more than one day from the current date.. e.g, today is March 14, so any directory that has time stamp March 13 backwards, i... (2 Replies)
Discussion started by: fara_aris
2 Replies

10. UNIX for Dummies Questions & Answers

tar archive: time, date?

Is there a way to know when (date, time) a tar archive on tape was created? (1 Reply)
Discussion started by: croy75
1 Replies
Login or Register to Ask a Question