Cant delete file with invalid name
Hey,
I created a few files with ascii values from 0 onward - ie non-alphanumeric characters - (forgetting to convert the integers to their character values) and now im unable to delete them. http://img109.imageshack.us/img109/9...eerrorskp6.png Any help getting rid of these demented files is appreciated! regards, fiveseven |
Quote:
I presume you programatically created the files (I could see few other ways of creating files with such names), so I suggest you also delete them in a similar manner, using the posix unlink (man 3 unlink) command, which is available in c, perl and probably plenty of other languages. I cannot guarantee that the posix layer wont bork at this point, but its worth a shot. If you actually managed (kudos points here) to get a character 0 into a filename, that is quite an acheivement, and may be a complete pain in the backside being that it is used as the standard string terminator, which may be exactly how the posix libraries see it. Your option then may be to try and list the directories contents in terms of their inodes, and try to unlink them by their inodes - this will not be easy. Danny |
I used standard c++ file streams to write the files as i'm very new to linux, and comming from a windows background i dont know my POSIX API yet.
To add to my problem, the invalid characters were from a timestamp so i have no idea as to what they would be, though i asume the mechanism used to write the filename would detect a null and termiate the string in the same way a reading command would. Is there a POSIX function that will enumerate all the files of a folder for me, so i can call unlink() manually as you instructed? Big thanks for your help Danny, fiveseven |
Yeah, looks like shell is bodging the names. Have you tried just rm -r the entire directory?
|
Extreme, but soggycornflakes method might work. Maybe what you should do then, is move out the files you do want to a temporary folder, delete the parent folder, and then recreate it with the bits you want.
|
Quote:
|
Unfortunatly trying to delete the directory gives me the same error
Quote:
regards, fiveseven |
Maybe you could try using echo -e to save the unreadable ASCII chars into a variable and then doing an rm using the variables in the filename.
It's probably a long shot though, as the shell may still interfere. Example: Code:
char=`echo -e -n \001`; #\001 indicates that the char with (ASCII) octal number 001 is to be printed. |
How about perl?
Code:
find src -print0 | perl -0wne 'unlink' |
The perl script does find 2 of the invalid files and deletes them (the two that are visible from nautilis and 'ls'), but upon deleting the directory i still get an error saying that it cant find a file in the dir. There were 5 files in total, so i have to asume the other 3 are still there but arent being displayed.
// edit: i tried rm -r 'ing the directory again after nautilis wouldnt delete the dir and it worked. At least the directory isnt showing up anymore, which ill take as a sign that its inode has been free'd for good and i can forget about this now :P Thanks for all your help guys, i really appreciate it. regards, fiveseven |
Scan for Invalid Filenames
I have files with invalid characters as well. However I can't pinpoint every single one of these files. Is there a way to scan for these files and either rename or delete them? They occasionally cause seemingly minor filesystem errors that the fsck fixes with ease.
|
Remove files using their inode number
Quote:
Code:
stat {file-name} Code:
ls -il {file-name} Code:
find . -inum [inode-number] -exec rm -i {} \; |
quick scan--apologies if I missed this being mentioned.
Did you try putting the files in a directory and then rm -rf dirname ? |
Easy, all of the files you wanted Deleted start with Music. I see nothing else that starts with Music, so just do a:
rm -r Music* Instead of: rm -r MusicAudit* Or find the Inode of each and do a rm that way. |
All times are GMT -5. The time now is 11:20 PM. |