RSS Feed

Linux Redirection & Pipes


Linux Redirection & Pipes

Features:

1. Ability to control input and output

Input redirection ‘<‘:

1. cat < 123.txt

Note: Use input redirection when program does NOT default to file as input

Output redirection ‘>’:

1. cat 123.txt > onetwothree.txt

Note: Default nature is to:

1. Clobber the target file

2. Populate with information from input stream

Append redirection ‘>>’:

1. cat 123.txt >> numbers.txt – creates ‘numbers.txt’ if it doesn’t exist, or appends if it does

  1. cat 456.txt >> numbers.txt

Pipes ‘|’:

Features: Connects the output stream of one command to the input stream of a subsequent command

1. cat 123.txt | sort

2. cat 456.txt 123.txt | sort

3. cat 456.txt 123.txt | sort | grep 3

Command Chaining

Features:

1. Permits the execution of multiple commands in sequence

2. Also permits execution based on the success or failure of a previous command

1. cat 123.txt ; ls -l – this runs first command, then second command without regards for exit status of the first command

2. cat 123.txt && ls -l – this runs second command, if first command is successful

3. cat 1234.txt && ls -l

4. cat 123.txt || ls -l – this runs second command, if first command fails

24. more|less – paginators, which display text one-page @ a time

1. more /etc/fstab

2. less 1thousand.txt

25. seq – echoes a sequence of numbers

a. seq 1000 > 1thousand.txt – creates a file with numbers 1-1000

26. su – switches users

a. su – with no options attempts to log in as ‘root’

27. head – displays opening lines of text files

a. head /var/log/messages

28. tail – displays the closing lines of text files

a. tail /var/log/messages

29. wc – counts words and optionally lines of text files

a. wc -l /var/log/messages

b. wc -l 123.txt

30. file – determines file type

a. file /var/log/messages

Advertisements

About Ali abdo

Ali 32 years old from Egypt working as system engineer riding motorcycle to Support and develop Egyptian tourism, spread motorcycling.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: