Dan*_*iel 20 command-line sudo wildcards
我正在尝试取出 folder1 的所有内容并将其放入 folder1 所在的 images_temp 文件夹中:
jeatonhomes@jeatonhomes.com [~/images_temp]# sudo mv folder1/* .
mv: cannot stat `folder1/*': No such file or directory
Run Code Online (Sandbox Code Playgroud)
然而,我遇到了上面的错误,我试图在这里查找答案,但我认为有些答案不适用于我的情况。请帮忙。
jeatonhomes@jeatonhomes.com [~]# pwd && ls -l
/home/jeatonhomes
total 108
drwx--x--x 18 jeatonhomes jeatonhomes 4096 Apr 3 13:25 ./
drwx--x--x 106 root root 4096 Mar 30 16:19 ../
lrwxrwxrwx 1 jeatonhomes jeatonhomes 37 Dec 18 2015 access-logs -> /usr/local/apache/domlogs/jeatonhomes/
-rw------- 1 jeatonhomes jeatonhomes 628 Apr 3 13:25 .bash_history
-rw-r--r-- 1 jeatonhomes jeatonhomes 18 Sep 22 2015 .bash_logout
-rw-r--r-- 1 jeatonhomes jeatonhomes 176 Sep 22 2015 .bash_profile
-rw-r--r-- 1 jeatonhomes jeatonhomes 124 Sep 22 2015 .bashrc
drwxr-xr-x 2 jeatonhomes jeatonhomes 4096 Aug 4 2016 cache/
-rw-r----- 1 jeatonhomes jeatonhomes 20 Jan 4 14:10 .contactemail
drwx------ 5 jeatonhomes jeatonhomes 4096 Mar 20 22:39 .cpanel/
drwx------ 4 jeatonhomes jeatonhomes 4096 Aug 4 2016 .cphorde/
-rw-rw-r-- 1 jeatonhomes jeatonhomes 15 Apr 3 13:26 .dns
drwxr-x--- 2 jeatonhomes mail 4096 Jul 22 2016 etc/
-rw------- 1 jeatonhomes jeatonhomes 17 Mar 8 22:39 .ftpquota
drwxr-x--- 2 jeatonhomes nobody 4096 Dec 18 2015 .htpasswds/
drwxr-xr-x 2 root root 4096 Apr 3 13:45 images_temp/
-rw------- 1 jeatonhomes jeatonhomes 211 Jan 4 14:09 .lastlogin
drwx------ 2 jeatonhomes jeatonhomes 4096 Apr 1 08:16 logs/
drwxr-x--x 8 jeatonhomes jeatonhomes 4096 Dec 18 2015 mail/
drwxrwxr-x 4 jeatonhomes jeatonhomes 4096 Jan 4 14:27 perl5/
drwxr-x--- 3 jeatonhomes jeatonhomes 4096 Dec 18 2015 public_ftp/
drwxr-x--- 7 jeatonhomes nobody 4096 Apr 3 06:06 public_html/
drwx------ 2 jeatonhomes jeatonhomes 4096 Jan 4 14:10 .ssh/
drwxr-xr-x 5 jeatonhomes jeatonhomes 4096 Feb 15 06:34 ssl/
drwx------ 2 jeatonhomes jeatonhomes 4096 Nov 3 22:55 .subaccounts/
drwxr-xr-x 7 jeatonhomes jeatonhomes 4096 Jul 6 2016 tmp/
drwx------ 2 jeatonhomes jeatonhomes 4096 Dec 18 2015 .trash/
lrwxrwxrwx 1 jeatonhomes jeatonhomes 11 Dec 18 2015 www -> public_html/
-rw-r--r-- 1 jeatonhomes jeatonhomes 658 Nov 10 2015 .zshrc
Run Code Online (Sandbox Code Playgroud)
另外,我收到了这个错误:
jeatonhomes@jeatonhomes.com [~/public_html]# wp media import
/home/jeatonhomes/images_temp/* --title="Images for East 46th West 59th and Sycamore Road" --alt="New Images for April"
Warning: copy(/home/jeatonhomes/images_temp/62262529_0.jpg): failed to open stream: Permission denied in phar:///usr/local/bin/wp/php/commands/media.php on line 292
Error: Could not create temporary file for /home/jeatonhomes/images_temp/62262529_0.jpg.
jeatonhomes@jeatonhomes.com [~/public_html]# sudo wp media import /home/jeatonhomes/images_temp/* --title="Images for East 46th West 59th and Sycamore Road" --alt="New Images for April"
[sudo] password for jeatonhomes:
sudo: wp: command not found
Run Code Online (Sandbox Code Playgroud)
Sté*_*las 28
在
sudo mv folder1/* .
Run Code Online (Sandbox Code Playgroud)
你的 shell(像你一样运行,而不是root
)正在扩展(好吧,试图扩展)那个folder1/*
glob。
这会导致传递给 的许多参数sudo mv
。但是,在这里,您(与 相反root
)没有对该目录的读取访问权限,因此 glob 无法匹配任何文件。您的外壳是那些损坏的(IMO)外壳之一,bash
或者sh
当 glob 不匹配时,它会按原样传递。
因此,shell 没有返回一个错误来告诉您它没有找到任何匹配该模式的文件,而是将folder1/*
字符串作为参数传递给sudo mv
. 并mv
抱怨它找不到名为的文件folder1/*
(谢天谢地,在这种情况下是无害的)。
在这里,您希望该 glob 由 root 扩展,因此您需要以root身份启动一个 shell来扩展该 glob:
sudo sh -c 'mv folder1/* .'
Run Code Online (Sandbox Code Playgroud)