LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 07-19-2012, 02:01 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Rep: Reputation: 76
'sudo ls /root/monitor/' outputs, 'sudo ls /root/monitor/*' does not


Hi:
Code:
semoi@host_1:/almacen/SLACK10$ sudo ls /root/monitor/
README  kbd_monitor  kbd_monitor.c  read_keyboard_status.txt
semoi@host_1:/almacen/SLACK10$ sudo ls /root/monitor/*
ls: cannot access /root/monitor/*: No such file or directory
semoi@host_1:/almacen/SLACK10$
Who is to blame (maybe me)? Anything to do with globbing? Thanks in advance.

GNU bash, version 3.1.17(2)-release (i486-slackware-linux-gnu)
Slackware 12.0

Last edited by stf92; 07-19-2012 at 02:24 PM.
 
Old 07-19-2012, 02:22 PM   #2
dmdeb
Member
 
Registered: Jul 2007
Location: Germany
Distribution: Debian
Posts: 45

Rep: Reputation: 6
Quote:
Originally Posted by stf92 View Post
Hi:
Code:
semoi@host_1:/almacen/SLACK10$ sudo ls /root/monitor/
README  kbd_monitor  kbd_monitor.c  read_keyboard_status.txt
semoi@host_1:/almacen/SLACK10$ sudo ls /root/monitor/*
ls: cannot access /root/monitor/*: No such file or directory
semoi@host_1:/almacen/SLACK10$
Who is to blame (maybe me)?

GNU bash, version 3.1.17(2)-release (i486-slackware-linux-gnu)
Slackware 12.0
Hi std02,

I guess your shell tries to expand the "*" before actually invoking the ls command with superuser rights. For example, compare the outputs of these two commands:
echo /tmp/*
echo "/tmp/*"

What happens if you try

sudo "ls /root/monitor/*"

instead?

Regards
dmdeb
 
Old 07-19-2012, 02:35 PM   #3
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
The same thing, exactly, that is, 'No such file or directory'. I created semoi thus:

useradd -d semoi -s /usr/bin/bash -m semoi.

This is /etc/passwd right now:
Code:
root@host_1:/etc# cat passwd
root:x:0:0::/root:/bin/bash
bin:x:1:1:bin:/bin:/bin/false
daemon:x:2:2:daemon:/sbin:/bin/false
adm:x:3:4:adm:/var/log:/bin/false
lp:x:4:7:lp:/var/spool/lpd:/bin/false
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/:/bin/false
news:x:9:13:news:/usr/lib/news:/bin/false
uucp:x:10:14:uucp:/var/spool/uucppublic:/bin/false
operator:x:11:0:operator:/root:/bin/bash
games:x:12:100:games:/usr/games:/bin/false
ftp:x:14:50::/home/ftp:/bin/false
smmsp:x:25:25:smmsp:/var/spool/clientmqueue:/bin/false
mysql:x:27:27:MySQL:/var/lib/mysql:/bin/bash
rpc:x:32:32:RPC portmap user:/:/bin/false
sshd:x:33:33:sshd:/:/bin/false
gdm:x:42:42:GDM:/var/state/gdm:/bin/bash
apache:x:80:80:User for Apache:/srv/httpd:/bin/false
messagebus:x:81:81:User for D-BUS:/var/run/dbus:/bin/false
haldaemon:x:82:82:User for HAL:/var/run/hald:/bin/false
pop:x:90:90:POP:/:/bin/false
nobody:x:99:99:nobody:/:/bin/false
semoi:x:1000:100::/home/semoi:/usr/bin/bash
root@host_1:/etc#
About your suggestion: I was wrong:
Code:
semoi@host_1:/almacen/SLACK10$ sudo "ls /root/monitor/*"
sudo: ls /root/monitor/*: command not found
semoi@host_1:/almacen/SLACK10$

Last edited by stf92; 07-19-2012 at 02:47 PM.
 
Old 07-19-2012, 02:47 PM   #4
dmdeb
Member
 
Registered: Jul 2007
Location: Germany
Distribution: Debian
Posts: 45

Rep: Reputation: 6
Okay, then let's invoke a shell that can properly expand the *:

sudo bash -c ls /root/monitor/*

(i.e.: Run a bash shell with the command line following -c).
 
Old 07-19-2012, 02:52 PM   #5
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Code:
semoi@host_1:/almacen/SLACK10$ sudo bash -c ls /root/monitor/*
README.1st                         slackware-10.2-install-d2.iso.md5
gpg-key                            slackware-10.2-source-d3.iso
s1.sh                              slackware-10.2-source-d3.iso.asc
s1.sh~                             slackware-10.2-source-d3.iso.md5
slackware-10.2-install-d1.iso      slackware-10.2-source-d4.iso
slackware-10.2-install-d1.iso.asc  slackware-10.2-source-d4.iso.asc
slackware-10.2-install-d1.iso.md5  slackware-10.2-source-d4.iso.md5
slackware-10.2-install-d2.iso      work
slackware-10.2-install-d2.iso.asc
semoi@host_1:/almacen/SLACK10$
Here he lists the working directory instead (/almacen/SLACK10).
 
Old 07-19-2012, 02:54 PM   #6
dmdeb
Member
 
Registered: Jul 2007
Location: Germany
Distribution: Debian
Posts: 45

Rep: Reputation: 6
Quote:
Originally Posted by stf92 View Post
Code:
semoi@host_1:/almacen/SLACK10$ sudo bash -c ls /root/monitor/*
README.1st                         slackware-10.2-install-d2.iso.md5
gpg-key                            slackware-10.2-source-d3.iso
s1.sh                              slackware-10.2-source-d3.iso.asc
s1.sh~                             slackware-10.2-source-d3.iso.md5
slackware-10.2-install-d1.iso      slackware-10.2-source-d4.iso
slackware-10.2-install-d1.iso.asc  slackware-10.2-source-d4.iso.asc
slackware-10.2-install-d1.iso.md5  slackware-10.2-source-d4.iso.md5
slackware-10.2-install-d2.iso      work
slackware-10.2-install-d2.iso.asc
semoi@host_1:/almacen/SLACK10$
Here he lists the working directory instead (/almacen/SLACK10).
ARGH - sorry! My third and last try:

sudo bash -c "ls /root/monitor/*"

That is, protect the entire command by "".
 
Old 07-19-2012, 02:55 PM   #7
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
I have been playing with different incarnations of this. Unexpected shell expansions are a common stumbling block.

Invoking a new shell still has some surprises.

Unless there is some good reason for not using ls /root/monitor/ (without the splat), just use that form, or su to root.

[EDIT]
It is important to note that the cause is NOT something "wrong".

It is just too many cooks in the kitchen - sudo, bash, ls, CWD - with conflicting jobs and precedence order. Instead of forcing them to all work on the same omlette, simplify the task (use the one that works) or step into the next kitchen (su to really be root).
[/EDIT]

Last edited by astrogeek; 07-19-2012 at 03:00 PM.
 
Old 07-19-2012, 03:01 PM   #8
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
I was trying to sudo cp from /root/monitor to semoi's dir and, of course, with the same problem. But I presume that would leave root's permissions there. As this is a recent reinstalation perhaps I did something different.
 
Old 07-19-2012, 03:06 PM   #9
dmdeb
Member
 
Registered: Jul 2007
Location: Germany
Distribution: Debian
Posts: 45

Rep: Reputation: 6
Quote:
Originally Posted by stf92 View Post
I was trying to sudo cp from /root/monitor to semoi's dir and, of course, with the same problem. But I presume that would leave root's permissions there. As this is a recent reinstalation perhaps I did something different.
Well, on my system, the following works just fine:

sudo bash -c "cp /root/install/* ."

(/root/install/ contains some files I installed as root such as nvidia drivers)
 
Old 07-19-2012, 03:12 PM   #10
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
In mine too. But I have installed 12.0 a thousand times and never did this happen! astrogeek must be right! Off for lunch. Back in five.
 
Old 07-19-2012, 05:20 PM   #11
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
On second thought, maybe I had never used such a command before. I'll have to use double quotes then or to adhere to astrogee's advice. Thanks for the posts.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sudo cd /root gives 'sudo: cd: command not found'. stf92 Linux - Newbie 4 03-03-2012 09:05 AM
root ,sudo !! shanky Linux - Newbie 22 10-22-2011 04:45 AM
Can't use sudo, only account that's not root is not a sudo'ers [Ubuntu 9.10] randyriver10 Linux - Desktop 1 01-09-2010 07:56 PM
How to hack sudo to become root lewkh Linux - Security 5 01-08-2005 06:20 AM
Sudo, su and root lesleyb Linux - Security 3 10-18-2004 01:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 02:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration