Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

desktop/code/unix

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.

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

OR

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .