Reputation: 5924
I have been using this command to make a file "results" with the output of the command "ls" in the sorted manner.
ls | sort | < results
But,I have find out that the file "results" is empty even though the "ls" command shows many files and folders.
Can some please explain the fault in using this command to get the desired result.
Upvotes: 0
Views: 143
Reputation: 31
You got the redirection wrong, as per the other answers you need:
ls | sort > results
And, might I ask, why are you using sort
? ls
already sorts by name. If you just want the results in one column you can use:
ls -1 > results
You can also sort by timestamp among other options see man ls
:
ls -1t
Or reverse sort any results:
ls -1tr
Upvotes: 1
Reputation: 6064
Use this:
ls | sort > results
<
is for input redirection, whereas you want the output to be redirected, ie, use >
. For more info on I/O redirection, read this.
Upvotes: 1
Reputation: 40232
Your redirection is in the wrong direction, use >
instead of <
. Also, you don't need the pipe after sort
. try this:
ls | sort > results
Upvotes: 2