您好,欢迎来到外链网!
当前位置:外链网 » 站长资讯 » 专业问答 » 文章详细 订阅RssFeed

Linux系统中cd无法进入xargs管道输出的目录(linux中cd的用法)

来源:互联网 浏览:45次 时间:2023-04-08

今天在写shell脚本的时候,想用cd进入xargs管道输出的内容介绍,但是提示报错。详情如下:

【环境描述】

如何在 Linux 中不使用 CD 命令进入目录 文件夹

内容介绍结构:

[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

通过Linux系统引导CD排除服务器故障 电脑课堂 LINUX教程

获取需要的内容介绍:

[root@test1 nagiosclient_db]# ls | egrep 'nrpe-[0-9].[0-9]+.$'
nrpe-2.12

LINUX操作系统中无法运行命令

使用管道进入指定的内容介绍:

[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

本文从互联网转载,来源地址:www.downzz.com/linuxs/193151.html,原作者保留一切权利,若侵权或引用不当,请联系茶猫云(cmy.cn)删除。【茶猫云,优质云服务器提供商】