- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: simple rm script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-25-2006 05:12 AM
тАО10-25-2006 05:12 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-25-2006 05:14 AM
тАО10-25-2006 05:14 AM
Re: simple rm script
- Tags:
- rm
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-25-2006 05:19 AM
тАО10-25-2006 05:19 AM
Re: simple rm script
Please define what you mean by "txt" --- an extension to a filename? --- an ASCII file as opposed to a binary one?
Do you want to recursively descend a directory?
Do you need help with the process of selecting and removing? Do you need help setting up a 'crontab'?
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-25-2006 05:40 AM
тАО10-25-2006 05:40 AM
Re: simple rm script
Script follows one that and safer than to execute rm *.txt :
for G in `ll |grep .sh |awk '{print $9}'`
do
rm $G
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-25-2006 05:46 AM
тАО10-25-2006 05:46 AM
Re: simple rm script
In this example, a cron job, which will be run as root, is scheduled. The job deletes all .txt files in /yourdir and its subdirectories at 11:00pm every day.
# grep -q root /var/adm/cron/cron.allow || echo root >> /var/adm/cron/cron.allow
# crontab -l root > /tmp/crontab.root
# echo "00 23 * * * find /yourdir -name '*.txt' -type f -exec rm -f {} 1> /dev/null \;" >> /tmp/crontab.root
# crontab < /tmp/crontab.root
# rm -f /tmp/crontab.root
For obvious reasons, care must be taken with a job such as this.
PCS
- Tags:
- crontab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-25-2006 07:23 AM
тАО10-25-2006 07:23 AM
Re: simple rm script
I'm not sure how this is safer or how it is "txt"? Also did you want to escape the "."?
But you can improve your script:
for G in $(ls | fgrep .sh); do rm $G; done
But this is the same as: rm *.sh.
Unless you really wanted to remove *.sh* files?
>spex
00 23 * * * find /yourdir -name '*.txt' -type f -exec rm -f {} 1> /dev/null \;
Any reason you want to redirect stdout from the rm command? You don't get anything, only to stderr. Did you mean "2>"?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-25-2006 07:27 AM
тАО10-25-2006 07:27 AM
Re: simple rm script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-25-2006 01:34 PM
тАО10-25-2006 01:34 PM
Solutionrm /var/tmp/specialdir/*.txt
then you simply add that to crontab and pick a time at night to run this command. If there are multiple commands needed, put them into a file, add an interpreter line at the top and make it executable. Then add the full path to the script to crontab. Something like this:
#!/usr/bin/sh
rm /var/tmp/specialdir1/*.txt
rm /var/tmp/specialdir2/*.txt
rm /var/tmp/specialdir3/*.txt
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-25-2006 07:19 PM
тАО10-25-2006 07:19 PM
Re: simple rm script
For me rm is rather silent.
I would prefer to embedd the rm command inside a find and log this. This would
improve security and visability.
The crontab entry would look like this:
(10 minutes before midnight, every day of the week)
50 23 * * * /root/adm/bin/text_clean.sh > /root/adm/logs/text_clean.log 2>&1
The script would look like this:
vi text_clean.sh
#!/sbin/sh
# Script to clean txt files by Tamara
find /path/textfiles -name "*txt" -type f -print -exec rm {} \;
#end of script
Now you could at a later stage , put a time
criteria in your find. For example to delete only the *.txt files older then 1 day.
The find command would look like this:
find /path/textfiles -name "*txt" -type f -mtime +1 -print -exec rm {} \;
You can also put multiple find commands in the script. So your housekeeping collection
can grow over time as the need arises.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-25-2006 08:24 PM
тАО10-25-2006 08:24 PM
Re: simple rm script
simply add in your crontab the command:
cd
at more conveninet time for you.
HTH,
Art