Is it possible to redirect output of a file to ls.
Example: file has a / in it and I want to direct that to ls to get the content of the / directory. When I try ls < file this does not work
Redirect file to ls
195 Views Asked by Chris At
3
You can use
xargsor command substitution to achieve this.Use xargs
The key is knowledge of the xargs command.
If you have a list of files in a file called
files_to_change, you can print them with the following one liner:Use command substitution
An alternate method is to use command substitution. This works the same as above.
Two different one-liners, using different syntax:
It won't matter if they are files or directories, and you can run any command on them.
If the contents of
file_to_changewas:cat files_to_change | xargs lsandls $(cat files_to_change)would be equivalent to running:The output on the console should be what you want.