/usr/usr bin python下的命令可以直接用名字启动吧,不用再输入/usr/bin打头

Linux在执行shell脚本时提示find: command not found,单独执行该命令可以正常执行_百度知道
Linux在执行shell脚本时提示find: command not found,单独执行该命令可以正常执行
执行时提示一下命令./backup.sh: line 45: date: command not found
//对应生成日子中显示日期./backup.sh: line 47: find: command not found
//对应删除备份
#!/bin/bash#设置日志文件,提前建好log目录LogFile=/home/oracle/bin/log/`date +&%Y-%m-%d&`.logecho &backup start at $(date +&%Y-%m-%d %H:%M:%S&)& &$LogFileecho &backup end at $(date +&%Y-%m-%d %H:%M:%S&)& &$LogFileecho &start open ftp server at $(date +&%Y-%m-%d %H:%M:%S&)& & $LogFileecho &put ftp end at $(date +&%Y-%m-%d %H:%M:%S&)& &$LogFile#最后上传完毕后再查看本地备份大于7天的自动删除,这样就可以实现本地异地双备份find /backup/datadmp -type f -mtime +8 -exec rm -f {} \;exit 0其中就第一个echo中能正常显示出时间来,其他的都提示date: command not found
我有更好的答案
你添加了指定解析器的说明了吗? #!/bin/sh写在开头第一行~最好把代码贴出来看看。
#!/bin/bash
说明了这个
因为你其他的date都没有加执行符号 【·】 你看看你的第一个date和后面几个有何区别,就是在date前面一个字符而且文件内容追加的话需要用 【&&】号。
开始就第一个那是& ,其他的都是&&着,但就第一个可以正常执行,我就把别的也都改成&了,我这命令就是直接复制的呀,实在找不出哪不同,帮帮我看看应该在哪加这个符号啊
查一下PATH环境变量,shell没有获取到。
具体怎么操作?
1、你可以写个脚本测试一下#!/bin/shecho $PATH & path.txt2、你可以检查~/.bash_profile,/etc/profile3、你可以在自己的脚步增加变量PATH=$PATH:/usr/bin:/bin
我echo中为什么第一个正确执行了,其他的都不能输出时间呢
把&改成&&,&号会清除之前的记录
脚本代码粘上来看看
确认你的脚本所在目录是你的shell目录吗?不是的话更改find路径,是的话给予脚本最大权限。
我脚本中其他命令都正确执行了,就这几条不能执行,怎么给脚本最大权限,是开chmod 777这样么
嗯,另外把你脚本文件名字改一下,改成backup1等那种把你的$LogFile相关文件权限也给777 echo &backup start at $(date +&%Y-%m-%d %H:%M:%S&)& &$LogFileecho &backup end at $(date +&%Y-%m-%d %H:%M:%S&)& &$LogFileecho &start open ftp server at $(date +&%Y-%m-%d %H:%M:%S&)& & $LogFileecho &put ftp end at $(date +&%Y-%m-%d %H:%M:%S&)& &$LogFile这里边把外边的双引号去掉,你原来那样用会出问题的
尝试加一下命令的绝对路径 ,
比如 date 换成
/usr/sbin/date
写绝对路径
怎么写能具体说下么
/bin/date/usr/bin/find 之类的有可能不一样用whereis 或者which 找出绝对路径
找出find的绝对路径么?然后怎么在脚本中写呢
就写绝对路径如:/usr/bin/find
1条折叠回答
其他2条回答
为您推荐:
其他类似问题
shell脚本的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。请问这个是哪个女星吗_百度知道
请问这个是哪个女星吗
我有更好的答案
她是“이수빈”(Ins:baby_bin47),是afreeca主播“열매”。
采纳率:73%
来自团队:
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。Ubuntu里面普通权限用户如何在控制台里面访问/usr /bin /lib等文件夹?_百度知道
Ubuntu里面普通权限用户如何在控制台里面访问/usr /bin /lib等文件夹?
如何用命令访问Ubuntu的全部文件夹?普通权限用户可以吗?使用什么命令? cd -L好像只能到/home这里,再高一级就不行了~求高手指点呀~~~
我有更好的答案
开启管理员权限。用管理员权限打开文件夹,在终端输入sudo nautilus或者sudo apt-get install nautilus-open-terminal安装,重启后,再右键单击文件夹,就可以看到“以管理员身份打开”。【其他】终端默认的启动位置就是当前用户目录,所以你cd -L当然是当前用户了。如果只是访问而不涉及修改的话,不需要root权限。直接输入以下命令就可以:cd /usrcd /bincd /lib如果需要对根用户权限下的文件或文件夹做修改的话,需要把自身权限提为root权限。方法就是在命令前加上一个sudo,然后按照提示输入root密码即可。
管理员权限用管理员权限打开文件夹,在终端输入sudo nautilus或者sudo apt-get install nautilus-open-terminal安装,重启后,再右键单击文件夹,就可以看到“以管理员身份打开”
终端默认的启动位置就是当前用户目录所以你cd -L当然是当前用户了……如果只是访问而不涉及修改的话,不需要root权限直接:cd /usrcd /bincd /lib之类的这些命令就可以~~如果需要对根用户权限下的文件或文件夹做修改的话需要把自身权限提为root权限方法就是在命令前加上一个sudo然后按照提示输入root密码即可
本回答被提问者采纳
通常ubuntu是关闭最高权限的,先提升用户权限到root,注销重新用root登陆,另外命令前要加sudo 的,具体细节可以在网上搜索一下。
语句前加sudo
其他2条回答
为您推荐:
其他类似问题
您可能关注的内容
ubuntu的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。shell - file $(ls /usr/bin/* | grep zip) command gives me errors. What's wrong? - Unix & Linux Stack Exchange
Stack Exchange Network
Stack Exchange network consists of 174 Q&A communities including , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
to customize your list.
This site uses cookies to deliver our services and to show you relevant ads and job listings.
By using our site, you acknowledge that you have read and understand our , , and our .
Your use of Stack Overflow’s Products and Services, including the Stack Overflow Network, is subject to these policies and terms.
I'm a total noob when it comes to unix/linux commands and I decided to read a book.
I've reached a chapter where they try to explain how to pass the output of commands as expansions to the shell.
The following command
file $(ls /usr/bin/* | grep zip)
gives me the error "cannot open "file name (No such file or directory)".
On the contrary, when I do
file $(ls | grep zip)
everything appears normally, no matter the folder. Why? Is it some kind of argument restriction?
If I do this
file $(ls Pictures/ | grep jpg)
I get the following:
1234.jpg: ERROR: cannot open 1234.jpg (No such file or directory)
while moving right in the directory that I want to list
nassosdim@ubuntu:~$ cd Pictures/
nassosdim@ubuntu:~/Pictures$ file $(ls | grep jpg)
prints out the result of file
1234.jpg: JPEG image data, JFIF standard 1.01
Can someone explain to me what's going on? :(
The error is coming because bash is trying to expand the * in your argument to ls using glob pattern matching. It will always through such an error when the glob doesn't match the pattern. The * then gets passed to ls as a real asterisk, which doesn't match a file either so ls will error!
There are several bits about what you are doing that are redundant. I know you are trying to learn a construct, but let's break down some of the bits of what you just accomplished and how it could have been done.
ls /usr/bin is sufficient to list files in the bin directory, you don't need the star at all.
You should never
at all, it is ambiguous and potentially dangerous.
You could get the same effect without grep by doing ls /usr/bin/*zip*, but the ls is still redundant, you can just pass the glob expantion to file: file /usr/bin/*zip*
Lastly, find is usually a better tool for finding files. You could do what you are after like this:
$ find /usr/bin -iname '*zip*' -exec file {} +
47.9k8142180
The shell expands the * and turns the command into file $(ls /usr/bin/a /usr/bin/b /usr/bin/whatever | grep zip).
You don't need to specify a asterisk in UNIX unless you want the shell to expand it to include everything before it passes it to the ls.
i.e. your shell replaces the * with every matching file before it runs the command, which is not how it works on Windows if you're used to that.
file $(ls /usr/bin/ | grep zip)
is the right way to do it (right in the sense that you don't need the *, but see Caleb's answer for other issues and options).
But note, that actually runs,
file /usr/bin/a /usr/bin/b /usr/bin/whatever
file /usr/bin/a
file /usr/bin/b
file /usr/bin/whatever
again, it doesn't do it the way windows does.
15.2k33952
Please try ls /usr/bin/* | grep zip to see what arguments you are feeding to file. I was baffled by the result a bit. On my Ubuntu system, the result is this:
/usr/bin/funzip
/usr/bin/gpg-zip
/usr/bin/mzip
/usr/bin/preunzip
/usr/bin/prezip
/usr/bin/prezip-bin
/usr/bin/unzip
/usr/bin/unzipsfx
/usr/bin/zip
/usr/bin/zipcloak
/usr/bin/zipgrep
/usr/bin/zipinfo
/usr/bin/zipnote
/usr/bin/zipsplit
prezip-bin
Using ls /usr/bin/* | less we can see why we get that result: after all the files in /usr/bin, ls also lists the contents of the /usr/bin/X11 directory, and it lists them without the directory names prepended.
And when you feed these file names without a directory name to file, file cannot find these files and you get the "No such file or directory" error messages (as a side note: if you get error messages, please don't just say "I got errors", but post the error messages).
Like Caleb already posted, just use file /usr/bin/*zip*.
Parsing the results of ls can be a risky business as the output format varies. You'd be better doing something like this:
file /path/to/*.zip
Try a simpler command to demonstrate how process substitution works:
ls $(echo /usr/bin)
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Post as a guest
Post as a guest
By clicking &Post Your Answer&, you acknowledge that you have read our updated ,
and , and that your continued use of the website is subject to these policies.
Not the answer you're looking for?
Browse other questions tagged
Unix & Linux Stack Exchange works best with JavaScript enabledubuntu 怎样用命令行的方式启动一个程序_百度知道
ubuntu 怎样用命令行的方式启动一个程序
我有更好的答案
方法是直接敲命令名,shell会在path变量定义的路径中寻找(默认为/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games)如果是你自己开发的(不在path里),需要完整路径名如/home/$HOME/a.out或相对路径名,如./程序名 (点代表你的当前工作目录)在用cX+shift+F1-6呼出的终端中只能启动CLI(PS:字符界面)的程序,如ping,whois,rm无法启动firefox,nautilus等要用GUI(PS:图形界面)的程序。而在你在图形界面中打开的Terminal(用cT+shift打开)则无此限制
采纳率:66%
当前目录下./程序名一定要加上./,解释为当前目录,如./eclipse
为您推荐:
其他类似问题
您可能关注的内容
ubuntu的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。

我要回帖

更多关于 usr bin env python 的文章

 

随机推荐