- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Removing files containing "-" character at the...
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
тАО10-07-2008 02:56 AM
тАО10-07-2008 02:56 AM
I'm attempting to remove files which contain the "-" at the start of its filename, which however failed (see output below).
danny@dimebag ~/nokia-bss-input $ rm -rf "-detail.cs"
rm: invalid option -- e
Try `rm --help' for more information.
danny@dimebag ~/nokia-bss-input $ ls -l
total 574
-rw-r--r-- 1 danny danny 39071 Sep 4 19:07 -detail.csv
-rw-r--r-- 1 danny danny 1340 Sep 4 19:07 -summary.csv
danny@dimebag ~/nokia-bss-input $ rm -i "-summary.csv"
rm: invalid option -- s
Try `rm ./-summary.csv' to remove the file `-summary.csv'.
Try `rm --help' for more information.
May I know what other methods that I could use to remove files with such names?
Thanks
Danny
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-07-2008 03:01 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-07-2008 03:08 AM
тАО10-07-2008 03:08 AM
Re: Removing files containing "-" character at the beginning of its filename
rm -- -summary.csv
This works with all programs that use a POSIX-compliant getopt() function to parse their options.
(e.g. the getopt() function included in the glibc used in almost all Linux distributions)
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-07-2008 02:57 PM
тАО10-07-2008 02:57 PM
Re: Removing files containing "-" character at the beginning of its filename
Yet another way to handle non-standard file names (those containing special characters; non-printing ones; file names with whitespace; file names with hyphens as their first character) is to find their inode number and then use that to remove them. This works thusly:
# cd /tmp
# touch -- -badfile
# ls -il -- -badfile
7151 -rw-r--r-- 1 root sys 0 Oct 7 18:54 -badfile
#
Note that the inode number of the file is 7151. Inodes are *only* unique within a filesystem, so we use '-xdev' in the 'find' below to *not* cross mountpoints.
# find /tmp -xdev -inum 7151 -exec rm {} \;
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2008 10:16 PM
тАО10-08-2008 10:16 PM
Re: Removing files containing "-" character at the beginning of its filename
Quoting doesn't help since they are removed by the shell before being passed to rm.
Besides the Standard "--", you can use "rm -i" with a wildcard or JRF's find.
But you can simply use an absolute or relative path:
rm -rf ./-detail.cs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2008 11:02 PM
тАО10-08-2008 11:02 PM
Re: Removing files containing "-" character at the beginning of its filename
Remove a file in the current directory whose name starts with - or *
or some other character that is special to the shell:
rm ./-filename
rm \*filename
and this is the output
unix # rm ./-detail.cs
sandchau as root@unix [/tmp]
#
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-14-2008 01:02 AM
тАО10-14-2008 01:02 AM
Re: Removing files containing "-" character at the beginning of its filename
You want to use the single quote '
so your command would be...
rm -rf '-detail.cs' '-summary.csv'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-14-2008 11:28 PM
тАО10-14-2008 11:28 PM
Re: Removing files containing "-" character at the beginning of its filename
This has nothing to do with quoting and the shell. "-" is not special to the shell but special to each command.
It helps if you read the other replies.