In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "Why cd can not enter the directory of xargs pipeline output in Linux system". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Today, when I was writing a shell script, I wanted to use cd to enter the directory of the xargs pipeline output, but I was prompted to report an error. Details are as follows:
[environment description]
Directory structure:
[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
Get the required directory:
[root@test1 nagiosclient_db] # ls | egrep 'nrpe- [0-9]. [0-9] + .$'
Nrpe-2.12
Use the pipe to enter the specified directory:
[root@test1 nagiosclient_db] # ls | egrep 'nrpe- [0-9]. [0-9] + .$' | xargs ls-ld | xargs cd
Xargs: cd: No such file or directory
Encountered an error message.
Modify the command:
[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
Entered the specified directory.
[why the cd command cannot enter the directory of xargs pipe output]
Xargs involves writing pipes, while cd is an internal command. Specifically related to the working principle of shell.
View the absolute path of the cd command:
[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)
View the absolute command for xargs:
[root@test1 nrpe-2.12] # which xargs
/ usr/bin/xargs
This is the end of the content of "Why cd in Linux system cannot enter the directory of xargs pipeline output". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.