Thursday, July 31, 2008

Advanced Unix Commands

Advanced unix commands


ACCTCOM
See the commands of all users acctcom | tail -20
See the commands of a particual user acctcom -u | tail -20
Show entries for a specific commandpattern acctcom -n | tail -20
Show all entries for commands staring with "l" acctcom -n '^l' | tail -30
Swho the output in reverse order acctom -b | more
AGREP
Find words with possible misspellings (here 2) agrep -2 'macropperswan'
AT
Execute a command once in the future at now + 5 days <>
AWK
Take first column of a file awk '{print $1}'
Take first two colums inverted awk '{print $2,"\t",$1}'
Print sum of first two colums awk '{print $1 + $2}'
Find lines with "money" and print last column awk '/money/ {print $NF}'
Find lines with "money" in second column awk '$2 ~ /money/ {print $0}'
Find lines without "A" at end of 3-rd column awk '$3 !~ /A$/ {print $0}'
For awk programming structures see separate page Per Kistlers Awk page
BASH
Bourne again shell. Best interaktive shell right after zsh
BC
Calculate sin(5) echo 's(5)' | bc -l
BG
Put last stopped job into the background bg
BREAK
Leave the inermost loop (while/until/for) break
CANCEL
Stop a print job allready started cancel ( as found with lpstat -o)
CASE in ESAC
Selective structure in sh/bash/ksh
CC
Compile a file.c cc -o
CHGRP
Change group of a file chgrp
CHOWN
Change owner of a file chown
CMP
Act on the difference of two files cmp ||
COL
Printing the man pages without thousand "^H" man | col -b |
CRONTAB
See your crontab file crontab -l
Edit your crontab file crontab -e
Every monday on 05:10 do /home/fred/foo.ksh 10 5 * * 1 /home/fred/foo.ksh
CRYPT
Encrypt a file with a password crypt password <> cryptfile
Decrypt the above file crypt password <> cleanfile
CSH
Oldest Berkly shell
CUT
Get the hostname field from the last output last | cut -c11-40
DATE
Set the date (root only) date
Special format of date (e.g. month only) date +%m
DF
See the used space of the disks in kB df -k
DIRCMP
Compare two directories dircmp
DTKSH
dtksh is a ksh93 with X11 graphics dtksh
DU
du = diskusage du -ks
ED
Commandline editor. Only used if all else fails ed
EGREP
Grep with "or" egrep '(A|B)'
Exclude a and B egrep -v '(A|B)'
EX
Edit a file from within a shell script ex -s file <g/money/s//cash/
EOF
Edit a file with a script ex -s file <>
EXPR
Calculate modulus expr 10 % 7
Check for string in variable expr $var : 'string'
Show first group of digits in string expr $var : '[^0-9]*\([a-z]*\)'
FG
Put the last stopped job into the foreground fg
FGREP
Find a string which is not a pattern fgrep '*,/.()'
FILE
See the file type (e.g. ascii) file
FIND
Find a file in the whole computer find / -type f -name -print
Find a file pattern find . -type f -name "**" -print
Delete all cores in the system find / -type f -name core -exec /bin/rm -f {} \;
Find all files with a word in them find . -type f -exec grep -l {} \;
Find files modified longer than a month ago find . -type f -ctime +30 -print
Use found files more then once with xargs find . -name "*.c" -print | xargs -i cp {} {}.bak
Don't search in nfs mounted filesystems find . -local ...
Follow the links while searching find . -follow ...
Look for files larger than 1 megabyte find /path -size 1000000c -print
Run find but discard the "permission denied"'s find ... 2>/dev/null ( in sh/bash/ksh only)
Find all manualpage directories find / -type d -print | egrep '.*/(catman|man)$'
Find all directories with write permissions find / -type d -perm -002 -print
GAWK
The gnu version of nawk
GREP
Find patterns in lines of files or stdin grep '[a-z][0-9]'
Find lines without pattern grep -v '^From'
Find files which contain a pattern grep -l '^[cC]' *.f
Count lines with pattern grep -c '[Ss]uccess'
Search while ignoreing case grep -i 'lAbEgF'
Print a line number in front of the line grep -n 'mo.*y'
HINV
Get infos about your host on silicon graphics hinv -v
IF then else ENDIF
Branching structure in csh/tcsh
IF then else FI
Branching structure in sh/bash/ksh if [[ condition ]];then commands;fi
KSH
Korn shell. (ksh88) See Per Kistlers ksh script guide
KSH93
ksh93 with real number arithmetics ksh93/ksh...depends on the system
LINE
Reprint lines until eof (sh/bash/ksh) while line;do :;done
LN
Make a hard link b to file A ln a B
Make a symbolik link b to file A ln -s a B
Romove link B rm B
LP
Print file on default printer lp
Print file on specific printer lp -d
LPSTAT
Show all printers lpstat -a
Check the printer queue lpstat -o
Show defoult printer destination lpstat -d
Show printer status lpstat -p
Show sceduler status lpstat -r
MAKE
Make the first target of a makefile make
Make a specific target of a makefile make
Make according to another file than makefile make -f
Just show what would be done but don't make -n
MKDIR
Make a directory with subdirectories at once mkdir -p //
MOUNT
See what is mounted mount
See what is mounted, but formated mount -p
Mount a cdrom to /cdrom mount /dev/cdrom /cdrom
Mount a diskpartition to /usr mount /dev/dsk/c0t3d0s5 /usr
NAWK
Enhanced version af awk
NL
Number text lines from a file nl -bt -nln
NOHUP
Start a job imune to logouts nohup &
OSVIEW
View system activity on SGI osview
PACK
An old form of compress. Use gzip instead. pack
PASSWD
Change your password passwd
Delete password of a user (as root) passwd -d
Change password of a user (as root) passwd
PASTE
Put single col files into one file with as many cols paste >
PERL
Programming language which can also be used from the commandline or from ksh scripts.
See Per Kitlers perl programing introduction: perl
PR
Format an ascii file for printing (76 lines) pr -l76 -h"title"
Print page formated via vpp (ETH only) pr -l76 -h"title" | vpp -des=rz -dev=printer
RCP
Copy a file from one computer to another rcp :// ://
REGCMP
Compile a regexp from a file regcmp
Entry in the file above (example) varname "^[a-z].*[0-9.*$"
RESET
Reset the terminal after having messed it up reset
RPCINFO
Get portinfo from rpcinfo -p
RSH
Execute a command on a remote computer rsh
RUSER
See who is logged in in the local network rusers
RWHO
Like rusers, but mostly doesn't work
SCRIPT
This logges all which passes the screen script
SED
Substitute a string in a file sed -e 's/fred/john/g'
Substitute a pattern in a file sed -e 's/[0-9]+/number/g'
Change all "X" to red in a html file sed -e 's!X!X!g;
Rename files with suffix .suf1 to files with suffix .suf2
ls -1 | grep '\.suf1$' | sed -e 's/\(.*\.\)suf1/mv & \1suf2/' | sh
Change a to b but only on lines with C sed -e '/C/s/A/B/' >
Delete all lines which contain "you owe me" sed -e '/you owe me/d' >
Have many editing commands in a file sed -f >
SH
Shell. The oldest AT&T shell, which is standard for universal shell scripts. Ksh is it's successor.
SHUTDOWN
Stop the system shutdown -h now
SLEEP
Tell ashell script to pause for 10 seconds sleep 10
SORT
Sort lines of a file alphabetically sort
Sort lines of a file numerically sort -n
Sort and reverse the order sort -r
Sort and take only one of equal lines sort -u
Show the used user ID's from /etc/passwd sort +2n -t: /etc/passwd | cut -d: -f3
SPELL
Check for misspelled words in a file spell
Check, but ignore words from okfile spell +
SPLIT
Split a big file for putting on floppy split -b1m
Put splitters together if their name starts with x cat x* >
STRINGS
Read ascii strings from a binary file strings
STTY
Show the terminal settings stty -a
Change the deletions chatachter to "^H" stty erase "^H"
Do no more show what is typed in scripts stty -echo
Show the typeing again stty echo
SU
Become root with own environment su
Become root with root environment su -
As root become another user su
TAIL
Report certain lines from a growing file tail -f | grep
TAR
Pack together a whole directory tar cvf .tar
Unpack a tar file tar xvf .tar
Unpack and untar a file with normal tar gzip -dc .tar.gz | tar xvf -
Unpack and untar a file with gnutar tar xzvf tar.gz
Set the tape variable in the .cshrc for tar tape=/dev/rmt/0mbn
Put a dir onto the tape tar cv
Retrieve the dir from the tape tar xv
Retrieve only a single file from the tape tar xv
Get table of contents from tape tar t
Copy a directory with links and propper permissions
(cd fromdir && tar -cBf - . ) | ( cd todir && tar -xBf - )
TCSH
Good interaktive shell from Berkly. Only second to bash.
TEE
Put output on screen and append to file who | tee -a >
TEST
Check for a file test -a
Check for beeing root test -O /usr/bin/su
Check for astrin beeing non null test -n "$foo"
Compare two strings numerically test $var1 -gt $var2
In a ksh script one uses "test" indirectly if [[ -a ]];then ...;fi
TIME
See how much time a command needs time
TOUCH
Protect against the the crontab find /myscratch -exec touch {} \;
TR
Replace a with x, b with y and c with z tr '[a-c]' '[x-z]' <> outfile
TRAP
Catch "^C" etc. and execute a subroutine trap "mysub;exit" 0 1 2 15
TRUE
Make a non extisting command to return 0 ln -s /usr/bin/true ranlib
TRUSS
See what system calls a command uses truss > /dev/null
TYPSET
Show the functions which are active typset
TTY
See the device for your terminal tty
ULIMIT
Show the max file size you can write ulimit
UMASK
Show your umask for new files umask
Set a save umask umask 077
UNIQ
Find a line of each equal ones an say how many sort | uniq -c
Find uniq lines sort | uniq -u
UPTIME
Show how long the computer is running uptime
UUENCODE
Encode a file for mailing uuencode decodedname namenow > codedname
UUDECODE
Decode a uuencoded file uudecode
WAIT
Wait for a background job to terminate wait $jobid
VI
The main unix editor vi
A vi introduction on the net: vi-www-page
WC
Count lines in a file wc -l
XARGS
Execute a command for each line from pipe | xargs grep 'pattern' {}
XON
Get an xterm from another computer xon
Get anything from another computer xon
ZSH
Inhanced ksh. But ksh93 and dtksh are now still better.

No comments:

Search

My Blog List