RSS Feed

Tag Archives: RHCE

sed & awk



1. Field/Column processor

2. Supports egrep-compatible (POSIX) RegExes

3. Can return full lines like grep

4. Awk runs 3 steps:

a. BEGIN – optional

b. Body, where the main action(s) take place

c. END – optional

5. Multiple body actions can be executed by separating them using semicolons. e.g. ‘{ print $1; print $2 }’

6. Awk, auto-loops through input stream, regardless of the source of the stream. e.g. STDIN, Pipe, File


1. awk ‘/optional_match/ { action }’ file_name | Pipe

2. awk ‘{ print $1 }’ grep1.txt print 1st column

Note: Use single quotes with awk, to avoid shell interpolation of awk’s variables

3. awk ‘{ print $1,$2 }’ grep1.txt

Note: Default input and output field separators is whitespace

4. awk ‘/linux/ { print } ‘ grep1.txt – this will print ALL lines containing ‘linux’

5. awk ‘{ if ($2 ~ /Linux/) print}’ grep1.txt print if colmun 2 = Linux ; awk ‘{if ($1 ~ /ali/) print $1,$2,$3 }’ /etc/passwd

6. awk ‘{ if ($2 ~ /8/) print }’ /var/log/messages – this will print the entire line for log items for the 8th

7. awk ‘{ print $3 }’ /var/log/messages | awk -F: ‘{ print $1}’

Sed – Stream Editor


1. Faciliates automated text editing

2. Supports RegExes (POSIX)

3. Like Awk, supports scripting using ‘-F’ option

4. Supports input via: STDIN, pipe, file


1. sed [options] ‘instruction[s]’ file[s]

2. sed -n ‘1p’ grep1.txt – prints the first line of the file

3. sed -n ‘1,5p’ grep1.txt – prints the first 5 lines of the file

4. sed -n ‘$p’ grep1.txt – prints the last line of the file

5. sed -n ‘1,3!p’ grep1.txt – prints ALL but lines 1-3

6. sed -n ‘/linux/p’ grep1.txt – prints lines with ‘linux’

7. sed -e ‘/^$/d’ grep1.txt – deletes blank lines from the document

8. sed -e ‘/^$/d’ grep1.txt > sed1.txt – deletes blank lines from the document ‘grep1.txt’ and creates ‘sed1.txt’

9. sed -ne ‘s/search/replace/p’ sed1.txt

10. sed -ne ‘s/linux/unix/p’ sed1.txt

11. sed -i.bak -e ‘s/3/4’ sed1.txt – this backs up the original file and creates a new ‘sed1.txt’ with the modifications indicated in the command

Note: Generally, to create new files, use output redirection, instead of allowing sed to write to STDOUT

Note: Sed applies each instruction to each line



1. The ability to parse lines based on text and/or RegExes

2. Post-processor

3. Searches case-sensitively, by default

4. Searches for the text anywhere on the line


1. grep ‘linux’ grep1.txt

2. grep -i ‘linux’ grep1.txt – case-insensitive search

3. grep ‘^linux’ grep1.txt – uses ‘^’ anchor to anchor searches at the beginning of lines

4. grep -i ‘^linux’ grep1.txt

5. grep -i ‘linux$’ grep1.txt – uses ‘$’ anchor to anchor searches at the end of lines

Note: Anchors are RegEx characters (meta-characters). They’re used to match at the beginning and end of lines

6. grep ‘[0-9]’ grep1.txt – returns lines containing at least 1 number

7. grep ‘[a-z]?’ grep1.txt

8. rpm -qa | grep grep – searches the package database for programs named ‘grep’

9. rpm -qa | grep -i xorg | wc -l – returns the number of pacakges with ‘xorg’ in their names

10. grep sshd messages

11. grep -v sshd messages – performs and inverted search (all but ‘sshd’ entries will be returned)

12. grep -v sshd messages | grep -v gconfd

13. grep -C 2 sshd messages – returns 2 lines, above and below matching line

14-. grep -c 2 sshd messages – returns count of lines

Note: Most, if not all, Linux programs log linearly, which means one line after another, from the earliest to the current

Note: Use single or double quotes to specify RegExes

Also, execute ‘grep’ using ‘egrep’ when RegExes are being used

Tar, Gzip, Bzip2, Zip


1. Compression utilities (gzip, bzip2, zip)

2. File rollers (the ability to represent many files as one)



1. gzip – compresses/decompresses files

2. gunzip – decompresses gzip files


1. compress ‘1million.txt’ file using gzip

a. gzip -c 1million.txt > 1million.txt.gz

Note: gzip auto-dumps to STDOUT, by default

b. gzip -l 1million.txt.gz – returns status information

c. gunzip 1million.txt.gz – dumps to file, and removes compressed version

d. gzip -d 1million.txt.gz

e. zcat 1million.txt.gz – dumps the contents to STDOUT zcat file.gz > file2.txt

f. less 1million.txt.gzip – dumps the contents of gzip files to STDOUT

Bzip2: better compress

  1. bzip2 -c 1million.txt > 1million.txt.bz2

Note: Bzip2 tends to outperform gzip on larger files

2. bunzip2 1million.txt.bz2

3. bzip2 -d 1million.txt.bz2

4. bzcat 1million.txt.bz2 – dumps contents to STDOUT

5. less 1million.txt.bz2 – also dumps the contents to STDOUT

Zip & unzip:

1. zip path/ – general usage

2. zip 1million.txt

Note: zip differs slight from gzip and bzip2 in that the destination file (resultant zip file) is specified before the source

  1. unzip

Tar & Gzip/Bzip2:

1. tar -cvf filename.tar path/ – creates a non-compressed archive

  1. tar -cvf 1million.txt.tar 1million.txt

Note: tar, requires a small overhead for itself in each file

3. tar -czvf 1million.txt.tar.gz 1million.txt – creates, tar/gzip document

4. tar -cjvf 1million.txt.tar.bz2 1million.txt – creates, tar/bzip2 document

  1. tar -tzvf display archive content
  2. tar -xzvf extract archive content

6. tar -cjvf 1million.txt.tar.bz2 1million.txt testRH5/- creates, tar/bzip2 document for the text file and ‘testRH5’ directory tree

Linux Redirection & Pipes

Linux Redirection & Pipes


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


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


1. tty – reveals the current terminal

2. whoami – reveals the currently logged-in user

3. which – reveals where in the search path a program is located

4. echo – prints to the screen

a. echo $PATH – dumps the current path to STDOUT

b. echo $PWD – dumps ths contents of the $PWD variable

c. echo $OLDPWD – dumps the most recently visited directory

5. set – prints and optionally sets shell variables

6. clear – clears the screen or terminal

7. reset – resets the screen buffer

8. history – reveals your command history

a. !690 – executes the 690th command in our history

b. command history is maintained on a per-user basis via:


~ = users’s $HOME directory in the BASH shell

9. pwd – prints the working directory

10. cd – changes directory to desired directory

a. ‘cd ‘ with no options changes to the $HOME directory

b. ‘cd ~’ changes to the $HOME directory

c. ‘cd /’ changes to the root of the file system

d. ‘cd Desktop/’ changes us to the relative directory ‘Desktop’

e. ‘cd ..’ changes us one-level up in the directory tree

f. ‘cd ../..’ changes us two-levels up in the directory tree

11. Arrow keys (up and down) navigates through your command history

12. BASH supports tab completion:

a. type unique characters in the command and press ‘Tab’ key

13. You can copy and paste in GNOME terminal windows using:

a. left button to block

b. right button to paste OR Ctrl-Shift-v to paste

14. ls – lists files and directories

a. ls / – lists the contents of the ‘/’ mount point

b. ls -l – lists the contents of a directory in long format:

Includes: permissions, links, ownership, size, date, name

c. ls -ld /etc – lists properties of the directory ‘/etc’, NOT the contents of ‘/etc’

d. ls -ltr – sorts chronologically from older to newer (bottom)

e. ls –help – returns possible usage information

f. ls -a – reveals hidden files. e.g. ‘.bash_history’

Note: files/directories prefixed with ‘.’ are hidden. e.g. ‘.bash_history’

15. cat – catenates files

a. cat 123.txt – dumps the contents of ‘123.txt’ to STDOUT

b. cat 123.txt 456.txt dumps both files to STDOUT

c. cat 123.txt 456.txt > 123456.txt – creates new catenated file

16. mkdir – creates a new directory

a. mkdir testRH5 – creates a ‘testRH5’ directory

17. cp – copies files

a. cp 123.txt testRH5/

By default, ‘cp’ does NOT preserve the original modification time

b. cp -v 456.txt testRH5/

18. mv – moves files

a. mv 123456.txt testRH5/ – moves the file, preserving timestamp

19. rm – removes files/directories

a. rm 123.txt

b. rm -rf 456.txt – removes recursively and enforces

20. touch – creates blank file/updates timestamp

a. touch test.txt – will create a zero-byte file, if it doesn’t exist

b. touch 123456.txt – will update the timestamp

c. touch -t 200801091530 123456.txt – changes timestamp

21. stat – reveals statistics of files

a. stat 123456.txt – reveals full attributes of the file

22. find – finds files using search patterns

a. find / -name ‘fstab’

Note: ‘find’ can search for fields returned by the ‘stat’ command

23. alias – returns/sets aliases for commands

a. alias – dumps current aliases

b. alias copy=’cp -v’

install linux useing FTP


1. Create FTP user account on FTP server

a. ‘useradd -s [shell]/bin/false –d [home] /srv/ linuxinstall’

b. ‘passwd linuxinstall’

2. Confirm FTP connectivity as the user ‘linuxinstall’

3. Reboot server with ‘boot.iso’ CD and type ‘linux askmethod’

Kickstart Configurator

Kickstart Configurator


1. Hands-free, automated installation

2. Scripted installation

3. Script can be used on multiple systems

Note: ‘system-config-kickstart’ is NOT installed by default


1. Open previously created ‘anaconda-ks.cfg’ file and modify if you need to

2. Define partitions accordingly

3. Confirm settings

4. Publish the ‘ks.cfg’ file to HTTP server

5. Install server using the following at the main menu:

‘linux ks=’

Note: The following can be used to boot a kickstart installation:

1. Boot.iso CD-ROM

2. First CD-ROM of the RH5 installation set

3. The DVD-ROM of the RH5 installation set

4. USB Pen/Stick – diskboot.img (use dd)