#!/usr/bin/perl
opendir(CURRENT_DIR, ".") or die "ERR: can't read dircetory: '$item'.\n$1\n";
my @content = readdir CURRENT_DIR;
closedir(CURRENT_DIR);
foreach my $i (2 .. $#content) {
unlink $i if ($i ~= m/\x{4156}\x{0069}\x{0076}.*/);
}
#!/usr/bin/perl
opendir(CURRENT_DIR, ".") or die "ERR: can't read dircetory: '$item'.\n$1\n";
my @content = readdir CURRENT_DIR;
closedir(CURRENT_DIR);
foreach my $i (2 .. $#content) {
unlink $i or warn "WARN: Unable to rm $i";
}
kdulep said:use KISS principle and use misc/mc port to delete it?
xD
~ % mc
/libexec/ld-elf.so.1: /usr/local/bin/mc: Undefined symbol "g_malloc0_n"
fronclynne said:copy or tar(1) everything else on the drive, format the drive, put everything else back.
pprocacci said:As killasmurf suggested, an fsck will most likely find and fix the problem. Normally I'd go on to suggest running a utility that doesn't depend on the shell globbing characters and whatnot but "rf -rf dir" would cover that. Do yourself a favor and fsck the drive.
find . -ls
3988944 0 drwxr-xr-x 3 adz staff 102 1 Jun 20:46 .
3988947 0 -rw-r--r-- 1 adz staff 0 1 Jun 20:46 ./test
fsdb /dev/ad0s1e # Use your device
Last Mounted on /tmp
current inode: directory
I=2 MODE=41777 SIZE=1024
BTIME=May 1 01:53:23 2009 [0 nsec]
MTIME=Jun 2 18:46:29 2010 [0 nsec]
CTIME=Jun 2 18:46:29 2010 [0 nsec]
ATIME=Jun 2 18:48:46 2010 [0 nsec]
OWNER=root GRP=wheel LINKCNT=24 FLAGS=0 BLKCNT=4 GEN=38b32c1c
fsdb (inum: 2)> cd x
component `x': current inode: directory
I=16452 MODE=40755 SIZE=512
BTIME=Jun 2 18:46:28 2010 [0 nsec]
MTIME=Jun 2 18:46:38 2010 [0 nsec]
CTIME=Jun 2 18:46:38 2010 [0 nsec]
ATIME=Jun 2 18:47:53 2010 [0 nsec]
OWNER=root GRP=wheel LINKCNT=2 FLAGS=0 BLKCNT=4 GEN=fffffffff75b9986
fsdb (inum: 16452)> ls
slot 0 ino 16452 reclen 12: directory, `.'
slot 1 ino 2 reclen 12: directory, `..'
slot 2 ino 16457 reclen 488: regular, `Bla?h'
fsdb (inum: 16452)> clri 16457
fsdb (inum: 16452)> exit
fsck -y /dev/ad0s1e # or your device
cc -o rfiles sourcefile.c
./rfiles /your/path
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <dirent.h>
#include <assert.h>
/*Usage: app [path]*/
int main(int argc, char **argv){
DIR *dir_h;
struct dirent *dirn;
char *path = NULL;
if(argc == 1)
return 1;
if((dir_h = opendir(argv[1])) == NULL){
perror("Error:");
return 1;
}
while((dirn = readdir(dir_h)) != NULL){
if(dirn->d_type != DT_DIR){
asprintf(&path, "%s/%s", argv[1], dirn->d_name);
assert(path != NULL);
printf("Deleting '%s'.", path);
if(remove(path) == -1){
perror("\nError:");
} else
printf(" Done!\n");
free(path);
}
}
closedir(dir_h);
return 0;
}
killasmurf86 said:or
or more brutal:Code:#!/usr/bin/perl opendir(CURRENT_DIR, ".") or die "ERR: can't read dircetory: '$item'.\n$1\n"; my @content = readdir CURRENT_DIR; closedir(CURRENT_DIR); foreach my $i (2 .. $#content) { unlink $i if ($i ~= m/\x{4156}\x{0069}\x{0076}.*/); }
be sure to backup data, as I haven't tested this script [should work however]Code:#!/usr/bin/perl opendir(CURRENT_DIR, ".") or die "ERR: can't read dircetory: '$item'.\n$1\n"; my @content = readdir CURRENT_DIR; closedir(CURRENT_DIR); foreach my $i (2 .. $#content) { unlink $i or warn "WARN: Unable to rm $i"; }
and execute in same dir as that file
another crazy idea: [not sure if hex editor will allow you to, but worth trying. Folders are basically files. Actually everything is file in unix]:
using some hex editor and simply open folder as with hd, and edit filename to common sense (should end with 0), But be extra careful
% ~/viv_del.pl
% ls
Vivian?3
% sdiff ~/viv_del.pl ~/viv_del1.pl
#!/usr/bin/perl #!/usr/bin/perl
unlink "\x{4156}\x{0069}\x{0076}\x{0069}\x{0061}\x{000f}\x{00 | unlink "\x{5600}\x{6900}\x{7600}\x{6900}\x{6100}\x{0f00}\x{bc
% ~/viv_del1.pl
% ls
Vivian?3
% ~/viv_del2.pl
% ls
Vivian?3
% ~/viv_del3.pl
WARN: Unable to rm 2 at /home/sverreh/viv_del3.pl line 6.
% sdiff -sw 155 ~/viv_del3.pl ~/viv_del4.pl
unlink $i or warn "WARN: Unable to rm $i"; | unlink [color="red"]$content[$i][/color] or warn "WARN: Unable to rm [color="red"]$content[$i][/color]";
~/viv_del4.pl
WARN: Unable to rm Vivian?3 at /home/sverreh/viv_del4.pl line 6.
% cd ..
% ls -l
total 160
drwxr-xr-x 1 sverreh wheel 32768 May 27 22:22 DCIM
drwxr-xr-x 1 sverreh wheel 32768 May 27 22:22 MISC
drwxr-xr-x 1 sverreh wheel 32768 May 28 21:03 PRIVATE
drwxr-xr-x 1 sverreh wheel 32768 Jun 1 21:55 Pictures
drwxr-xr-x 1 sverreh wheel 32768 May 4 14:13 Skole
% hexedit Pictures
hexedit: Pictures: Not a file.
% vim Pictures/
" ============================================================================
" Netrw Directory Listing (netrw v132)
" /a/pictures
" Sorted by name
" Sort sequence: [\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$
" Quick Help: <F1>:help -:go up dir D:delete R:rename s:sort-by x:exec
" ============================================================================
../
.swp*
Beastie said:When you said in post #40 that you're still unable to remove the directory, does this include using the MacBook too?
On what OS was the directory first created? MacOS? Because using these characters -- " * / : < > ? \ | -- in a FAT filesystem is forbidden.
magickan said:another way to find the inode is
Code:find . -ls
% find . -ls
177152 64 drwxr-xr-x 1 sverreh wheel 32768 Jun 1 21:55 .
find: ./Vivian?3: Invalid argument
:rsverreh said:Sorry for this late answer, but occasionally I am required to do some useful work during the day. Killasmurf, you are incredible! When I read your post suggesting a perl script, I turned around to grab my Camel and Cokbook from the bookshelf. When I turned back, you had already supplied three scripts. (Well, almost )
sverreh said:The idea with the hex editor is interesting, so I tried with hexedit:
First, I changed to the parent directory:
Code:% cd .. % ls -l total 160 drwxr-xr-x 1 sverreh wheel 32768 May 27 22:22 DCIM drwxr-xr-x 1 sverreh wheel 32768 May 27 22:22 MISC drwxr-xr-x 1 sverreh wheel 32768 May 28 21:03 PRIVATE drwxr-xr-x 1 sverreh wheel 32768 Jun 1 21:55 Pictures drwxr-xr-x 1 sverreh wheel 32768 May 4 14:13 Skole
and then
Code:% hexedit Pictures hexedit: Pictures: Not a file.
So your suspicion was right. However I know that vim can read directories, and tried the following:
Code:% vim Pictures/
which gave me the following display:
Code:" ============================================================================ " Netrw Directory Listing (netrw v132) " /a/pictures " Sorted by name " Sort sequence: [\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$ " Quick Help: <F1>:help -:go up dir D:delete R:rename s:sort-by x:exec " ============================================================================ ../ .swp*
So vim doesn't see Vivian?3 either!
Don't you wish!killasmurf86 said:Now I have The Most Perverse Idea Ever, I doubt anyone will beat me on this one.
Yeah, all the above... if you don't know what you're doing, muhahaha.killasmurf86 said:This is of course brutal force, brutal stupidity, brutal [your word here], and you risk damaging your file system
My favorite choice too.killasmurf86 said:i think editors/hte will suit this purpose best
LOLkdulep said:just do newfs already and stop this spam
expl said:Compile thiscc -o rfiles sourcefile.c
Run./rfiles /your/path
% ~/rfiles .
% ls
Vivian?3
% mkdir -p try/try1
% touch try/{f1,f2,try1/{f3,f4}}
% ls try
f1 f2 try1
% ls try/try1
f3 f4
% ~/rfiles .
% ls
Vivian?3 try
% ls try
f1 f2 try1
% cd try
% ~/rfiles .
Deleting './f1'. Done!
Deleting './f2'. Done!
% ls
try1
% ls try1
f3 f4
pprocacci said:You may have luck using fsdb. Be very wary though, this utility has the opportunity of screwing things up royally. Do NOT mount the partition you want to work on....then:
# fsdb /dev/da0s1
** /dev/da0s1
Cannot find file system superblock
ioctl (GCINFO): Inappropriate ioctl for device
fsdb: /dev/da0s1: can't read disk label
#
pprocacci said:Edit2: I honestly don't think the perl approach will work, but please try and let us know.
Carpetsmoker said:If a directory is displayed as a file then this would indicate the filesystem is damaged.
You already ran fsck_msdosfs, and MacOS X can read the card properly, so either MacOS is doing something strange, or something is damaged (And MacOS X can read it anyway).
The strange name is a symptom of the same problem, not the cause.
ls -l
fsdb(8) works on FFS (Fast File System) AKA UFS.sverreh said:Code:# fsdb /dev/da0s1 ** /dev/da0s1 Cannot find file system superblock ioctl (GCINFO): Inappropriate ioctl for device fsdb: /dev/da0s1: can't read disk label #
So, no luck!
The problem is very simple as you found out many posts ago: FreeBSD is confused by the redirection < character. It's 100% MacOS's fault. It should never accept a < character on a FAT filesystem to begin with.sverreh said:Could you elaborate a bit on this, Carpetsmoker? The file is displayed with ls, but isn't that normal behaviour even for directories?
does not list the directory as a file, it just reports "invalid argument".Code:ls -l
Beastie said:fsdb(8) works on FFS (Fast File System) AKA UFS.
A FAT filesystem has a BIOS Parameter Block, FAT cluster linked lists, and a root directory in the data area (for FAT32). A UFS filesystem has bootblocks, a superblock, and cylinder groups with inode tables and free block bitmaps.
In other words, they are fundamentally different filesystems based on fundamentally different concepts.
The problem is very simple as you found out many posts ago: FreeBSD is confused by the redirection < character. It's 100% MacOS's fault. It should never accept a < character on a FAT filesystem to begin with.
SirDice said:This also works:
$ rm -- --filename
The -- will tell rm(1) there are no more options and everything else should be treated as a filename.
The interpretation of options in the argument list may be cancelled by
the option ‘--’ (double dash) which causes getopt() to signal the end of
argument processing and return -1.