|
Search:
Advanced search
|
Browse by category:
|
Contact Us |
Delete files/folder having special characters in their name |
|||||
You might have come across situations like files and folders having special characters in their name. If you are lucky, you will be able to access the file/folder by escaping the special chars in the name. It may not work all the time, i.e. even if you escape the special char, you won't be able to access the file/folder. In such cases, seeing the contents of that file/folder or deleting them is tricky. In Linux, everything is considered as a file. Being a file, the files/folders have an inode number associated with them. Using ls command with option -i, you will be able to see the inode number associated with such specially named files/folders. In the following example, you may see such a special folder with name \t\t\t\t/ and having an inode number 2343166. root@host [/]# ls -li total 346 2 drwxr-xr-x 23 root root 4096 Dec 27 23:09 ./ 2 drwxr-xr-x 23 root root 4096 Dec 27 23:09 ../ 2343166 drwxr-xr-x 2 root root 4096 Oct 24 05:45 \t\t\t\t/ So the trick here is to use the inode number to see the contents or delete such files/folders. But the ls, rm or rmdir commands have no option to access any files/folders with inode number. So those commands won't help in such situations. Here comes the find command with its power to address files/folders in a number of ways. It can find the files/folders based on the inode number. In the above example, the inode number is 2343166. So we can use the find command as follows. root@host [/]# find . -inum 2343166 -maxdepth 1 ./ root@host [/]# Though the name of the folder as shown by ls command is \t\t\t\t/, find is identifying the folder as a sequence of white spaces. To the see the contents of that folder, root@host [/]# find . -inum 2343166 -maxdepth 1 -exec ls -la {} \; total 8 drwxr-xr-x 2 root root 4096 Oct 24 05:45 . drwxr-xr-x 23 root root 4096 Dec 27 23:09 .. root@host [/]# As you may see, that folder has no contents at all. You may use the same command to even delete that folder like, root@host [/]# find . -inum 2343166 -maxdepth 1 -exec rmdir {} \; So, using ls and find you will be able to deal with such special files/folders. |
|||||
Powered by
Deru Communications (Webhosting Knowledgebase)