Shell Programming Blog Shell Programming Blog

Wednesday, 17 October 2012

Linux Bash Scripting: how to rename or delete a file which has special characters in its filename

Unknown | 19:46 | |


Bash Linux Unix shell scripting

Suppose if you have created a file with a special character in its name because of a typo, you may not be able to access it. You may not even be able to delete the file. For example, see the below files.



If you see the output of ls command, you will not be able to identify the space at the end of the file. Hence you may not be able to access the file unless you specify a space at the end of the file using quotes.

The ? is a wild character for which any character can be substituted. Hence you may end up deleting or reading some other file.

To handle this situation, we can make use the inode of the file. Every file has a unique inode number with which we can identify the file. 



To rename the file:

You can specify the inode number in the find command as below to rename the files. The below command renames the file using  the inode number.



To delete the file:

You can delete the file using the inode number of the file with the help of "find" command as below.

 

0 Comments:

   

Post a Comment

Don't just read and walk away, Your Feedback Is Always Appreciated. I will try to reply to your queries as soon as time allows.

Note:
1. If your question is unrelated to this article, please use our Facebook Page.
2. Please always make use of your name in the comment box instead of anonymous so that i can respond to you through your name and don't make use of Names such as "Admin" or "ADMIN" if you want your Comment to be published.
3. Please do not spam, spam comments will be deleted immediately upon my review.

Regards,
Mohamed Abubakar Sittik A

 

Shell Programming Copyright © 2012 Shell Programming theme is Designed by Abusittik, Shell Programming