- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- how to rm files in all subdirs,
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
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-02-2010 03:19 PM
тАО02-02-2010 03:19 PM
Is it possible to do with rm -r, I need to delete all .zip files in number of subdir.
Only files need to be deleted, subdirs should stay as is.
Will be good if no need for any looping.
Tx to all
D
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-02-2010 04:13 PM
тАО02-02-2010 04:13 PM
Solution> Is it possible to do with rm -r, [...]
I don't see how. The usual tool for a task
like this would be "find".
man find
Look for "-exec".
Perhaps something like:
find dir -name '*.zip' -exec ls {} \;
If you like the list, then change "ls" to
"rm".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-03-2010 06:27 AM
тАО02-03-2010 06:27 AM
Re: how to rm files in all subdirs,
As Steven noted, the manpages are your friend. That said, you could do:
# find /path -xdev -type f -name "*.zip -exec rm {} +
The '-xdev' option prevents 'find()' from crossing mountpoints. The '-type f' limits things to files (and not directories). The '-name "*.zip"' looks for the files with the '.zip' extension. You must quote the name so that the shell doesn't expand the "*" wildcard character. The quotes allow the expression to be passed intact to 'find()'.
The '-exec rm {} +' says to bundle up multiple arguments and pass them to 'rm'. This is very efficient. If you use the '-exec rm {} \;' form then a 'rm' process is spawned for *every* file that needs to be removed. This can really warm your processor :-)
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-03-2010 07:07 AM
тАО02-03-2010 07:07 AM
Re: how to rm files in all subdirs,
Missed a quotation mark (after "*.zip)?
> [...] The '-type f' limits things to files
> (and not directories). [...]
Although, if you're foolish enough to have a
directory named "*.zip", it might be useful
to get a nice error message back from "rm".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-03-2010 10:35 AM
тАО02-03-2010 10:35 AM
Re: how to rm files in all subdirs,
It's simple now, I"m new in unix, so it bit hard to get used all this ksh, for me it's look to compact ant too powerful. Already rm'ed some good stuff0).
I also was looking how to extract just file name from the path, something like perl's split command.
Tx again to all.
J
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-03-2010 12:17 PM
тАО02-03-2010 12:17 PM
Re: how to rm files in all subdirs,
> I also was looking how to extract just file name from the path, something like perl's split command.
You have that as 'basename' [ and its complementary 'dirname' ]:
# FILE=/usr/bin/perl
# echo $(basename $FILE)
perl
...or if you prefer, use the shell's parameter substitution:
# FILE=/usr/bin/perl
# echo ${FILE##*/}
perl
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-03-2010 08:27 PM
тАО02-03-2010 08:27 PM
Re: how to rm files in all subdirs,
I started with "ls" instead of "rm" for a
reason. Trust no one, especially yourself,
I always say.