- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- deletion of files in single stroke
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
Forums
Discussions
Discussions
Discussions
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
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
01-13-2005 04:53 PM
01-13-2005 04:53 PM
deletion of files in single stroke
i have a directory wherein system puts thousands of files everyday ..now i have above 5000 files in that directory containing files of 'nov','dec','jan'...
currently we are facing space problem...
so
can anyone tell me how can i delete files of 'nov' & 'dec' in a single stroke ?
i thought of following:
for file in `ls -lrt|grep 'dec'|awk '{print $9}'`
do
rm -fr $file
done
is this correct?
Will find command be of any help? if yes,how?
thanks all,
regards
ABHI k
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2005 05:39 PM
01-13-2005 05:39 PM
Re: deletion of files in single stroke
you might want to use the find command:
first see which files you select with:
# find /dirname -mtime +12 -exec ll {} \;
where you select all files modified 12 days ago or more
and display them.
if oke
then use
# find /dirname -mtime +12 -exec rm {} \;
for removal
good luck.
Henk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2005 05:48 PM
01-13-2005 05:48 PM
Re: deletion of files in single stroke
$ ls -1 | grep "nov|dec" | xargs rm -rf
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2005 06:03 PM
01-13-2005 06:03 PM
Re: deletion of files in single stroke
"grep" in my previous message.
$ ls -1 | egrep "nov|dec" | xargs rm -rf
Since egrep is going to be obsolete soon, you
can do the same thing using "grep":
$ ls -1 | grep -e nov -e dec | xargs rm -rf
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2005 06:03 PM
01-13-2005 06:03 PM
Re: deletion of files in single stroke
thanks for the suggestion,
but i don't want to check the access/modify peroid while deleting the these files.
i must delete them,only problem is that the
count is huge( above 5000)...
i must preserve the files for "january"..
but i need to delete "nov" ,"dec" files..
any comments on the 'for' loop?
regards
ABHI K
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2005 06:40 PM
01-13-2005 06:40 PM
Re: deletion of files in single stroke
the loop looks fine but it removes not only
-r--r--r-- 1 root sys 4585 dec 13 23:59 syslog.log.13-dec-04
but also the files of recent date with nov/dec in the name :
-r--r--r-- 1 root sys 963 jan 13 23:59 deco.log.13-jan-05
so be carefull.
regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2005 06:56 PM
01-13-2005 06:56 PM
Re: deletion of files in single stroke
the problem with deleting huge number of files only gives a problem if you exceed the max length for the command.
So your approach with a loop is correct as it only deletes one file in each pass.
If you have a certain filename format, wou may want to limit your ls -1 with wildcards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2005 08:13 PM
01-13-2005 08:13 PM
Re: deletion of files in single stroke
you can avoid deleting files which contain dec in the name with
grep '_dec_'
_ is blank
greetings,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2005 01:55 AM
01-14-2005 01:55 AM
Re: deletion of files in single stroke
for FILE in `ls -1 *Nov*`
do
echo $FILE
gzip $FILE
done
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2005 02:22 AM
01-14-2005 02:22 AM
Re: deletion of files in single stroke
i too think that find would be the better way.
Anyway if you want a loop in order to choose in some strange way, eg. deleting all files except March and June, I suggest you to avoid building a long argument list as in ur example, instead use a pipeline.
To do that find a command that write on stdout the names you want to delete and pipe this command with:
while read fname; do rm -f $fname; done
for instance
ll | awk '$6 != "Mar" && $6 != "Jun" {print $9}' | while read fname; do rm -f $fname; done
the awk should (check it please) print names of files with date not in March or June, the while loops for all this names using one for every loop and so avoiding the possible problem of having too much args on command line
hope it helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2005 01:32 AM
01-19-2005 01:32 AM
Re: deletion of files in single stroke
for file in *-dec-*
do
rm -f $file
done