0

what does this command do if it was executed in my current working directory that has files in it?

ls 2> result

I think whatever ls writes will be redirected to the result file?

Is that correct and will it redirect everything for stderr and stdout? Or only stderr?

marked as duplicate by jasonwryan, John WH Smith, Stephen Kitt, taliezin, don_crissti Jun 5 '15 at 9:25

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

ls command does listing of given directory. Only ls lists current directory's contents. > and 2> are IO Redirection tools. > is used to redirect stdout - standard output. 2> is for stderr - standard error. So:

user@linux:~$ ls 2> result

will redirect errors of ls command to file named result. To redirect both (error and output), you need to use:

user@linux:~$ ls >>result 2>&1

It will redirect and append stdout and stderr to that file.

Good luck!

Not the answer you're looking for? Browse other questions tagged or ask your own question.