->Title Page
->Intro
->Unix
-->Overview
-->File Structure
-->Online Manual
-->Basic Commands
-->Additional Commands
-->Login files
-->Special characters
-->Miscellaneous Tips
->Strange names
--->Advanced wildcards
--->Terminal input
--->Remote shell
--->Loops in scripts
--->More tricks
-->Things to try
->Vi editor
->Mirror sites
->Further reading

[ Up ]
[Prev][Home][Next]
[Author]

Unix ---> Removing files with strange names

There may come a time that you will discover that you have somehow created a file with a strange name that cannot be removed through conventional means. This section contains some unconventional approaches that may aid in removing such files.

Files that begin with a dash can be removed by typing


    rm ./-filename
A couple other ways that may work are


    rm -- -filename
and


    rm - -filename
Now let's suppose that we an even nastier filename. One that I ran across this summer was a file with no filename. The solution I used to remove it was to type


    rm -i *
This executes the rm command in interactive mode. I then answered "yes" to the query to remove the nameless file and "no" to all the other queries about the rest of the files.

Another method I could have used would be to obtain the inode number of the nameless file with


    ls -i
and then type


    find . -inum number -ok rm '{}' \;
where number is the inode number.

The -ok flag causes a confirmation prompt to be displayed. If you would rather live on the edge and not be bothered with the prompting, you can use -exec in place of -ok.

Suppose you didn't want to remove the file with the funny name, but wanted to rename it so that you could access it more readily. This can be accomplished by following the previous procedure with the following modification to the find command:


    find . -inum number -ok mv '{}' new_filename \;

Please notify owners of webpages with outdated links to these pages

Find this site useful? Want to give something back?

© 1993-2001 Christopher C. Taylor