This was an exercise proposed to us in class' but I didn't get it. What exactly will these commands do?

cd / 
ls -al > $HOME/outputfile.log

I did try it (in Linux) but (apparently) nothing happened at least that I can see. I understand the commands cd /, ls and -al. I also know what $HOME means.

What I am struggling with is the following part:

> $HOME/outputfile.log

As in, what is this supposed to do?

I did ls -al > outputfile.log first and got permission denied, which I also understand. So what is the difference here?

Thanks guys.


You did not say which Operation System. I will assume that it is Gnu/Linux with bash (however it should not matter).

I will not give answer, but will give you help in finding an answer (as it is clear that your goal is to learn).

There are two commands. Look them up.

  • help cd -- it is a shell built in, so you need to use help.
  • man ls -- not a shell built in, so you use man.

looking up >

man bash | less "+/^REDIRECTION"

looking up $HOME

man bash | less "+/^[[:blank:]]+HOME"

looking up $ -- variable expansion

  • Actually, bash is one of the few shells where that command would be incorrect as you need to quote word expansions in the target of redirections there. – Stéphane Chazelas May 10 '20 at 15:00
  • 1
    See info bash redirection and info bash HOME as better ways to get to the documentation (would also work with zsh in place of bash, as that syntax is more zsh-like than bash-like) – Stéphane Chazelas May 10 '20 at 15:02
  • @StéphaneChazelas feel free to patch the answer. – ctrl-alt-delor May 10 '20 at 21:25
  • @StéphaneChazelas I don't grok your first comment. – ctrl-alt-delor May 10 '20 at 21:26
  • In bash, when interactive or when not in POSIX mode, you need to quote that $HOME unless you can guarantee it doesn't contain any character of $IFS or wildcards. IOW, ls -al > $HOME/outputfile.log is zsh syntax but not bash syntax. In bash, the equivalent is ls -al > "$HOME/outputfile.log" or ls -al > ~/outputfile.log. – Stéphane Chazelas May 11 '20 at 6:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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