I did a search and didn't find what I was looking for. I finally found a beginners UNIX book that I like. I am going through some examples and I notice output is generated in the home folder. I am using OS X. I keep all my code on my desktop in a folder called code for all my programming assignments and practice. C,C++...etc.

So my question is, how do I do a file redirect from the terminal to create a file in a specific folder? If I type:

cal 2011 > cal2011

it creates a file called cal2011 to my home folder. How do I write at the terminal without changing directories (the initial command prompt) to save it to:


Thank you for the help. I am still new at this...

migrated from stackoverflow.com Jul 6 '11 at 11:03

This question came from our site for professional and enthusiast programmers.


Assuming you are in your homedir, the relative path works.

cal 2011 > desktop/code/unix/cal2011

If you aren't, you can use the ~ to denote your homedir

cal 2011 > ~/desktop/code/unix/cal2011
  • lil late to the party but thank you. – J-e-L-L-o Nov 23 '14 at 8:52
cal 2011 > /home/<user name>/folder/filename.txt


cal 2011 > ~/folder/filename.txt
  • That won't work. You can't redirect to a directory... you need a filename like ~/folder/some_file. – Mark Jul 5 '11 at 23:13
  • That's obhious ... right; I was just showing how can we redirect to any specified folder. Anyways, edited. – Rahul Jul 5 '11 at 23:23
  • 2
    Not all Unix-based systems (e.g., Mac OS X, used by the OP) place users' home directories in /home/username, and so using a tilde is far more portable. – jwodder Jul 6 '11 at 0:15

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.