How to remove directory name with special characters and directories with variable name env on UNIX

I did a search in this repository and I didn’t find any similar questions or maybe my search was wrong.

I have this problem in my client environment, the user application creates directories with the environment variable "$ SRCDIR" and "$ HOME", and the directory where they are created is itself the dir HOME path. if I say rm -rf $HOME, then all files and subdir in $ HOME, which is the current directory, will be deleted. How to remove these unwanted directories.

-rw-r--r--  1 grp domain users 418051450 Apr 18 18:09 $SRCDIR
-rw-r--r--  1 grp domain users 418051450 Apr 18 18:09 $HOME

Also, some directories are unnecessary characters, as shown below.

-rwxr-xr-x  1 grp domain users  0 Feb  7  2106 ??????w?O???*????_6??t??Ó¡?>?tP??Ñ?|?C

How to remove them?

+5
source share
7 answers

, . (, _6) . :

ls *_6*

, :

rm *_6*

, , :

ls *w*_6*tP*N*x*

, , .

+10

--rw-r-r--. : rm -rf ./--rw-r-r-- >

+7

inode /:

# ls -ila 
14549980 drwxr-xr-x  3 root root       4096 Mar  5 20:45 ">?<

rm:

find . -inum 14549980  -exec rm -ir {} \;
+5

zsh shell linux

[root@rhel5-8 ~]# zsh
[root@rhel5-8]~

, .

bash

[root@rhel5-8 ~]# cd "??????w?O???*????_6??t??Ó¡?>?tP??Ñ?|?C???????>?̤-???y?X???N?x??H?????Ч)?n?5‌​??{@?~]?" 

+3
source

You can try rm -rf '$ HOME' '$ SRCDIR', since single quotes will prevent shell variables from expanding. tried using bash and ksh.

+2
source

Just avoid the dollar sign. Try it like this -

rm -rf \$HOME

Same thing with the symbol ?.

0
source

You can use the c program to avoid shell / escape problems. Look at the answers to this question .

0
source

All Articles