Why the CD command failed to enter the directory for Xargs pipeline output

Source: Internet
Author: User
Tags egrep

Today, when writing a shell script, you want to use a CD to enter the Xargs pipeline output directory, but prompted the error. Details are as follows:

"Environment description"

Directory structure:

[Root@test1 nagiosclient_db]# ls-ltr

Total 2488

-rw-r--r--. 1 root 405725 Mar 3 14:12 nrpe-2.12.tar.gz

-rw-r--r--. 1 root 2095419 Mar 3 14:12 nagios-plugins-1.4.15.tar.gz

Drwxrwxrwx. 501 root 4096 Mar 3 14:36 nagios-plugins-1.4.15

Drwxrwxr-x. 7 4096 Mar 3 14:37 nrpe-2.12

Get the directory you want:

[Root@test1 nagiosclient_db]# ls | Egrep ' nrpe-[0-9]. [0-9]+.$ '

nrpe-2.12

To enter a specified directory using a pipe:

[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 prompt.

To 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 for Xargs pipeline output"

Xargs involves writing pipes, while CDs are internal commands. Concrete involves the workings of the shell.

To 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)

To view the absolute commands for Xargs:

[Root@test1 nrpe-2.12]# which Xargs

/usr/bin/xargs

Details such as the above, because of the non-system engineers, so the shell's principle does not do in-depth research.

This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/

Author: csdn Blog Jason_asia

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.