Wednesday, May 1, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 3104  / 3 Years ago, mon, may 17, 2021, 1:21:20

I am trying to understand how to use the stdout as the stdin of another command. To test it, I am trying to use the following command to delete all directories from the current folder.



ls -d -- */ | rm -rf $1


I would expect the result of ls -d -- */ to be piped into the input of the rm, but it does not work. Ideas?


More From » bash

 Answers
3

Not all commands/programs will directly accept piped input (including rm). Additionally, why are you using the bash substitution variable $1 outside of a script?



For your general case, you need to look at xargs, a utility whose goal is to simplify such scenarios by taking a list from stdin and then invoking a command with the elements of that list (in different possible ways).



For what you want to do...(use it wisely!): rm -rf * (or .) will suffice.


[#36350] Wednesday, May 19, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
suitman

Total Points: 487
Total Questions: 105
Total Answers: 98

Location: India
Member since Wed, Aug 4, 2021
3 Years ago
;