Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions

  




 

 

6.2. Usage

>

The greater than symbol is used to send information somewhere (for example a text file)

Example:

cat file1 file2 > file1_and_2.txt

This will concatenate the files together into one big file named "file1_and_2.txt". Note that this will overwrite any existing file.

<

The less than symbol will insert information from somewhere (a text file) as if you typed it yourself. Often used with commands that are designed to get information from standard input only.

For example (using tr):

tr [A-Z] [a-z] < fileName.txt > fileNameNew.txt

The example above would insert the contents of "fileName.txt" into the input of tr and output the results to "fileNameNew.txt".

>>

The >> symbol appends (adds) information to the end of a file or creates one if the file doesn't exist.

<<

The << symbol is sometimes used with commands that use standard input to take information. You simply type << word (where word can be any string) at the end of the command.

The command takes your input until you type "word", which causes the command to terminate and process the input.

Using << is an alternative to using CTRL-D (EOF key), except it uses a string to perform the end-of-file function.

For example type "cat" (with no options...) and it will work on standard input.

To stop entering standard input you would normally hit CTRL-D .

As an alternative you can type "cat << FINISHED", then type what you want.

When you are finished, instead of hitting CTRL-D you could type "FINISHED" and it will end (the word FINISHED will not be recorded).

2>

Redirects error output. For example, to redirect the error output to /dev/null, so you do not see it, simply append this to the end of another command...

For example:

make some_file 2> /dev/null

Runs make on a file and send all error output to /dev/null

|

The "pipe" command allows the output of one command to be sent to the input of another.

For example:

cat file1.txt file2.txt | less

Concatenates the files together, then runs less on them. If you are only going to look at a single file, you would simply use less on the file...

tee Sends output of a program to a file and to standard output. Think of it as a T intersection...it goes two ways.

For example:

ls /home/user | tee my_directories.txt

Lists the files (displays the output on the screen) and sends the output to a file: "my_directories.txt".

&>

Redirects standard output and error output to a specific location.

For example:

make &> /dev/null

Sends both error output and standard output to /dev/null so you won't see anything...

 
 
  Published under the terms of the GNU General Public License Design by Interspire