0

I am starting learning bash syntax and I have a some problems trying to write pipe commands with xargs functions. E.g, when I try ls -lah ~ > home.txt | xargs head nothing happends, but then, I tried to figure out if the problem is with pipes or the std1 to home.txt. So I tried this instead: ls -lah ~ home.txt head home.txt and it works (as i thought the other function would do). So I want to know if there is an option to do that in only one command using pipes.

  • The output of `ls` is being redirected to `home.txt`, so there is nothing to pipe to `xargs`. – Biffen Feb 23 '21 at 13:42
  • It's not entirely clear what you are asking. Are you asking how to redirect the output of a command to *both* a file **and** a different command at the same time? – Quentin Feb 23 '21 at 13:42
  • `is an option to do that in` Do "that" - what exactly? You want to list files in home directory with permissions and then output some first lines from `home.txt`, these sound like two separate tasks to be run by two separate programs - one for listing files, the other for printing lines in file. – KamilCuk Feb 23 '21 at 13:45
  • Okey @Quentin. It was that, so I figured out xargs was not the appropiate command. Instead I used tee to write the stdout to both and it works now. Thank you for the help – alberto tokos Feb 23 '21 at 13:55

0 Answers0