Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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.
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.
Any help getting rid of these demented files is appreciated!
regards,
fiveseven
When you use *, the shell expands them, and then passes them on to the program, here being rm. You may want to try a different approach, as the shell may even be munging (that is - destroying) these character codes on the way.
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.
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?
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.
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.
I agree. This seems likely to be the most reliable solution.
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.
rm "myfile${char}"; #or something like that.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.