Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I was trying to find how to pass some text to a file without overwriting what's there already using the > command and I realised I don't know what it's called. Searching for right arrow or right chevron or more than command didn't show up anything. I've always just called it pass to.

share|improve this question
add comment

4 Answers

up vote 40 down vote accepted

> is not a command but a file descriptor redirection. This means that the shell parses this assignment, removes it from the command line and changes the environment for the new process in which it is started. The new process does not notice this part of the command line. That's the reason why you can put it everywhere: At the beginning, at the end or in between.

Look for the REDIRECTION block in man bash.

In order to add to an existing file you need >>.

share|improve this answer
add comment

> is a redirection operator. Note that using > to redirect to a regular file will overwrite what is already there, unless noclobber is set. >> will append to the end of the file.

share|improve this answer
    
And it doesn't overwrite if noclobber has been set (bash). –  Hauke Laging 2 days ago
    
Updated my answer, thanks for the clarifications. –  Josh Jolly 2 days ago
5  
@HaukeLaging noclobber isn't just a bashism. It's part of POSIX –  kojiro 2 days ago
add comment

> redirects output to a file (or device) overwriting anything already existing there

>> redirects output to a file (or device) appending to anything already existing there

< directs data from a file (or device) to a program or device

<< directs new data from a file (or device) to a program or device

share|improve this answer
1  
<< is a here document –  Graeme 15 hours ago
add comment

As other people have answered, > is not a command, but rather a redirect operator. However, the term 'redirection operator' doesn't specifically refer to the >, but a number of different possible redirection operators. The dash man page lists the following as redirection operators:

 < > >| << >> <& >& <<- <>

I'm not sure there is a valid individual name for each one. Maybe if you dig through some old shell manuals you will find something interesting. This source, correct or incorrect, certainly has a go at naming some of them:

>  - 'output redirection operator'
<  - 'input redirection operator'
>> - 'output append operator'

But also:

2> - 'standard error redirection operator'

However I don't think this is really correct since the 2 is technically an argument rather than part of the operator.

A quick reference (in case you don't recognise any of the ones above):

>   - redirect output stream to a file, eg >somefile (for stdout) or 2>somefile
>|  - as above but overwrite the file even if the noclobber shell option is set
>>  - append output stream to file
<   - redirect input stream from file, n defaults to 0 for stdin
<>  - open file for reading and writing on stdin
>&  - redirect output stream to another stream (eg >&1) or close with - (eg 2>&-)
<<  - here document - see http://en.wikipedia.org/wiki/Here_document
<<- - here document with leading tabs removed.

In bash you also have:

<<< - here string, a one line here file. Eg <<<"foo bar"
share|improve this answer
add comment

protected by TAFKA 'goldilocks' 10 hours ago

This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.

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