Friday, August 12, 2011

Removing Files in Linux having Name starting with special characters

Since on  Linux everything is to be considered as file, So a file may have any name that start with anything. So in case you got some file that has name starting with some unusual characters or you can say with special characters.

                         This post will show you about "How to Delete files whose name start with special characters in Linux".
e.g. files like --test2.

There are two ways to delete such files.
1.) Find inode of that particular file to be deleted and then delete using find command.

        Syntax:  ~]# find . -inum -exec rm -rf {} \;

2.) Second way is use rm command in following manner.

       Syntax: ~]# rm -rf ./


Now let me show you with Example. Here suppose I have a file having name ~test1. So for deleting this file....
Using find command :
                           [root@server199 ks]# ll -i 
                           total 0
                           16154646 -rw-r--r-- 1 root root 0 Aug 12 13:44--test
                    
                           [root@server199 ks]# find . -inum 16154646 -exec rm -rf {} \;
                           [root@server199 ks]# ll -i
                           total 0

Using rm Command:
                            [root@server199 ks]# ll -i
                            total 0
                            16154646 -rw-r--r-- 1 root root 0 Aug 12 13:47 --test
                            [root@server199 ks]# rm -rf ./--test
                            [root@server199 ks]# ll -i
                            total 0

                          
!Hope This will help You

Kuldeep Sharma

No comments:

Post a Comment

Kubernetes 1.31 || Testing the Image Volume mount feature using Minikube

With Kubernetes new version 1.31 ( https://kubernetes.io/blog/2024/08/13/kubernetes-v1-31-release/ ) there are so many features releases for...