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.
> 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
In order to append to an existing file you need to use
> 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.
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'
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.
bash you also have:
<<< - here string, a one line here file. Eg <<<"foo bar"
> 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
protected by goldilocks Apr 5 '14 at 13:53
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?