Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to remove a file from a server via bash rm command.

This is a sample file Test_ Mürz.jgp.

How would one go about removeing files with such chars issues in the filename on a grand scale ... especially when you don't know the position of the chars.

share|improve this question
add comment

3 Answers

up vote 4 down vote accepted

For single files, or small sets of files, if wildcard globbing doesn't allow you the precision you feel you need, you can combine ls -i (or stat, if available) and find -inum.

For example:

~$ ls -i myweirdfile
183435818 myweirdfile
~$ find . -inum 183435818 -exec rm -i '{}' ';'
rm: remove regular file `./myweirdfile'? y

Alternatively, in a single invocation (this might depend on GNU coreutils stat, which should be a fairly safe assumption on Linux, and uses sh-style process substitution):

~$ find . -inum $(stat -c '%i' 'myweirdfile') -exec rm -i '{}' ';'
rm: remove regular file `./myweirdfile'? y
share|improve this answer
why -i, what is the problem of list all files and try to remove the file by name? –  lzprgmr Sep 10 '13 at 13:23
Izprgmr it does work with escaping some chars –  mahatmanich Sep 10 '13 at 13:25
@lzprgmr Because with GNU coreutils rm, rm -i causes rm to prompt once for each file removal, ensuring you don't accidentally delete the wrong file (it's very easy to mistype the inode number!). Since the question is tagged linux, I think assuming GNU coreutils is reasonable. –  Michael Kjörling Sep 10 '13 at 15:04
add comment

Easy way:

ls -i Test_*

rm -i [inode number]
share|improve this answer
Oh this is cool didn't know about it thanks! –  mahatmanich Sep 10 '13 at 12:28
What rm program is this? With rm from GNU coreutils, -i means "prompt before every removal". –  Lekensteyn Sep 10 '13 at 12:37
yeah tried it and it does not work! –  mahatmanich Sep 10 '13 at 13:14
It depends about distro (checked on debian). –  Paul Rudnitskiy Sep 11 '13 at 10:37
Debian certainly does not do that in its rm! –  mahatmanich Sep 13 '13 at 12:06
add comment

What "grand scale" goals do you have?

Why isn't this sufficient?

$ rm Test_*

One way of diving into a directory tree of files:

$ find /your/base/dir -maxdepth 3 -type f -name 'Test_*' -exec rm {} \;

You can tune the find command to zero-in on your files.

share|improve this answer
because 'rm anything*' will get you in deeper trouble faster than you might think! I want a pinpoint operation not a wildcard one! –  mahatmanich Sep 13 '13 at 12:08
I don't understand your "grand scale" requirement. How can this requirement be achieved without some "globbing"? –  rickhg12hs Sep 13 '13 at 16:17
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.