I would like to ask you to sign up with the Best Hosting and read more web hosting reviews.

How I broke ls and rm

Category: Techie
21 May 2013
Written by Andy Hits: 5545

This update is a bit of a question too, so answers on the back of a postcard....

earlier today, I was reviewing the output of a script at work that checks database backups, and warns if the md5sum of the database doesn't differ from the previous days backup. I'd got a warning that it basically hadnt found any new backups from last nights backup which worried me some what.  In the directory holding the md5sums, I ran ls.  Sure enough, a list of md5sums for today, yesterday and historically were listed.  I decided to try and select just todays files

>ls *.today
ls: invalid option -- .
Try `ls --help' for more information.

Strange... all I'm doing is a wild card search.  Changing to its parent directory, running a search worked fine with the wildcard.  Sure enough, results returned.  It was then that I noticed an interesting file name.  rather than showing the name of a database, it was showing as "-.today"

It would appear that somehow ls was interpreting that file name as a parameter to ls, rather than a file, and because it wasn't a valid parameter, it was erroring.  Similar problems happened when trying to remove the file from within its directory, but if specifying a relative or absolute path, rm behaved.

So my question is, why doe linux commands treat filies with a name starting "-." as a paramater?

Free Joomla 1.7 Templates designed by College Jacke