AIX 5L Basics (Unit 13) – AIX Utilities – Part 2

grep – search for lines within files matching pattern
grep [options] pattern [file1 file2…]
grep pattern
grep option pattern file1

grep ‘regular_expression’ file

Valid Metacharacters:
. – Any single character
* – Zero or more occurrencess of the preceeding character
[aA] – Enumeration: a or A
[a-f] – Any ONE of the characters in range a-f
^a – Any lines that start with ‘a’
z$ – Any lines that end with ‘z’

ps -ef | grep wltest
grep ‘^B’ phone1 – starts with B
grep ‘5$’ phone1 – ends with 5
grep ‘^[DH]’ phone1 – starts with D or H
grep ‘^A .*o$’ phone1 – starts with A, any # of chars, ends with o

grep Options:
-v – print lines that do not match
-c – print only a count of matching lines
-l – print only the names of the files with matching lines
-n – number the matching lines
-i – ignore the case of the letters
-w – do a whole word search

fgrep – fast grep, only fixed strings, no wild cards
egrep – extended grep, allows for multiple patterns
egrep ‘800|817’ phone1 – | means ‘or’

Sort – sort lines and writes to standard output
sort [-t delimiter] [+field[.column]] [options]
-d – sorts in directory order, only letters, digits, spaces considered
-r – reverse the order of the sort
-n – sorts numberic fields in arithmetic value
-l – tells sort what character separates fields

cat animals

sort animals – sorts by the first letter of each line
cat animals | sort +0.1 – field 0 (first word), column 1 (second letter)
cat animals | sort -t. -n +1 – delimiter is period ‘.’, numeric order, 2nd field

du – disk usage command
du /home | sort -rn

head -5 filename – shows first 5 lines of the file
tail -20 filename – shows last 20 lines of the file
tail +20 filename – shows lines starting at line 20 to the end of file

Transfering DOS data files:
dosdir -l – list contents of DOS diskette

tn – login to a remote host
tn hostname
tn ipaddress

FTP – File Transfer Protocol:
Transfer files between hosts

ftp hostname

cd remotedir
dir ls -l
get RemoteFile [LocalFile]
put LocalFile {RemoteFile]

Backup/Restore Files:
Backup Files: -c
tar -cvf /dev/rmt0 . – the period ‘.’ means current directory
tar -cvf /dev/fd0 .
tar -cvf /tmp/file.tar .

Restore Files: -x
tar -xvf /dev/rmt0
tar -xvf/dev/fd0
tar -xvf /tmp/file.tar

-v – verbose
-f – copy files to device
-c – backup
-x – restore
-t – show contents of archive file

tar -tvf /dev/rmt0 – -t means to show content of archive file

Note: You can selectively restore files by name. Relative path verses specific path makes a difference when backing up and restoring files.
Use the full path inorder to restore to the same directory.

Leave a Reply

Your email address will not be published. Required fields are marked *