- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Operations on irregularly named files in a dir...
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
тАО04-06-2011 04:06 AM
тАО04-06-2011 04:06 AM
There are 10 files in a directory called:
a
b
1a
\
*
x
-
\*
9
0
what scripting code/ awk / perl would you use to (safely and robustly) delete all files that d0 not start with an alpha or numeric ?
thks in advance
Solved! Go to Solution.
- Tags:
- rm
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2011 04:38 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2011 05:05 AM
тАО04-06-2011 05:05 AM
Re: Operations on irregularly named files in a directory
You could do:
# cd mydirectory
# ls -1 | perl -ne 'm{^[a-zA-Z0-9]} or print'
Note that the 'ls -1' is a numeric ONE.
If you are satisfied with the output of the above, which would be the files to be *removed* then _change_ the 'print' to 'unlink'. Doing so will remove those files.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2011 05:49 AM
тАО04-06-2011 05:49 AM
Re: Operations on irregularly named files in a directory
thks ...the inode solution is good but how would you script that ?
The perl is slick ...but how would one script the end bit ...to avoid
rm "*" (lol) and rm "\" ....
as a
for i in `perl stuff here`
loop would cause $i (in the case if *) to list all the files....
so doing
rm $i would effectively be doing rm "list of file" or rm *
thks !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2011 05:57 AM
тАО04-06-2011 05:57 AM
Re: Operations on irregularly named files in a directory
ls -1 | perl -ne 'm{^[a-zA-Z0-9]} or unlink'
produces the same output / full file list without any deletions ..unless Im getting the syntax wrong ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2011 06:04 AM
тАО04-06-2011 06:04 AM
Re: Operations on irregularly named files in a directory
OK, it's reasonable to skip the dot files :-) Your original description of your problem didn't suggest that requirement :-)
#cd /path && ls -1 | perl -ne 'm{^[.a-zA-Z0-9]} or print'
Note that I added a dot ('.') to the permitted character list.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2011 11:07 AM
тАО04-06-2011 11:07 AM
Re: Operations on irregularly named files in a directory
I think it's not common to have nonprinting characters in filenames, so there's no need to script it. Anyway, I like to sleep well and wouldn't automatize (e.g. through cron) such a script that checks for such files and deletes those. I like to do this manually, that's why I said "rm -i". Just to be sure nothing important get deleted.
Unix operates with beer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2011 06:36 PM
тАО04-06-2011 06:36 PM
Re: Operations on irregularly named files in a directory
I think it's not common to have nonprinting characters in filenames, so there's no need to script it.
wow Viktor ...thats a very special statement there. I bow to your superior knowledge on whats not common and what scripts are "needed" for everyone in the SA world.
;-)
...Perhaps there should be a new thread called "It happened to me" to get a sense of the odd things that have happened ..
Seriously though, the fact that the question has been asked is indicative of a "need". It only needs to occur 1ce for it to be relevant to the question asker. ...of course saying "I dont know" ...or nothing might also be an option
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2011 06:42 PM
тАО04-06-2011 06:42 PM
Re: Operations on irregularly named files in a directory
yes the dot files are excluded from the list/ requirement. I do like the simiplicity of the perl solution ...I m still unclear though how you would delete the found files ....
a ls -1 | perl -ne 'm{^[.a-zA-Z0-9]} or unlink'
then an ll shows
all the (original) files *, \ etc
thks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2011 07:08 PM
тАО04-06-2011 07:08 PM
Re: Operations on irregularly named files in a directory
rm -i !([A-Za-z0-9]*)
- Tags:
- pattern