Zipping and moving

Hi,

I have got the script which find out the file that was modified 3 days ago now i want that all the files which fall into this category to be get zipped and then send to another directory...plz can u suggest me for that or any commands

For zipping use the zip -command or gzip, bzip2, compress, ... .
For "sending" files to another directory try the cp or mv commands. The 1st will copy, the 2nd will move the files.
Reading a list of files could be done with a combination of a while -loop together with the read command for example.

Generally you should read a shell scripting to tutorial to start learning about basic commands and shell usage. For example: Linux Shell Scripting Tutorial - A Beginner's handbook

Hi ,

I am using this command to find out the files modified within 3 days and now I want to send those files into another directory named test ,i want that inside test directory the zip file should reside .... but my this below command is not working..can u correct the below command

find /home/499633/scripts -iname "*.txt" -mtime -3| tar -cvzf /test/backup.tgz directory
 
find /home/499633/scripts -iname "*.txt" -mtime -3| xargs tar -cvzf /test/backup.tgz 

Hi,

I have written this command in a script file and then executing that script but it is showing error

can you post the script and the error message

Hi ,

Now i want to copy those filter files into the test directory can you please provide me the command to copy those selected files into the test directory and later I will zip that test folder later.

itkamaraj is trying to help you and asked a question for further information. Since neither itkamaraj nor any other user here (I assume) has any magic capabilities that would make them have a look at your code through your eyes. So help yourself by answering those people that try to help you. If you keep ignoring them and just ask a new question before answering the previous, do not expect to become further help.

Also what was not clear from the commands suggested so far? If you continue to just ask questions without answering previous or do not show own effort in using the hints given so far, I will set your status to read-only for this forum.

1 Like

Hi itkamaraj,

the error for u r command (find /home/499633/scripts -iname "*.txt" -mtime -3| xargs tar -cvzf /test/backup.tgz) that u were discussing is ...

xargs invalid option --c

find /home/499633/scripts -iname "*.txt" -mtime -3| xargs tar -cvzf /test/backup.tgz

i missed the tar command. check your syntax again

Hi,

Thanks a lot...but now upon executing this on cywgin..it is in output showing error ...
command not found...any idae wats d prblm..??

please always "post the exact error message" and what you tried.

unless, its very hard to assume and tell what is wrong

I have also tried executing by ./ne1.sh .....now the file is executed but the error is ...

tar: cowardly refusing to create an empty archive

wats d reason for that any guesses..!!

---------- Post updated at 10:09 AM ---------- Previous update was at 09:51 AM ----------

Hi,

Thanks a lot now the command is working ..the command finally is ....

find /home/Administrator/files -iname "*.txt" -mtime -3| xargs tar -cvzf /home/Administrator/output/backup.tgz

I am really thankful to you...but only the prblm is that when i go the output folder ..I see the tar backup..but when i unrar it thru win rar i got the complete folder structure lyk home then administrator and then finally the files but i want when my tar file unzipped it should directly contain file names only,,,!! any idea how to solve this..!!

mkdir /tmp/myfiles
find /home/Administrator/files -iname "*.txt" -mtime -3 | while read file
do
  cp $file /tmp/myfiles
done

tar -cvzf myfile.tgz /tmp/myfiles

[LEFT]Hi,

Again thanx alot for that guidance and i want now these task to be repeated after evry 3 hour in a day..so I have to gor for crontab...could you also plz provide the command for me that ..I mean d script ...so that this task executed after every 3 hour in a day..!!
[/LEFT]

---------- Post updated at 11:55 AM ---------- Previous update was at 11:47 AM ----------

Hi,

Nice scripts ..but upon execution it is creating folder named my files in /tmp directory and inside that directory no tar file is there...something missin..!!:frowning:

crontab -e.

I already gave you a link to the man page in your other thread.

Good luck. If you run into difficulties, please ask.

Hi,

can u provide me the script also so that i can execute the below command after every 3 hours in a day..

find /home/Administrator/files -iname "*.txt" -mtime -3 | while read file
do
  cp $file /tmp/myfiles
done
tar -cvzf myfile.tgz /tmp/myfiles

You already have the script.

The command you are looking for is crontab -e.

I already gave you a link to the man page in your other thread.

Good luck. If you run into difficulties, please ask.

Hi ,

Can you plz provide the shell script of corn so that this below command run in every 2 hr in a day..the command is

find /home/Administrator/files -iname "*.txt" -mtime -3| while read file
do
cp $file /home/Administrator/output
done
tar -cvzf myfile.tgz /home/Administrator/output
:eek:

---------- Post updated at 12:23 PM ---------- Previous update was at 12:21 PM ----------

Hi ,

In the script of urs that is

-mtime -3| while read file
do

the file is variable or what....?