Linux系统中cd无法进入xargs管道输出的目录
今天在写shell脚本的时候,想用cd进入xargs管道输出的目录,提示报错。详情如下
【环境描述】
目录结构
[root@test1 nagiosclient_db]# ls -ltr
total 2488
-rw-r--r--. 1 root root 405725 Mar 3 14:12 nrpe-2.12.tar.gz
-rw-r--r--. 1 root root 2095419 Mar 3 14:12 nagios-plugs-1.4.15.tar.gz
drwxrwxrwx. 16 501 root 4096 Mar 3 14:36 nagios-plugs-1.4.15
drwxrwxr-x. 7 500 500 4096 Mar 3 14:37 nrpe-2.12
获取需要的目录
[root@test1 nagiosclient_db]# ls | egrep 'nrpe-[0-9].[0-9]+.$'
nrpe-2.12
使用管道进入指定的目录
[root@test1 nagiosclient_db]# ls | egrep 'nrpe-[0-9].[0-9]+.$' | xargs ls -ld | xargs cd
xargs: cd: No such file or directory
遇到报错提示。
修改命令
[root@test1 nagiosclient_db]# cd "`ls | egrep 'nrpe-[0-9].[0-9]+.$' `"
[root@test1 nrpe-2.12]# pwd
/home/monitor/nagiosclient_db/nrpe-2.12
进入了指定的目录。
【为什么cd命令不能进入xargs管道输出的目录】
xargs牵涉写管道,而cd是内部命令。具体的牵涉shell的工作原理。
查看cd命令的绝对路径
[root@test1 nrpe-2.12]# which cd
/usr/b/which: no cd (/usr/local/sb:/usr/local/b:/sb:/b:/usr/sb:/usr/b:/root/b)
查看xargs的绝对命令
[root@test1 nrpe-2.12]# which xargs
/usr/b/xargs
详情如上,因非系统工程师,故此处不对shell的原理做深入研究。
【参考链接】
http://bbs.chaunix./thread-750335-2-1.html
http://blog.csdn./jason_asia/article/details/28407189
网络推广
- 5g网络有多快:5g网络网速有多快
- dota2无法连接至steam网络 为什么无法连接dota2网络
- 无线网络信号接收器 无线网络信号接收器怎么用
- 网络延时是什么意思 网络延时是什么原因
- 无线网络不可用:无线网络不可用是什么原因
- 网络广告销售技巧 网络广告销售技巧有哪些
- 智能手机网络设置 智能手机网络设置在哪里
- 为什么找不到无线网络 为什么找不到无线网络信
- 网络这么赚钱:网络怎么能赚到钱
- 为什么无线网络连接不上 为什么无线网连不起来
- 网络上的人际交往 网络上人际交往的优势
- 支付宝网络系统异常 支付宝显示网络异常什么时
- 营销软件:营销软件有哪些
- 无法访问您要使用的功能所在的网络位置
- 网络安全基本知识 网络安全基本知识有哪些
- 什么网络电话最好用 什么网络电话最好用最便宜