- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- deleting a lot of files in a directory
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
тАО02-23-2006 01:56 AM
тАО02-23-2006 01:56 AM
deleting a lot of files in a directory
Hi,
I wanna make a script to delete alot of files in a directory.
Today I do it this way but it is not a good solution:
ls -1 VFSweden1LIB1051001* | xargs rm
ls -1 VFSweden1LIB1051002* | xargs rm
ls -1 VFSweden1LIB1051003* | xargs rm
ls -1 VFSweden1LIB1051004* | xargs rm
ls -1 VFSweden1LIB1051005* | xargs rm
and so on..
I want to create a script doing this for me.
Complete name of files:
VFSweden1LIB105110100010050007
I want the script to replace the:
1051101
with
1051102, 1051103 and so on..
I hope you understand me and can help me with this..
Thanks and Regards,
Paul
- Tags:
- rm
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-23-2006 02:09 AM
тАО02-23-2006 02:09 AM
Re: deleting a lot of files in a directory
# cd chosen_path
# find . -xdev -type f -name "VFSweden1LIB10511*" | xargs rm
Regards!
...JRF...
- Tags:
- find
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-23-2006 02:17 AM
тАО02-23-2006 02:17 AM
Re: deleting a lot of files in a directory
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-23-2006 03:53 AM
тАО02-23-2006 03:53 AM
Re: deleting a lot of files in a directory
IMHO...you don't need a script just the "rm" command with a wildcard character in the filename serving as a placeholder for all similarly named files. Assuming that your current working dir is the one that contains those files then you could simply do:
# rm VFSweden1LIB105*00010050007
cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-23-2006 08:06 PM
тАО02-23-2006 08:06 PM
Re: deleting a lot of files in a directory
why not simply?
rm VFSweden1LIB105110[1-9]00010050007
This will remove file from VFSweden1LIB105110100010050007 to
VFSweden1LIB105110900010050007
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-23-2006 11:16 PM
тАО02-23-2006 11:16 PM
Re: deleting a lot of files in a directory
maybe the "mtime" switch to "find" can also help. (assuming the files are timestamped)
or also create a loop that increments a counter starting from 1051101 ...
e.g.
count=1051101
while test $count -lt 1051121
do
#do something for 0,1,2...9
echo "deleting VFSweden1LIB"$count
rm "VFSweden1LIB"$count
count=$(($count+1))
done
hope this helps too!
kind regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-23-2006 11:36 PM
тАО02-23-2006 11:36 PM
Re: deleting a lot of files in a directory
# cd chosen_path
# find . -xdev -type f -name "VFSweden1LIB10511*" | awk '{print "rm ",$1}' > rm_script
Then you can visually check it to see if it's about the right size and then run it.
chmod +x rm_script
./rm_script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2006 02:28 AM
тАО02-24-2006 02:28 AM
Re: deleting a lot of files in a directory
By the way, if you like using xargs in general, but especially when for file removal, the -t (trace) option is a nice and easy way to see exaclty what is happening or being removed:
example:
ls /tmp/garbage* | xargs -t rm
rm /tmp/garbage1 /tmp/garbage2 /tmp/garbage3
Or Even nicer when combined with the xargs -i (insert) option:
# ls /tmp/garbage* | xargs -t -i rm {}
rm /tmp/garbage1
rm /tmp/garbage2
rm /tmp/garbage3
If you want to use this in a script, be sure to redirect error output to stdout, because the trace output is considered debug or error output.
example: (no error redirect):
# ls /tmp/garbage* | xargs -t -i rm {} > out.txt
rm /tmp/garbage1
rm /tmp/garbage2
rm /tmp/garbage3
# cat out.txt
{{{EMPTY}}}
example: (with error redirected to stdout)
# ls /tmp/garbage* | xargs -t -i rm {} > out.txt 2>&1
{{{No screen Output}}}
# cat out.txt
rm /tmp/garbage1
rm /tmp/garbage2
rm /tmp/garbage3
example: If you want output to show in both file and screen, use '|tee' instead of '>' for the initial redirect of stdout to a file:
# ls /tmp/garbage* | xargs -t -i rm {} |tee out.txt 2>&1
rm /tmp/garbage1
rm /tmp/garbage2
rm /tmp/garbage3
# cat out.txt
rm /tmp/garbage1
rm /tmp/garbage2
rm /tmp/garbage3