Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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...

share|improve this question

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

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

2 Answers 2

up vote 3 down vote accepted

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
share|improve this answer
cal 2011 > /home/<user name>/folder/filename.txt


cal 2011 > ~/folder/filename.txt
share|improve this answer
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
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 posting your answer, you agree to the privacy policy and terms of service.