LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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

Reply
 
Search this Thread
Old 08-15-2006, 02:00 PM   #1
fiveseven
LQ Newbie
 
Registered: Aug 2006
Posts: 7

Rep: Reputation: 0
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.



Any help getting rid of these demented files is appreciated!

regards,
fiveseven
 
Old 08-15-2006, 02:08 PM   #2
dannystaple
Member
 
Registered: Apr 2006
Location: London, Uk
Distribution: Ubuntu on Desktop
Posts: 121

Rep: Reputation: 15
Quote:
Originally Posted by fiveseven
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.



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.

Danny
 
Old 08-15-2006, 02:45 PM   #3
fiveseven
LQ Newbie
 
Registered: Aug 2006
Posts: 7

Original Poster
Rep: Reputation: 0
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

Last edited by fiveseven; 08-15-2006 at 02:46 PM.
 
Old 08-17-2006, 11:51 AM   #4
soggycornflake
Member
 
Registered: May 2006
Location: England
Distribution: Slackware 10.2, Slamd64
Posts: 249

Rep: Reputation: 31
Yeah, looks like shell is bodging the names. Have you tried just rm -r the entire directory?
 
Old 08-17-2006, 05:01 PM   #5
dannystaple
Member
 
Registered: Apr 2006
Location: London, Uk
Distribution: Ubuntu on Desktop
Posts: 121

Rep: Reputation: 15
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.
 
Old 08-17-2006, 05:08 PM   #6
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
Quote:
Originally Posted by dannystaple
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.
 
Old 08-18-2006, 04:23 AM   #7
fiveseven
LQ Newbie
 
Registered: Aug 2006
Posts: 7

Original Poster
Rep: Reputation: 0
Unfortunatly trying to delete the directory gives me the same error

Quote:
five@nuclear-pussy:~/testarea/debug$ ls src
src/MusicAudit - src/MusicAudit -
five@nuclear-pussy:~/testarea/debug$ rm -r src
rm: cannot remove `src/MusicAudit - ': No such file or directory
five@nuclear-pussy:~/testarea/debug$
Ill eventually get around to poking around the net and see if i can find an API to enumerate files.

regards,
fiveseven
 
Old 08-18-2006, 06:46 AM   #8
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
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.
 
Old 08-18-2006, 09:24 AM   #9
soggycornflake
Member
 
Registered: May 2006
Location: England
Distribution: Slackware 10.2, Slamd64
Posts: 249

Rep: Reputation: 31
How about perl?

Code:
find src -print0 | perl -0wne 'unlink'
 
Old 08-18-2006, 05:07 PM   #10
fiveseven
LQ Newbie
 
Registered: Aug 2006
Posts: 7

Original Poster
Rep: Reputation: 0
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

Last edited by fiveseven; 08-18-2006 at 05:10 PM.
 
Old 05-28-2007, 10:03 PM   #11
iXneonXi
Member
 
Registered: Jul 2004
Distribution: Xubuntu
Posts: 37

Rep: Reputation: 15
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.
 
Old 12-05-2007, 11:39 AM   #12
masinick
Member
 
Registered: Apr 2002
Location: Concord, NH
Distribution: Debian, sidux, antiX, SimplyMEPIS, Kubuntu, Mandriva, Fedora, Xandros, Arch, and many others
Posts: 560
Blog Entries: 14

Rep: Reputation: 35
Remove files using their inode number

Quote:
Originally Posted by fiveseven View Post
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.



Any help getting rid of these demented files is appreciated!

regards,
fiveseven
First find out file inode number by using either of the following commands:

Code:
stat {file-name}
or
Code:
ls -il {file-name}
then use find to remove the file
Code:
find . -inum [inode-number] -exec rm -i {} \;
When prompted for confirmation, press Y to confirm removal of the file.
 
Old 12-05-2007, 12:13 PM   #13
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
quick scan--apologies if I missed this being mentioned.

Did you try putting the files in a directory and then rm -rf dirname ?
 
Old 12-05-2007, 02:12 PM   #14
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 197Reputation: 197
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.
 
  


Reply

Tags
delete, filename, invalid


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
My static routes file is invalid charlest Red Hat 1 07-25-2006 10:30 AM
kino gives "invalid file specified" when i try to open an *.mpg file lefty.crupps Linux - Software 1 10-31-2005 03:20 AM
ELF file OS ABI invalid man26 Linux - General 0 07-29-2004 05:54 AM
Tried to delete file as root but it says I don't have permission to delete it! beejayzed Mandriva 23 03-12-2004 02:46 AM
How to delete invalid network folders? hitbob Linux - Networking 3 08-22-2003 04:50 PM


All times are GMT -5. The time now is 02:30 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration