0

Ubuntu 16.04.6 LTS

A weird one at first, but I think I narrowed down my issue to a question of permissions and how asterisk(*) is interpreted on the command line because of it.

I was originally analysing apache log files but recreated the question as follows.

Two users: user1 and user2

User2 owns the folder in question, with the following permissions:

user2@server-01:~$ ls -lahd myFolder/
drwxrwx--- 2 user2 user2 4.0K Aug 28 13:22 myFolder/

The folder contains a bunch of files, named with a naming convention that can be followed. i.e.

user2@server-01:~/myFolder$ ls -l
total 0
-rw-rw-r-- 1 user2 user2 0 Aug 28 13:24 abc_1
-rw-rw-r-- 1 user2 user2 0 Aug 28 13:24 abc_2
-rw-rw-r-- 1 user2 user2 0 Aug 28 13:24 abc_3
-rw-rw-r-- 1 user2 user2 0 Aug 28 13:24 abc_4
-rw-rw-r-- 1 user2 user2 0 Aug 28 13:24 abc_5
-rw-rw-r-- 1 user2 user2 0 Aug 28 13:24 def_1
-rw-rw-r-- 1 user2 user2 0 Aug 28 13:24 def_2
-rw-rw-r-- 1 user2 user2 0 Aug 28 13:24 def_3
-rw-rw-r-- 1 user2 user2 0 Aug 28 13:24 def_4
-rw-rw-r-- 1 user2 user2 0 Aug 28 13:24 def_5

If I only want to analyse, or list, the 'abc' files in the folder we can of course do this (as user2):

user2@server-01:~/myFolder$ ls -l abc*
-rw-rw-r-- 1 user2 user2 0 Aug 28 13:24 abc_1
-rw-rw-r-- 1 user2 user2 0 Aug 28 13:24 abc_2
-rw-rw-r-- 1 user2 user2 0 Aug 28 13:24 abc_3
-rw-rw-r-- 1 user2 user2 0 Aug 28 13:24 abc_4
-rw-rw-r-- 1 user2 user2 0 Aug 28 13:24 abc_5

Now, user1's user is configured as follows (note they're a sudoer):

user1@server-01:~$ id
uid=1004(user1) gid=1004(user1) groups=1004(user1),27(sudo)

Of course, our user1 won't be able to list the content of myFolder, unless we precede the command with sudo. Like this:

user1@server-01:~$ ls /home/user2/myFolder
ls: cannot open directory '/home/user2/myFolder': Permission denied

user1@server-01:~$ sudo ls /home/user2/myFolder
abc_1  abc_2  abc_3  abc_4  abc_5  def_1  def_2  def_3  def_4  def_5

Finally, my question is how does user1 list only the 'abc' files, because the sudo command, or the directory permissions, or something around the security is not interpreting the asterisk in the below command, in the normal way?

user1@server-01:~$ sudo ls /home/user2/myFolder/abc_*
ls: cannot access '/home/user2/myFolder/abc_*': No such file or directory

Or am I misunderstanding the situation completely?

2

1 Answer 1

0

Excellent explanation here: https://unix.stackexchange.com/questions/101847/cannot-expand-asterisk-without-proper-permission

We'll need to call the shell with sudo and pass the whole command with the -c flag

[user1@server-01 ~]$ sudo sh -c 'ls -l /home/user2/myFolder/abc*'
-rw-rw-r--. 1 user2 user2 0 Aug 28 14:01 /home/user2/myFolder/abc_1
-rw-rw-r--. 1 user2 user2 0 Aug 28 14:01 /home/user2/myFolder/abc_2
-rw-rw-r--. 1 user2 user2 0 Aug 28 14:01 /home/user2/myFolder/abc_3
-rw-rw-r--. 1 user2 user2 0 Aug 28 14:01 /home/user2/myFolder/abc_4
-rw-rw-r--. 1 user2 user2 0 Aug 28 14:01 /home/user2/myFolder/abc_5

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .