Problems removing files with semicolons in the filename


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Problems removing files with semicolons in the filename
# 1  
Old 09-03-2013
Problems removing files with semicolons in the filename

There are some 40 files created by accident with filenames with semicolons, as well as other non-printable characters. I can not find a correct way to delete them. This is what I tried:

Code:
bash-2.03# ls bad|head -1
000025;001;1377795616;
bash-2.03# rm "bad/000025;001;1377795616;???"
rm: bad/000025;001;1377795616;??? non-existent
bash-2.03# 
bash-2.03# rm 'bad/000025;001;1377795616;???' 
rm: bad/000025;001;1377795616;??? non-existent
bash-2.03# rm 'bad/000025;001;1377795616;*'  
rm: bad/000025;001;1377795616;* non-existent
bash-2.03# rm 'bad/000025\;001\;1377795616\;*'
rm: bad/000025\;001\;1377795616\;* non-existent
bash-2.03# rm "bad/000025\;001\;1377795616\;*" 
rm: bad/000025\;001\;1377795616\;* non-existent

I can not remove the whole directory as well

Code:
bash-2.03# rm -r bad
rm: 000025;001;1377795616; non-existent
rm: 000025;003;1377809391; non-existent
rm: 000025;012;1377803446;' non-existent
rm: 000025;014;1377789967; non-existent
...
... etc... same kind of non-existent msg per each file
...
rm: unable to remove directory bad: File exists (error 17)
bash-2.03#

What can I do?
# 2  
Old 09-03-2013
Remove files with a semicolon in the filename
Code:
rm *\;*

But
Code:
rm -r bad

should work!
It looks like the file system is corrupted.
# 3  
Old 09-04-2013
You can also list the inode of the file along with long listing using
Code:
ls -il

and then remove files using inode number

Code:
find . -inum xxxx -exec rm {} \;

Replace xxxx with the inode number found using previous ls command
# 4  
Old 09-04-2013
I tried both proposed solutions, but it did not work:
Code:
# rm *\;*
rm: 000025;001;1377795616; non-existent
rm: 000025;003;1377809391; non-existent
... etc ...

and
Code:
# ls -il
ls: ./000025;001;1377795616; not found: No such file or directory (error 2)
ls: ./000025;003;1377809391; not found: No such file or directory (error 2)
 
... etc ...

# 5  
Old 09-04-2013
If even ls can't list them all by itself with no filenames given, that means the raw names being given by readdir are wrong... This does suggest disk corruption unfortunately.
# 6  
Old 09-04-2013
I have actually created these file by extracting some uniq ids from some http logs forgetting to replace ';' with some other delimiter. I don't think the disk has any issue.

Actually we did have this box restarted for another reason and fsck -o was run without any issues.

Just to get the inodes I cooked up this code:

Code:
 
  struct dirent *di = {NULL};
  DIR           *cd = {NULL};
  struct stat   stinfo = {NULL};
        if((cd = opendir(path)) == NULL)
                return(-1);
        while((di = readdir(cd)) != NULL)
        {
                if(di->d_name[0] == '.')
                {
                        if(di->d_name[1] == '.' || di->d_name[1] == 0)
                                continue;
                }
                printf("%li\t%s\n", di->d_ino, di->d_name);
        }
        closedir(cd);
        return(0);

and I got those inodes:
Code:
129935  000025;001;1377795616;
129936  000025;003;1377809391;
... etc ...

I hoped I could use find with -inod, but it did not work:
Code:
$ find . -inum 129935 -exec rm {} \;
find: cannot access ./000025;001;1377795616;: No such file or directory (error 2)
find: cannot access ./000025;003;1377809391;: No such file or directory (error 2)
... etc ...

Somehow find listed out all files, not the one pointed by the inode.

The file system is HTFS under OSR 5.8
Any ideas, please?

---------- Post updated at 11:43 AM ---------- Previous update was at 11:32 AM ----------

some more info, I debugged my code and printed dirent :


Code:
(dbxtra) p *di
(d_ino = 129935, d_off = 56, d_reclen = 32, d_name = "0")
(dbxtra) p &di->d_name
0x4016b6
(dbxtra) 0x4016b6 / 32 c
0x004016b6:  '0' '0' '0' '0' '2' '5' ';' '0' '0' '1' ';' '1' '3' '7' '7' '7'
0x004016c6:  '9' '5' '6' '1' '6' ';' '\220' '\373' '^A' '\0' 'X' '\0' '\0' '\0'
' ' '\0'

So, I see that name contains several \0 zeroes. Is there any way to remove thises files?
# 7  
Old 09-04-2013
Strings in C stop at the very first \0, everything after it you can ignore. Your debugger prints the whole array regardless, ignorant of what its contents represent. Filenames cannot contain \0 unless you've got an egregious filesystem bug, anyway.

I wonder if the filename is somehow being mangled when being passed between program to program. I wonder if the name were fed direct from di->d_name to unlink(), whether it would take.

If you try this, try it with extreme caution! I suggest as a start, this to avoid non-semicolon filenames:

Code:
#include <string.h>
...

if(strchr(de->d_name, ';') == NULL) continue;


Last edited by Corona688; 09-04-2013 at 03:59 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] Modifying/Removing Timestamps from a filename

So given filenames of varying lengths, I was wondering how I would remove or modify appended timestamps of the current date DD-MM-YY. So say: test_DD-MM-YY.txt coolbeans_DD-MM-YY.pdf And what I expect the output to be: test.txt coolbeans.pdf Thanks :) (2 Replies)
Discussion started by: sodaboyz
2 Replies

2. UNIX for Dummies Questions & Answers

BASH - Removing the very last character(s) extension of a filename

Hello. I would like to know how to do this in bash script : A_WORD="ABCD_EFGH.0.100.40.123" NEW_WORD=remove_last_ext("A_WORD") NEW_WORD --> ABCD_EFGH.0.100.40 A_WORD="ABCD_EFGH.0.50.3" NEW_WORD=remove_last_ext("A_WORD") NEW_WORD --> ABCD_EFGH.0.50 A_WORD="ABCD_EFGH.3.100.50." ... (2 Replies)
Discussion started by: jcdole
2 Replies

3. Shell Programming and Scripting

removing a range of characters in a filename

hi, I have quite a bunch of files with annoyingly long filenames. I wanted to cut the range of characters from 9-18 and just retain the first 8 characters and the .extension. any suggestion how to do it. thanks much. original filename: 20000105_20000105_20100503.nc.asc output filename:... (4 Replies)
Discussion started by: ida1215
4 Replies

4. Shell Programming and Scripting

removing the filename extension

Is there an easy way to strip off a filename's extension? For example, here's a filename: blahblahblah.thisisok.thisisnotok I want to get rid of .thisisnotok from the filename, so that what's left is blahblahblah.thisisok Thanks. I have a directory full of filenames that need to be... (5 Replies)
Discussion started by: daflore
5 Replies

5. UNIX for Dummies Questions & Answers

Removing the trailing date from a filename

Hi I have 3 files (say) in a folder as in the example below abc_01012011.csv def_01012011.csv xyz_01012011.csv I need to move these files to a different folder as follows abc.csv def.csv xyz.csv I am trying to put together a script with a for loop which reads the source filenames... (5 Replies)
Discussion started by: bobsn
5 Replies

6. UNIX for Dummies Questions & Answers

Help with Removing extra characters in Filename

Hi, It's my first time here... anyways, I have a simple problem with these filenames. This is probably too easy for you guys: ABC_20101.2A.2010_01 ABD_20103.2E.2010_04 ABE_20107.2R.2010_08 Expected Output: ABC_20101 ABD_20103 ABE_20107 The only pattern available are the ff: 1) All... (9 Replies)
Discussion started by: Joule
9 Replies

7. AIX

removing 8th and 9th character of a FILENAME

Hi everyone, I have a file called pdf.txt which has the following list inside: 7110412_1_31122012.pdf 7286510_4_46667100.pdf 4002176_1_00018824.pdf ... I need a looping script to REMOVE the 8th and 9th character of the filenames listed, no matter what character that is. So... (4 Replies)
Discussion started by: chipahoys
4 Replies

8. Shell Programming and Scripting

Filename from splitting files to have the same filename of the original file with counter value

Hi all, I have a list of xml file. I need to split the files to a different files when see the <ko> tag. The list of filename are B20090908.1100-20090908.1200_CDMA=1,NO=2,SITE=3.xml B20090908.1200-20090908.1300_CDMA=1,NO=2,SITE=3.xml B20090908.1300-20090908.1400_CDMA=1,NO=2,SITE=3.xml ... (3 Replies)
Discussion started by: natalie23
3 Replies

9. Shell Programming and Scripting

Removing spaces within Filename

Hello, I have a Folder (myfile) which contain the following files: P$12789865KR +N+01+OM+16102009165416.nu P$M1-508962GD +N+01+ALP+14102009094417.nu Is there a sed command(s) that will loop through this folder and remove the spaces that exists in the filename? Any help would be... (7 Replies)
Discussion started by: Fishn
7 Replies

10. AIX

Removing a filename which has special characters passed from a pipe with xargs

Hi, On AIX 5200-07-00 I have a find command as following to delete files from a certain location that are more than 7 days old. I am being told that I cannot use -exec option to delete files from these directories. Having said that I am more curious to know how this can be done. an sample... (3 Replies)
Discussion started by: jerardfjay
3 Replies
Login or Register to Ask a Question