- 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 08:15 PM
тАО04-06-2011 08:15 PM
Re: Operations on irregularly named files in a directory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-07-2011 10:31 AM
тАО04-07-2011 10:31 AM
Re: Operations on irregularly named files in a directory
> then an ll shows all the (original) files *, \ etc
Oops, try this:
# ls -1 | perl -nle 'm{^[.a-zA-Z0-9]} or unlink'
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-07-2011 11:31 AM
тАО04-07-2011 11:31 AM
Re: Operations on irregularly named files in a directory
...and the addition of the '-l' switch is a kludge which hides a common (?) oversight.
The behavior is documented in 'perlrun' and in part says:
First, it automatically chomps $/ (the input record separator) when used with -n or -p. Second, it assigns $\ (the output record separator) to have the value of octnum so that any print statements will have that separator added back on. If octnum is omitted, sets $\ to the current value of $/ .
For every line read from our pipe, the filename already ends with a newline character. In the absence of the '-l' switch we let the print() honor what's there. That's fine for pretty printing, *but* means that 'unlink()" sees a string with the newline which does *not* match the file we think it should.
Adding the '-l' "fixes" the problem (ever so obtusely) since an automatic chomp() of the newline character occurs, leaving 'unlink()' to be handed a filename that can be found.
All this to say, it would have been much better to have written:
# ls -1|perl -ne 'chomp;m{^[.a-zA-Z0-9]} or print "$_\n"'
...to print, and:
# ls -1|perl -ne 'chomp;m{^[.a-zA-Z0-9]} or unlink'
...to actually remove files.
Or, if you prefer to be a a bit long-handed, say:
' ... or unlink $_'
By the way, unlink() will normally not remove directories.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-08-2011 08:49 PM
тАО04-08-2011 08:49 PM
Re: Operations on irregularly named files in a directory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-08-2011 08:52 PM
тАО04-08-2011 08:52 PM
Re: Operations on irregularly named files in a directory
- « Previous
-
- 1
- 2
- Next »