xargs AND cd WITH MORE MANIPULATION

ABOUT xargs

xargs is a command on Unix and most Unix-like operating systems used to build and execute commands from standard input. It converts input from standard input into arguments to a command.

Some commands such as grep and awk can take input either as command-line arguments or from the standard input. However, others such as cp and echo can only take input as arguments, which is why xargs is necessary.

TYPICAL SHELL SESSION EXPOSURE
[bash]
$ls shelter/
symmel
$ls shelter/ | xargs cd –
xargs: cd: No such file or directory
$ls shelter/ | xargs sh -c cd –
$pwd
/home/jeffrin
$ls shelter/ | xargs ls
ls: cannot access symmel: No such file or directory
$ls shelter/ | xargs cd
xargs: cd: No such file or directory
$ls shelter/ | xargs sh -c cd
$pwd
/home/jeffrin
$ls shelter/ | xargs `sh -c cd – `
symmel
$pwd
/home/jeffrin
$ls shelter/ | xargs `sh -c cd `
symmel
$ls shelter/ | xargs sh -c cd
$pwd
/home/jeffrin
$ls shelter/ | xargs `sh -c cd` –
xargs: -: No such file or directory
$ls shelter/ | xargs sh -c cd –
$pwd
/home/jeffrin
$cd symmel-code/
$cd ..
$pwd
/home/jeffrin
$cd shelter/symmel/
$ls
Algorithms beautifulwork books config-files Docs https: language ovlfose
art.text bookmark bugs-general debian-howtos firewall kernel linux README
$ls config-files/ | xargs ls
ls: cannot access corporation-style.txt: No such file or directory
ls: cannot access dot-bashrc: No such file or directory
ls: cannot access dot-emacs: No such file or directory
ls: cannot access dot-gitconfig: No such file or directory
ls: cannot access dot-muttrc: No such file or directory
ls: cannot access dot-muttrc-personal: No such file or directory
ls: cannot access dot-procmailrc: No such file or directory
ls: cannot access fullscreen.text: No such file or directory
ls: cannot access git-smtp-yahoo-commands.txt: No such file or directory
ls: cannot access likins-glow.scm: No such file or directory
ls: cannot access minimal-style.sheet.txt: No such file or directory
ls: cannot access regex.txt: No such file or directory
ls: cannot access save: No such file or directory
ls: cannot access scripts: No such file or directory
ls: cannot access sources.list: No such file or directory
README
$cd config-files/ | xargs ls
Algorithms beautifulwork books config-files Docs https: language ovlfose
art.text bookmark bugs-general debian-howtos firewall kernel linux README
$pwd
/home/jeffrin/shelter/symmel
$cd config-files/ | xargs pwd
/home/jeffrin/shelter/symmel
$cd config-files/
$pwd
/home/jeffrin/shelter/symmel/config-files
$cd ..
$pwd
/home/jeffrin/shelter/symmel
$

[/bash]

RELATED LINKS
https://en.wikipedia.org/wiki/Xargs
https://shapeshed.com/unix-xargs/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s