I just used a command ls -l > ~/ls_output in my /usr/bin directory and I'm not sure what happened. The terminal accepted my command but I don't know what happened to the output or where it went. I think I may have redirected the output to a new directory called ls_output but I'm not sure and I'm also unclear on how ~ works in Bash.

Any advice?


1 Answer 1


~ expands to $HOME, your home directory, such as /home/justin or /home/muru.

So ls -l > ~/ls_output will create a file in your home directory, redirecting the output to the file at ~/ls_output (not a directory), creating a new file if necessary and raising an error if it can't.

Do ls -l ~/ls_output to verify that the file was created.

Do cat ~/ls_output to see the contents.

  • Once again muru, I really appreciate the help! I just tried "cat ~/ls_output" and was able to view the contents. However when I try to see this file in a list (just to verify) using my "ls" command in the current directory, I can't seem to find it. I created this file in my "/usr/bin" directory, so shouldn't it be in the "ls" list somewhere?
    – Justin
    Sep 21, 2014 at 20:42
  • @Justin you ran the command in /usr/bin, but as I say in the second sentence, the file is created in your home directory (the ~/ls_output expands to /home/justin/ls_output and the full path is used). You will see it in the ls output if you do ls ~.
    – muru
    Sep 21, 2014 at 20:44
  • Ok, I think I'm following you. Does the "~" and "/" cause it to be created there?
    – Justin
    Sep 21, 2014 at 20:45
  • @Justin yes, because that specifies the path of the target file. Without a path and just a file name, the current directory will be used.
    – muru
    Sep 21, 2014 at 20:49

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.