Today, the way in which commands are executed by the UNIX shells can be
summarized as follows:
- The shell reads a command line from the terminal.
- It creates a child process with fork().
- The child process uses exec() to call in the command from a file.
- Meanwhile, the parent shell uses wait() to wait for the child (command) process to terminate by calling exit.
- The parent shell goes back to step 1.
General Utilities:
General Applications:
awk - pattern scanning and text processing language
cut - remove sections from each line of files
tr - translate or delete characters
uniq - remove duplicate lines from a sorted file
wc - print the number of newlines, words, and bytes in files
sed - is a stream editor. A stream editor is used to perform basic text
transformations on an input stream (a file or input from a pipeline).
while in some ways similar to an editor which permits scripted edits
(such as ed), sed works by making only one pass over the input(s), and
is consequently more efficient. But it is sed's ability to filter text
in a pipeline which particularly distinguishes it from other types of
editors.
tail:
tty|tail -c2
1
awk:
ls -ld /home/* | grep drwxr-x | awk '{print $1 "\t" $3}'
ls -ld /home/* | grep drwxr-x | awk '{print $3}' > open.users &
grep:
$(grep -v EXPR) opposite behavior (don't print if)
grep -v "denied"
cut:
echo hello world | cut -c1
h
echo hello world | cut -c1-5
hello
df -h | grep /dev/hda1 | cut -c 40-43
100%
echo file.txt|cut -d"." -f1
file
echo file.txt|cut -d"." -f2
txt
wc:
users=$(/bin/netstat -t 2>/dev/null | /bin/grep :22 | /usr/bin/wc -l)
IP=`/sbin/ifconfig "$INT"|awk '/inet addr/ {gsub(".*:","",$2); print $2}'`
IP=$(echo "$INT"|sed -e 's/^[^:]*://' -e 's/[ ].*//')
PPPIP=`/sbin/ifconfig $PPPIF|awk '/inet addr/ {gsub(".*:","",$2); print $2}'`
PPPPE=`/sbin/ifconfig $PPPIF|awk '/inet addr/ {gsub(".*:","",$3); print $3}'`
PPPMA=`/sbin/ifconfig $PPPIF|awk '/inet addr/ {gsub(".*:","",$4); print $4}'`
PPPRX=`/sbin/ifconfig $PPPIF|awk '/RX packet/ {gsub(".*:","",$2); print $2}'`
PPPTX=`/sbin/ifconfig $PPPIF|awk '/TX packet/ {gsub(".*:","",$2); print $2}'`
--------------------------------------------------------------------------------
NAME
cut - remove sections from each line of files
SYNOPSIS
cut [OPTION]... [FILE]...
DESCRIPTION
Print selected parts of lines from each FILE to standard output.
Mandatory arguments to long options are mandatory for short options
too.
-b, --bytes=LIST
output only these bytes
-c, --characters=LIST
output only these characters
-d, --delimiter=DELIM
use DELIM instead of TAB for field delimiter
-f, --fields=LIST
output only these fields; also print any line that contains no
delimiter character, unless the -s option is specified
-n (ignored)
-s, --only-delimited
do not print lines not containing delimiters
--------------------------------------------------------------------------------
NAME
wc - print the number of newlines, words, and bytes in files
SYNOPSIS
wc [OPTION]... [FILE]...
DESCRIPTION
Print newline, word, and byte counts for each FILE, and a total line if
more than one FILE is specified. With no FILE, or when FILE is -, read
standard input.
-c, --bytes
print the byte counts
-m, --chars
print the character counts
-l, --lines
print the newline counts
-L, --max-line-length
print the length of the longest line
-w, --words
print the word counts