Sponsored Content
Top Forums Shell Programming and Scripting Help - To copy and compress files one day ago Post 302965890 by JackyJohn on Thursday 4th of February 2016 05:41:36 AM
Old 02-04-2016
Dear Rudic,

Sorry about code tags, actually I didn't know how do it.

@Don, Please see in line my answers to your queries.

Do you want to COPY and compress or MOVE and compress? (I.e., do you want to leave an unmodified version of the file where it is while creating a compressed version of the file somewhere else, or do you just want to create a compressed version of the file somewhere else and remove the original file?)

[Jacky]: I want to COPY and compress files in a single command line using zip/gzip or any other command. I dont want to disturb oringinal files in the source directory (/dump/traces/...)

What is the name of the directory containing these files?
[Jacky]:
Source Dir = /opt/TGS/traces
Target Dir = /dump/old_traces


What is the name of the directory in which you want to create the compressed copies of your files?
[Jacky]: /dump/old_traces


What utility do you want to use to compress your files? (Some possibilities include compress , pack , and zip .)
[Jacky]: zip

What do you mean by yesterday? (Are you looking for files that are 24 to 48 hours old when you run the script? Or, are you looking for files that were created between midnight at the start of yesterday and midnight at the start of today?)

[Jacky]: For example, below you can see the list of files. So now I want to copy/compress all files of 3rd Feb only (i.e. yesterday).


Code:
-rw-r--r--   1 rtp99    dba         228K Feb  3 00:57 RtpTrcError.0096
-rw-r--r--   1 rtp99    dba         289K Feb  3 01:57 RtpTrcError.0097
-rw-r--r--   1 rtp99    dba         228K Feb  3 02:57 RtpTrcError.0098
-rw-r--r--   1 rtp99    dba         228K Feb  3 03:57 RtpTrcError.0099
-rw-r--r--   1 rtp99    dba         229K Feb  3 04:57 RtpTrcError.0000
-rw-r--r--   1 rtp99    dba         229K Feb  3 05:57 RtpTrcError.0001
-rw-r--r--   1 rtp99    dba         228K Feb  3 06:57 RtpTrcError.0002
-rw-r--r--   1 rtp99    dba         244K Feb  3 07:58 RtpTrcError.0003
-rw-r--r--   1 rtp99    dba         228K Feb  3 08:58 RtpTrcError.0004
-rw-r--r--   1 rtp99    dba         228K Feb  3 09:57 RtpTrcError.0005
-rw-r--r--   1 rtp99    dba         228K Feb  3 10:58 RtpTrcError.0006
-rw-r--r--   1 rtp99    dba         273K Feb  3 11:58 RtpTrcError.0007
-rw-r--r--   1 rtp99    dba         229K Feb  3 12:58 RtpTrcError.0008
-rw-r--r--   1 rtp99    dba         250K Feb  3 13:58 RtpTrcError.0009
-rw-r--r--   1 rtp99    dba         229K Feb  3 14:58 RtpTrcError.0010
-rw-r--r--   1 rtp99    dba         259K Feb  3 15:58 RtpTrcError.0011
-rw-r--r--   1 rtp99    dba         228K Feb  3 16:58 RtpTrcError.0012
-rw-r--r--   1 rtp99    dba         244K Feb  3 17:58 RtpTrcError.0013
-rw-r--r--   1 rtp99    dba         302K Feb  3 18:58 RtpTrcError.0014
-rw-r--r--   1 rtp99    dba         280K Feb  3 19:58 RtpTrcError.0015
-rw-r--r--   1 rtp99    dba         243K Feb  3 20:58 RtpTrcError.0016
-rw-r--r--   1 rtp99    dba         228K Feb  3 21:58 RtpTrcError.0017
-rw-r--r--   1 rtp99    dba         229K Feb  3 22:59 RtpTrcError.0018
-rw-r--r--   1 rtp99    dba         228K Feb  3 23:58 RtpTrcError.0019
-rw-r--r--   1 rtp99    dba         230K Feb  4 00:59 RtpTrcError.0020
-rw-r--r--   1 rtp99    dba         240K Feb  4 01:59 RtpTrcError.0021
-rw-r--r--   1 rtp99    dba         229K Feb  4 02:59 RtpTrcError.0022
-rw-r--r--   1 rtp99    dba         235K Feb  4 03:59 RtpTrcError.0023
-rw-r--r--   1 rtp99    dba         229K Feb  4 04:59 RtpTrcError.0024
-rw-r--r--   1 rtp99    dba         229K Feb  4 05:59 RtpTrcError.0025
-rw-r--r--   1 rtp99    dba         228K Feb  4 06:59 RtpTrcError.0026
-rw-r--r--   1 rtp99    dba         243K Feb  4 07:59 RtpTrcError.0027
-rw-r--r--   1 rtp99    dba         229K Feb  4 08:59 RtpTrcError.0028
-rw-r--r--   1 rtp99    dba         287K Feb  4 09:59 RtpTrcError.0029
-rw-r--r--   1 rtp99    dba         338K Feb  4 11:00 RtpTrcError.0030
-rw-r--r--   1 rtp99    dba         238K Feb  4 11:59 RtpTrcError.0031
-rw-r--r--   1 rtp99    dba         226K Feb  4 13:00 RtpTrcError.0032
-rw-r--r--   1 rtp99    dba         180K Feb  4 13:35 RtpTrcError.0033



Thanks,

Regards,
Moderator's Comments:
Mod Comment Directions, including a tutorial video, showing you how to use CODE tags and ICODE tags for sample input, sample output, and for code segments was sent to you when you received your first warning for not using CODE tags.

Please review that tutorial and start formatting your posts correctly yourself. Don't depend on moderators and administrators to clean up your posts.

Last edited by Don Cragun; 02-04-2016 at 02:46 PM.. Reason: Add CODE and ICODE tags.
 

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Compress and copy a Folder

hi Buddies , How can i Compress and move a folder through UNIX completely to windows 2000 through FTP. (1 Reply)
Discussion started by: scorpiyanz
1 Replies

2. Shell Programming and Scripting

Cron to run first day of month to calculate date 3 months ago

Hi, I would like to find out how can i calculate a date which is 3 months ago. I intend to run a cron job on the 1st of every month, and calculate the month 4 months earlier from the date. For example, if today's date is 1st May 2007, i would like to return 012007( January 2007). i can get... (1 Reply)
Discussion started by: new2ss
1 Replies

3. UNIX for Dummies Questions & Answers

Copy and compress

Is there a way to copy a file and compress it at the same time? I realize the file can be copied and then compressed, but I was wondering if it's possible to do it in a one-line command and for that matter, if it would be more efficient to perform the operation with a one-line command? Thanks. (5 Replies)
Discussion started by: here2learn
5 Replies

4. UNIX for Dummies Questions & Answers

Copy Compress as one command

Hi, I need to copy and compress files in a directory in single line of command. I am able to copy and gzip files in one command but not directory. Command that I am using for copying directory is below : cp -rp /u01/app/<directory> /u01/app/backup |gzip -r /u01/app/backup/<directory> ... (10 Replies)
Discussion started by: findprakash
10 Replies

5. Shell Programming and Scripting

How to extract the day of the year and use that info to copy a file remotely

Hello, Thank you in advance for helping a newbie who is having great trouble with this simple task. I'm allowed to copy one file remotely each night due to bandwidth restrictions. A new file gets generated once a day, and I need to copy the previous day's file. Here is what I'd like to do:... (1 Reply)
Discussion started by: tmozdzen
1 Replies

6. Shell Programming and Scripting

Help - compress file one day ago

Hi All, I'm a new member of this Forum. I have need your help to handle this request. "Compress a file name not of today but of yesterday only". For example 0 mar 08:00 TEST_RPT_STATUS_M1I_CMI20120320.xls 20 mar 08:00 TEST_RPT_STATUS_M1I_CMI20120320.rep 21 mar 08:00... (6 Replies)
Discussion started by: gio123bgg
6 Replies

7. Shell Programming and Scripting

script to compress files in directory that changes its name every day

Hi all I have the following script that should compress a file in a directory: # compress log files older than 2 days find /u01/easydone/DBDUMPS/*.dmp -mtime +2 -exec gzip {} \; BUT the problem is that these files that I want to compress are inside a directory with following format: ... (5 Replies)
Discussion started by: fretagi
5 Replies

8. UNIX for Dummies Questions & Answers

Move the files between Current day & a previous day

Hi All, I have a requirement where I need to first capture the current day & move all the files from a particular directory based on a previous day. i.e move all the files from one directory to another based on current day & a previous day. Here is what I am trying, but it gives me errors.... (2 Replies)
Discussion started by: dsfreddie
2 Replies

9. Shell Programming and Scripting

How to copy all structure folder create last day?

HI All, please help , i got same case . i want copy folder and directory create yesterday. for sample below : drwxr-xr-x 4 apps apps 33 Nov 23 04:00 xxxxxx@gmai.com drwxr-xr-x 4 apps apps 33 Nov 23 04:00 yyyyyyy@gmail.com drwxr-xr-x 4 apps apps 33 Nov 24 04:00... (2 Replies)
Discussion started by: fajar_3t3
2 Replies
All times are GMT -4. The time now is 11:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy