Linux系统中cd无法进入xargs管道输出的目录
linux  /  管理员 发布于 7年前   416
今天在写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-plugins-1.4.15.tar.gz
drwxrwxrwx. 16 501 root 4096 Mar 3 14:36 nagios-plugins-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/bin/which: no cd in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
查看xargs的绝对命令:
[root@test1 nrpe-2.12]# which xargs
/usr/bin/xargs
详情如上,因非系统工程师,故此处不对shell的原理做深入研究。
【参考链接】
http://bbs.chinaunix.net/thread-750335-2-1.html
http://blog.csdn.net/jason_asia/article/details/28407189
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号