"Linux notes" CD fails to enter the Xargs pipeline output directory

Source: Internet
Author: User
Tags egrep

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

"Environment description"

Directory structure:

[Email protected] 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. 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:

[[email protected] nagiosclient_db]# ls | Egrep ' nrpe-[0-9]. [0-9]+.$ '
nrpe-2.12

Use the pipeline to enter the specified directory:

[[email protected] 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 a command:

[[Email protected] nagiosclient_db]# CD "' ls | Egrep ' nrpe-[0-9]. [0-9]+.$ ']
[Email protected] nrpe-2.12]# pwd
/home/monitor/nagiosclient_db/nrpe-2.12

entered the specified directory.


"Why does the CD command not go to the Xargs pipeline output directory"

Xargs involves writing pipelines, while CDs are internal commands. Specifically involved in how the shell works.

To view the absolute path of the CD command:

[[email protected] 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 Xargs's absolute commands:

[email protected] nrpe-2.12]# which Xargs
/usr/bin/xargs

For details, as a non-system engineer, there is no in-depth study of the Shell's principles.


"Reference link"

Http://bbs.chinaunix.net/thread-750335-2-1.html

http://blog.csdn.net/jason_asia/article/details/28407189

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.