Why doesn't the wildcard work in the `rm` expression?

I tried to delete all files in the logs directory and use the default bash shell on CentOS 6.5

[lei@ids7gueywjZ /]$ sudo ls -al /var/log/jenkins/
total 1541512
drwxr-x---   2 jenkins jenkins       4096 Jul 22 09:52 .
drwxr-xr-x. 10 root    root          4096 Jul 14 21:27 ..
-rw-r--r--   1 jenkins jenkins      31483 Jul 22 17:07 jenkins.log
-rw-r--r--   1 jenkins jenkins 1073606656 Jul 18 03:16 jenkins.log-20150718
-rw-r--r--   1 jenkins jenkins  504815011 Jul 19 03:30 jenkins.log-20150719.gz
[lei@ids7gueywjZ /]$ sudo rm -r /var/log/jenkins/*
rm: cannot remove `/var/log/jenkins/*': No such file or directory

      

I don't understand why it rm -r /var/log/jenkins/*

doesn't work? Is there some default shell configuration I was missing?

+3


source to share


2 answers


The expansion of the lookup is done by the shell, not rm

.

And the shell has no rights sudo

, it only rm

does.

Since the shell has no read permission /var/log/jenkins

, there is no extension, and it rm

tries to delete the file (not the wildcard) /var/log/jenkins/*

- which does not exist.



To get around this, you need a shell with rights sudo

running your rm

:

sudo sh -c 'rm /var/log/jenkins/*'

      

+7


source


The directory /var/log/jenkins

does not have permission for "other". Even if you run it sudo rm -r /var/log/jenkins/*

, the shell expansion will be done by your user. You must either delete all code ( suro rm -r /var/log/jenkinks

) or do everything as the appropriate user (I would recommend su

-ing with the user jenkins

).



0


source







All Articles