Deru Knowledgebase
Search:     Advanced search
Browse by category:
Contact Us

Delete files/folder having special characters in their name

Add comment
Views: 2756
Votes: 1
Comments: 0
Posted: 28 Dec, 2007
by: Prasad P.
Updated: 17 Jul, 2012
by: Prasad P.

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.
Others in this Category
document Unix and windows text file formats
document How to find uptime of a windows/Linux server ?
document rpmdb: Lock table is out of available locker entries ?
document Set up an SSH tunnel for webmail access using putty.
document SSH Port Forwarding (SSH tunneling ) in Linux machines.
document Use "find" comand to find files by time stamp
document Album access issue in Gallery
document How to install APC (Alternative PHP Cache)
document Steps to clear Browser cache
document How to clear DNS Cache
document How to change the hostname of a Linux system
document Upgrade from PHP4 to PHP5: Backward Incompatible Changes
document How to reset mysql root password in the server?
document Website creation and site management via Webmin/Virtualmin
document Contact Email Address for your website
document Using traceroute command
document How to migrate a mysql user to another server?
document How to create virtual server Alias in Virtualmin?
document How can we create sub domains via Virtualmin?
document How to configure email filters via cPanel?
document How ot redirect URLs via cPanel?
document How to deny an IP address via cPanel?
document How to change MySql database password via cpanel?
document How to change MySQL User Password?
document How to enable remote Mysql access from cPanel?
document Linux commands to check the hardware details.



RSS