Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Problems removing files with semicolons in the filename Post 302850375 by migurus on Wednesday 4th of September 2013 02:43:17 PM
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?
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
READDIR(3)						     Linux Programmer's Manual							READDIR(3)

NAME
readdir, readdir_r - read a directory SYNOPSIS
#include <dirent.h> struct dirent *readdir(DIR *dirp); int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result); Feature Test Macro Requirements for glibc (see feature_test_macros(7)): readdir_r(): _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _BSD_SOURCE || _SVID_SOURCE || _POSIX_SOURCE DESCRIPTION
The readdir() function returns a pointer to a dirent structure representing the next directory entry in the directory stream pointed to by dirp. It returns NULL on reaching the end of the directory stream or if an error occurred. On Linux, the dirent structure is defined as follows: struct dirent { ino_t d_ino; /* inode number */ off_t d_off; /* offset to the next dirent */ unsigned short d_reclen; /* length of this record */ unsigned char d_type; /* type of file; not supported by all file system types */ char d_name[256]; /* filename */ }; The only fields in the dirent structure that are mandated by POSIX.1 are: d_name[], of unspecified size, with at most NAME_MAX characters preceding the terminating null byte; and (as an XSI extension) d_ino. The other fields are unstandardized, and not present on all systems; see NOTES below for some further details. The data returned by readdir() may be overwritten by subsequent calls to readdir() for the same directory stream. The readdir_r() function is a reentrant version of readdir(). It reads the next directory entry from the directory stream dirp, and returns it in the caller-allocated buffer pointed to by entry. (See NOTES for information on allocating this buffer.) A pointer to the returned item is placed in *result; if the end of the directory stream was encountered, then NULL is instead returned in *result. RETURN VALUE
On success, readdir() returns a pointer to a dirent structure. (This structure may be statically allocated; do not attempt to free(3) it.) If the end of the directory stream is reached, NULL is returned and errno is not changed. If an error occurs, NULL is returned and errno is set appropriately. The readdir_r() function returns 0 on success. On error, it returns a positive error number (listed under ERRORS). If the end of the directory stream is reached, readdir_r() returns 0, and returns NULL in *result. ERRORS
EBADF Invalid directory stream descriptor dirp. CONFORMING TO
SVr4, 4.3BSD, POSIX.1-2001. NOTES
Only the fields d_name and d_ino are specified in POSIX.1-2001. The remaining fields are available on many, but not all systems. Under glibc, programs can check for the availability of the fields not defined in POSIX.1 by testing whether the macros _DIRENT_HAVE_D_NAMLEN, _DIRENT_HAVE_D_RECLEN, _DIRENT_HAVE_D_OFF, or _DIRENT_HAVE_D_TYPE are defined. Other than Linux, the d_type field is available mainly only on BSD systems. This field makes it possible to avoid the expense of calling lstat(2) if further actions depend on the type of the file. If the _BSD_SOURCE feature test macro is defined, then glibc defines the fol- lowing macro constants for the value returned in d_type: DT_BLK This is a block device. DT_CHR This is a character device. DT_DIR This is a directory. DT_FIFO This is a named pipe (FIFO). DT_LNK This is a symbolic link. DT_REG This is a regular file. DT_SOCK This is a Unix domain socket. DT_UNKNOWN The file type is unknown. If the file type could not be determined, the value DT_UNKNOWN is returned in d_type. Currently, only some file systems (among them: Btrfs, ext2, ext3, and ext4) have full support returning the file type in d_type. All applications must properly handle a return of DT_UNKNOWN. Since POSIX.1 does not specify the size of the d_name field, and other nonstandard fields may precede that field within the dirent struc- ture, portable applications that use readdir_r() should allocate the buffer whose address is passed in entry as follows: len = offsetof(struct dirent, d_name) + pathconf(dirpath, _PC_NAME_MAX) + 1 entryp = malloc(len); (POSIX.1 requires that d_name is the last field in a struct dirent.) SEE ALSO
getdents(2), read(2), closedir(3), dirfd(3), ftw(3), offsetof(3), opendir(3), rewinddir(3), scandir(3), seekdir(3), telldir(3), fea- ture_test_macros(7) COLOPHON
This page is part of release 3.27 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. 2010-09-10 READDIR(3)
All times are GMT -4. The time now is 06:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy