Friday, September 5, 2008

 

Pesky Filenames

It's common knowledge among Linux aficionados that you can encounter files and directories with strange names.

For example it's possible to encounter a youtube video with a dash as the first character in a filename. Let's say the you download a file from youtube using the youtube-dl script and the filename is -m7PqBPqCl4.flv

Now if you try to play it at the command line with mplayer:

mplayer -m7PqBPqCl4.flv

you get:

Unknown option on the command line: -m7PqBPqCl4.flv

You could simply rename the file to something a bit more descriptive and without the dash in front but:

mv -m7PqBPqCl4.flv video1.flv

gives:

mv: invalid option -- m

So you have to tell the mv command not to process the dash like so:

mv -- -m7PqBPqCl4.flv video1.flv

You'll get the same result if you try to delete a file when the first character is a dash but the solution is similar:

rm -- -m7PqBPqCl4.flv

But what if you wanted to copy the file? Same thing:

cp -- -m7PqBPqCl4.flv video1.flv

I have come across another example of strange directories in /tmp which were able to resist the rm command.

Let's say some hacker (the bad kind) wanted to make a directory in /tmp to store their malware. One thing they could do is make a directory name of ". ." in /tmp

We will assume in this case that the files are owned by user 'nobody'.

Now deleting with rm may not work:

find /tmp -user nobody | xargs rm -r -f -v

The directory ". ." will still be in /tmp

Instead you may need to explicitly reference the directory:

cd /tmp
rmdir ". ."

Or it can be removed by this method, as there may be more files in ". ."

find /tmp -user nobody | xargs rm -r -f -v ". ."

Comments:

Post a Comment

Subscribe to Post Comments [Atom]





<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]