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?

Luke
  • 1

1 Answers1

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!

rzaaeeff
  • 532