2

This question already has an answer here:

I remove some files using trash-cli:

$ pwd
/tmp/test
$ sudo trash mfile 
$

Then I look for where the deleted file is stored:

$ sudo ls /.Trash/0/ -la
total 16
drwx------ 4 root root 4096 May 19 16:52 .
drwx------ 3 root root 4096 May 19 16:52 ..
drwx------ 2 root root 4096 May 19 16:52 files
drwx------ 2 root root 4096 May 19 16:52 info

$ sudo ls /.Trash/0/* -la
ls: cannot access '/.Trash/0/*': No such file or directory

$ sudo ls /.Trash/0/files/ -la
total 12
drwx------ 2 root root 4096 May 19 16:52 .
drwx------ 4 root root 4096 May 19 16:52 ..
-rw-rw-r-- 1 t    t       6 May 19 16:48 mfile

Why does filename expansion not work in the second command?

Thanks.

marked as duplicate by Michael Homer, muru, Jeff Schaller, telcoM, Barmar May 20 '18 at 4:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Why are you putting your switches after the directory? – Jesse_b May 19 '18 at 22:24
6

The first ls shows that /.Trash/0/ is only readable by root (the first line, the one for .). Since you're using sudo, you probably aren't root, so your shell can't list the contents of the directory and can't expand the *. ls /.Trash/0/ without the sudo would probably give Permission denied.

This is similar to how sudo echo foo > /some/path/filename doesn't work, if /some/path is writable only by root: The shell processes expansions and redirections before running sudo. You'd need sudo bash -c 'ls /.Trash/0/*' or such to have the command line processed under sudo.

  • Thanks. By sudo, didn't I get superuser privillege to read /.Trash/0/? – Tim May 19 '18 at 22:51
  • 2
    Sure you did, @Tim, but the shell performs pathname expansion on the (whole) command before executing it. In this case, that means it does the expansion with your ordinary, unprivileged identity, because it is only by running the (expanded) command that you obtain privilege. By then, it is too late. – John Bollinger May 20 '18 at 3:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.