Compress files as per timestamp in multiple subdirectories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compress files as per timestamp in multiple subdirectories
# 1  
Old 10-28-2010
Compress files as per timestamp in multiple subdirectories

I'd really appreciate if anyone could assist me with this code

A directory with multiple subdirectories has multiple files which are timestamp'ed.

We need to
- compress files as per timestamp
- save compressed file/s in the respective folder
- delete the source files


============
Current output
===========

Example : -
john (directory)
=============
1.xml oct 21 2010
2.xml oct 22 2010
3.xml oct 22 2010
4.xml oct 24 2010


sam (sub -directory)
===============
41.xml oct 22 2010
45.xml oct 21 2010
23.xml oct 23 2010
14.xml oct 24 2010
11.xml oct 24 2010


test (sub -directory)
================
91.xml oct 23 2010
14.xml oct 25 2010
15.xml oct 24 2010
18.xml oct 25 2010


===============
Required output
===============

john(directory)
===============
oct 21 2010.gz #(one file)
oct 22 2010.gz #(two file)
oct 24 2010.gz #(one file)


sam (sub -directory)
======================
oct 22 2010.gz #(one file)
oct 21 2010.gz #(one file)
oct 23 2010.gz #(one file)
oct 24 2010.gz #(two file)


test (sub -directory)
=====================
oct 23 2010.gz #(one file)
oct 25 2010.gz #(two file)
oct 24 2010.gz #(one file)


I managed
find ${MAIN_DIR} -mtime +7 -exec gzip -1 {} \;

Correct me if it needs any changes and Thanks in Advance.
# 2  
Old 10-28-2010
this command will look for file whose modification time is older than 7 days and zip them as filename.gz and not with the timestamp.

Also tell me does ur filename has space inbetween or any other characters ?
# 3  
Old 10-28-2010
Thanks abinaya.

Yes, you are correct this code is zipping files which are older than 7 days individual but i need to compress all files which are pertain to one day in to one file as their respective directories.

And we have different types of file names and some of them i given below.

john_0_20100905_000028.xml
sam01013735.xml
test_2010092417071107.XML

kindly let me know if you need any further information.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compress multiple gzip files

Good afternoon friends. I wanted to make a query, how to compress several files and leave them all in 1, for example flat text files: filename_1.csv filename_2.csv filename_3.csv expected result filename_end.gzip = (filename_1.csv filename_2.csv filename_3.csv) please (2 Replies)
Discussion started by: tricampeon81
2 Replies

2. Shell Programming and Scripting

Compress Files in Multiple Directories

I would like to compress the files in multiple directories. For some reason, it only compress the first directory (/Sanbox/logs1) but not the rest of the other directories ("/Sanbox/logs2" "/Sanbox/logs3" "/Sanbox/logs4" ). Any help would be appreciated. Here's my code: #!/bin/bash... (1 Reply)
Discussion started by: Loc
1 Replies

3. Shell Programming and Scripting

Script to find & replace a multiple lines string across multiple php files and subdirectories

Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ? The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories. So lets say im at root/dir1/dir2/ , when i execute... (12 Replies)
Discussion started by: spfc_dmt
12 Replies

4. Shell Programming and Scripting

Bash Script to Compress All Subdirectories

I'd like to create simple bash script that, given a directory, compresses each directory by name, e.g.: Contents of ~/Documents Folder1 Folder2 Folder3 compress-subdirectoies.sh ~/Documents Results: Folder1. Folder2. Folder2. Any advice would be appreciated (7 Replies)
Discussion started by: furashgf
7 Replies

5. UNIX for Dummies Questions & Answers

Help with untarring multiple files from tarred directories and subdirectories

Hi, I want to untar all log files from following tarred directory hierarchy Log_files.tar.gz/subject*.tar.gz/project*/*.log It means there are subject1.tar.gz to subject9.tar.gz and in those tarred subect directories there are project1 - project5 directories and in those directories there... (2 Replies)
Discussion started by: rv_trojan
2 Replies

6. Shell Programming and Scripting

Error in concatenating multiple files from subdirectories

I want to concatenate multiple files recursively from sub-directories intoone file in Linux. I saved the following script as script.sh in $HOME/testing1 where I have several subdirectories and .txt files into them. I ran script.sh from the command prompt of $HOME/testing1 as ./script.sh. But it... (3 Replies)
Discussion started by: raj284
3 Replies

7. Shell Programming and Scripting

Problem in concatenating multiple files from subdirectories

I want to concatenate multiple files recursively from sub-directories intoone file in Linux. I saved the following script as script.sh in $HOME/testing1 where I have several subdirectories and .txt files into them. I ran script.sh from the command prompt of $HOME/testing1 as ./script.sh. But it... (3 Replies)
Discussion started by: raj284
3 Replies

8. UNIX for Dummies Questions & Answers

Compress multiple files at one go

I want to compress all the files which are three years older ..I have thousands of files... 1) This doesnt work find ./ -type f -mtime +1176 -print | xargs -n1 -i tar -cvf {} Errror tar: Missing filenames Probably because of - find ./ -type f -mtime -1 -print returns - " ./temp.txt"... (6 Replies)
Discussion started by: kedar.mehta
6 Replies

9. Shell Programming and Scripting

Compress multiple files

Hi Friends, Can anyone help me out with compressing multiple files. I have multiple files in directory , I have to compress these into a single file, I tried using gzip -r outfile.gz file1 file2 file3. It is not working Thanks in advance for your help S :) (5 Replies)
Discussion started by: sbasetty
5 Replies

10. UNIX for Dummies Questions & Answers

sftp multiple files and subdirectories

Hi, I'm new to using the sftp command prompt within the unix shell (usually I just use an FTP windows program). I've successfully connected to a remote server from within ssh. I've also been able to copy multiple files using the mget command e.g. mget *.html How do I copy all files,... (3 Replies)
Discussion started by: robbieg
3 Replies
Login or Register to Ask a Question