LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-12-2010, 11:28 PM   #1
elainelaw
Member
 
Registered: Jan 2008
Posts: 258

Rep: Reputation: 30
script


I have a directory there are many files are writing to it , I would like to write a script to do that , can please provide the advise .

archive all files to one single file in every 30 days , and then remove these old files .


Thx .
 
Old 04-13-2010, 12:40 AM   #2
bsat
Member
 
Registered: Feb 2009
Posts: 347

Rep: Reputation: 72
Your questions seems a little vague, can mention what kind of files are they ? Simple text files can be merged using just "cat" command, and you can use the "crontab" to schedule the running of the script. If you have tries some thing please post your script also.
 
Old 04-13-2010, 01:29 AM   #3
elainelaw
Member
 
Registered: Jan 2008
Posts: 258

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by bsat View Post
Your questions seems a little vague, can mention what kind of files are they ? Simple text files can be merged using just "cat" command, and you can use the "crontab" to schedule the running of the script. If you have tries some thing please post your script also.
Thx reply ,

yes , it is text file , I do not have anything to test before .

Thx
 
Old 04-13-2010, 01:47 AM   #4
bakdong
Member
 
Registered: Apr 2009
Posts: 214

Rep: Reputation: 44
Concatenate all the files in order of filename:

$ mkdir cattest

$ cd cattest/
$ echo 1 > 1.txt;
$ echo 2 > 3.txt;
$ echo 3 > 2.txt;

$ ls
1.txt
2.txt
3.txt

$ cat *
1
3
2

$ cat * > all.txt
$ ls
1.txt
2.txt
3.txt
all.txt

$ cat *
1
3
2
1
3
2

Archive all txt files into a tar file:

$ rm all.txt
rm: remove `all.txt'? y

$ tar cvf all.tar *.txt
1.txt
2.txt
3.txt

$ 'ls'
1.txt 2.txt 3.txt all.tar


$ tar -tf all.tar
1.txt
2.txt
3.txt
 
0 members found this post helpful.
Old 04-13-2010, 08:58 PM   #5
elainelaw
Member
 
Registered: Jan 2008
Posts: 258

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by bakdong View Post
Concatenate all the files in order of filename:

$ mkdir cattest

$ cd cattest/
$ echo 1 > 1.txt;
$ echo 2 > 3.txt;
$ echo 3 > 2.txt;

$ ls
1.txt
2.txt
3.txt

$ cat *
1
3
2

$ cat * > all.txt
$ ls
1.txt
2.txt
3.txt
all.txt

$ cat *
1
3
2
1
3
2

Archive all txt files into a tar file:

$ rm all.txt
rm: remove `all.txt'? y

$ tar cvf all.tar *.txt
1.txt
2.txt
3.txt

$ 'ls'
1.txt 2.txt 3.txt all.tar


$ tar -tf all.tar
1.txt
2.txt
3.txt
thx reply , it seems a step to do it , can advise if want to run it as a script , how to do it ? thx
 
Old 04-13-2010, 09:24 PM   #6
bakdong
Member
 
Registered: Apr 2009
Posts: 214

Rep: Reputation: 44
The simple answer is: put all the commands in a file and run it, but I don't think that's what you really want. Maybe have a look here http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html for some info.
 
Old 04-14-2010, 03:50 AM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Hello elainelaw

I have read many of your questions and they are all difficult to answer because you do not give enough information. The English is hard to follow. Reading the English creatively to understand your thoughts it seems your thoughts are not clear either.

Many people have difficulty with English when asking questions here but their thoughts are clear and we can understand them.

Could you tell us something about yourself so we can better undertand you and so better help you?

Best

Charles
 
Old 04-14-2010, 04:02 AM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
Quote:
I have a directory there are many files are writing to it
Maybe you would also answer, with respect to he above, what application is creating the files in the directory you are
referring too?

Quote:
archive all files to one single file in every 30 days
When you say archive, are you referring to combining into one file, as demonstrated by bakdong, if so, maybe
you would explain why this option has been chosen (especially if the files become very large)?
Or are you perhaps referring to archiving as in combining all the files together like zipping them up on windows?
 
Old 04-14-2010, 04:15 AM   #9
bakdong
Member
 
Registered: Apr 2009
Posts: 214

Rep: Reputation: 44
Quote:
Originally Posted by grail View Post
Or are you perhaps referring to archiving as in combining all the files together like zipping them up on windows?
Which, btw, I also demonstrated:

Quote:
Archive all txt files into a tar file:

$ rm all.txt
rm: remove `all.txt'? y

$ tar cvf all.tar *.txt
1.txt
2.txt
3.txt

$ 'ls'
1.txt 2.txt 3.txt all.tar


$ tar -tf all.tar
1.txt
2.txt
3.txt
Add j or z to the tar options and you can also compress at the same time.

Last edited by bakdong; 04-14-2010 at 04:17 AM.
 
Old 04-14-2010, 06:49 AM   #10
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
Yeah sorry ... didn't look past the first bit as I thought it was more of th same at quick glance .. my bad
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script problem with ftp session exiting the script early edomingox Programming 5 02-23-2010 06:39 AM
How to get full path to script file inside script itself? And in case of sym links? maggus Linux - Newbie 3 05-28-2009 09:40 AM
Iptables (with masq) troubleshooting, very simple script attached script and logs. xinu Linux - Networking 13 11-01-2007 05:19 AM
i get an error message running php script inside a cgi script. repolona Linux - Software 0 02-22-2007 10:10 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 01:20 AM


All times are GMT -5. The time now is 06:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration