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

4 Answers 4

up vote 48 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 append to an existing file you need to use >>.

share|improve this answer
If the option noclobber is set, then >| will override and allow clobbering the file. –  bdowning Apr 9 at 16:52

> 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 Apr 3 at 16:34
Updated my answer, thanks for the clarifications. –  Josh Jolly Apr 3 at 16:48
@HaukeLaging noclobber isn't just a bashism. It's part of POSIX –  kojiro Apr 3 at 17:16

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
Very nice quick reference list, but doesn't <<- remove leading tabs and spaces? –  iconoclast Jun 22 at 18:21
@iconoclast, nope, definitely just tabs. –  Graeme Jun 22 at 19:24

> 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

<< a here document

share|improve this answer
<< is a here document –  Graeme Apr 5 at 8:35
@ Graeme I edited my answer. Thank you for the help –  les Apr 7 at 20:01

protected by goldilocks Apr 5 at 13:53

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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