Oli's answer already provides great deal of explanation. My purpose in this answer is to provide several practical examples.
Input redirection with [command] < file
The <
redirection serves to send output from a file to a command. If you can imagine , the virtual wire is unplugged from keyboard and plugged to file. It works well when you don't want to use pipes, or can't use pipes.
For instance,suppose I have a list of files. I want to run some kind of test on each filename (maybe check if file exists, or is a specific file).
while read FILENAME; do [ -d $FILENAME ] && echo $FILENAME;done < fileList.txt
Normally such command as read
takes input from STDIN , but using <
operator we make it take input from file.
Here document <<
This is very useful when you want to operate on the output of another command or multiple commands, but do not want to create a file.
In my answer to What's the difference between <<, <<< and < < in bash?, I have showed two simple examples wc < <(echo bar;echo foo)
and diff <(ls /bin) <(ls /usr/bin)
. The last one is especially useful - we're comparing outputs of two commands without ever creating a file for storing the data to be compared.
Redirection with COMMAND1 > >(COMMAND2)
This one is equivalent to piping.
xieerqi@eagle:~$ df > >(grep "dev" )
xieerqi@eagle:~$ /dev/sda1 115247656 83004376 26365932 76% /
udev 2914492 4 2914488 1% /dev
As shown in Greg's wiki , this can be used for giving same input
to multiple commands
some_command | tee >(grep A > A.out) >(grep B > B.out) >(grep C > C.out) > /dev/null
<<TOKEN
,<<<"string"
seems pretty useless right? because the job of later one can be done by former one – Alex Jones Nov 12 '15 at 11:42<<<
is called Here Strings which is a short form of Here Doc..You don't need explicitTOKEN
in<<<
..<<<
is basically used for one-liners.. – heemayl Nov 12 '15 at 11:44