Commands
CUT:
lspv | cut -c 6-7 lists the hdisks numbers (cuts the 6th and 7tn character (disk nubers))
dlnkmgr view -drv | grep -w 00000 | awk '{print $4}' | cut -d . -f 3
--------------------------------------------------------------------------------
EXPR: integer arithmetic
\* multiplication (\ is needed to tell * is not a special character)
/ division
% remainder
+ addition
- substraction
expr \( 6 + 4 \) / 2 5
--------------------------------------------------------------------------------
FIND: recursively searches the directory tree
find / -xdev -type f -name "cor*" -size +10000c -exec ls -l {} \;
/ where to find
-xdev looks only in the given fs
-type f what type to look for (f: file, d: direcory)
-name "cor*" name to look for
-size +10000c search for the given size (+10000c : greater than 10000 character (larger then 10kbyte))
-size +2 search for greater than 1kbyte (bloxk size is 512 byte, that's why +2 is given)
-exec ls -l {} \; what command to execute
({}: it represents each findings and \; is needed at the end of line)
e.g. find /home -xdev -name "*.old" -exec rm {} \;
-mtime -1 file modifocation date is less then 1 day (+1 means older than 1 day)
find . -name '*.ksh' -ok rm {} \; this will ask if the command (rm) should be executed or not (much safer if find is not perfect)
find /etc/rc.d -ls it lists the files and dirs in the given dir
find /tmp/bb -exec awk '/func/ {print FILENAME}' {} \; it will check in /tmp/bb if any files contains the word "func" and list those
--------------------------------------------------------------------------------
GREP: (Global Regular Expression Parser) The grep command searches for the pattern.
grep -i ignore case (small letter or capital)
grep -c displays only a count of matching lines
grep -n shows line number at the beginning of the matching line
grep -v invert the sense of matching, to select non-matching lines
grep -w selects only whole words
grep -l lists the name of the files (once) which contain matching line (grep -l paging00 *)
ps -ef | egrep 'ssh|aix' select lines with ssh and aix
errpt -a|grep -A1 'NAME' selects lines with NAME and shows 1 line after that (A: after, B: before)
--------------------------------------------------------------------------------
HEAD, TAIL:
head filename displays first 10 lines of the file
head -50 filename displays first 50 lines
tail filename displays last 10 lines of the file
tail -50 filename displays last 50 lines
tail +15 filename displays the file starting from the 15th line
tail -f filename used when we are monitoring the file (interactively shows how the file is changing)
--------------------------------------------------------------------------------
LSOF:
NETWORK
-n no host name resolution
-P not converts port numbers to port names
lsof -i show all network connections
lsof -i| grep LISTEN shows what ports are waiting for connections
lsof -i | grep ESTABLISHED shows current active connections
lsof -i tcp list only TCP connections (works with udp as well)
lsof -i :<port> shows all connections of a given port (lsof -i :22 or lsof -i :ssh)
lsof -i @<host> shows connections to a specific host (lsof -i @192.168.1.5)
lsof -i protocol:@ip:port this is the syntax for network findings (protocol: tcp or udp, @ip: any ip address, port: a port number)
lsof -a -u <user> -i shows all network activity of a user (-a combines -u and -i)
USER, FILES, PROCESSES
lsof -u <user> shows what is open for a user (lsof -u oracle)
lsof <file> shows what is using a file (lsof /var/adm/syslog.log)
lsof <directory> shows what pids are using the filesystem (directory) (it can be good if we cannot umount)
lsof +D <directory> shows which file is open by which process in a directory (lsof +D /usr)
(+D will show recurcively the open files, otherwise only device name would be shown)
lsof -N list all NFS files
lsof -c <command> shows files and network connections a command is using (lsof -c ssh)
lsof -p <pid> shows what a proccess ID has open (lsof -p 335545)
-----------------------------
HOW TO FIND WHAT FILES ARE OPENED BY A PID
1.
root@aix20: /root # lsof -p 319660
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ovcd 319660 root 32r VREG 10,5 12153 69705 /usr (/dev/hd2)
(it will show the filesystem and the indode number (69705))
2.
root@aix20: /root # find /usr -inum 69705
/usr/lpp/VV/msg/en_US/sec.cm.client.cat
--------------------------------------------------------------------------------
METACHARACTERS, VARIABLES:
GREP SHELL
single character . ?
multicharacter .* *
character range [x-z] [x-z]
begins a line ^ N/A
ends a line $ N/A
variable N/A $
HOME home directory
$PS1 prompt symbol
set displays the values of all shell variables
--------------------------------------------------------------------------------
RPM:
rpm -qa shows what rpm packages are installed
rpm -ql <package name> shows where the files are installed (rpm -qlp .. shows the absolut paths???)
rpm -q --filesbypkg cdrecord list all the files on installed rpm package
rpm -qf /usr/bin/lynx query a file to find the source rpm package
rpm -qi <package name> list information on an installed rpm package
rpm -qR <package name> list all dependencies on any rpm package
rpm -ivh httpd-2.2.8.aix5.1.rpm install the rpm package
rpm -ivh --force *.rpm
rpm -ivh --force --nodeps <package name> does not check dependency (same can be done with "rpm -Uvh..." for upgrade)
rpm -e <package name> removes the rpm package
rpm -Va shows which files are missing from the RPM database
rpm -Vv <package name> verifies a package
rpm --rebuilddb compress and rebuild the RPM database
/usr/sbin/updtvpkg enables the rpm command to recognize that the libraries have been installed
In
some cases you might get an error about failed dependencies when you
install RPMs on AIX (for example, error: failed dependencies:
libX11.a(shr4.o) is needed by tk-8.3.3-1). Most likely the error occurs
because the rpm command does not recognize the shared library. If the
error occurs, check to see if the X11 libraries are installed in the
directory /usr/lpp/X11/lib. If they are not installed, use the AIX
product media to install them. After you have installed the libraries,
run the above command (updtvpkg). The command enables the rpm command to
recognize that the libraries have been installed.
--------------------------------------------------------------------------------
RSYNC:
Much
like cp, rsync copies files from a source to a destination. Unlike cp,
the source and destination of an rsync operation can be local or remote.
rsync can resume a transfer after interruption; it transfers only those
portions of a file that differ between source and destination; and
rsync can perform entire or incremental backups.
By
default, rsync uses Secure Shell (SSH) as its transport mechanism; you
can reuse your machine aliases and public keys with rsync
rsync -av /tmp/bb_rs30 /tmp/bb it will copy the directory (/tmp/bb_rs30) and its contents under /tmp/bb
rsync -av /tmp/bb_rs30/ /tmp/bb it will copy the contents of the named directory but not the directory itself (check / at the end)
-v option enables verbose messages
-a option (stands for archive), is a shorthand for -rlptgoD:
recurse, copy symbolic links as
symbolic links, preserve permissions, preserve file times,
preserve group, preserve owner, and preserve devices and special files, respectively
rsync -n -av /tmp/bb_rs30/ /tmp/bb -n: previews what will happen but does not move a single byte (it is good for testing)
rsync -av /tmp/bb_rs30/ aix2:/tmp/bb_rs20 it will copy the contents of the given dir to the other host
(assuming the same login name on the remote machine)
--------------------------------------------------------------------------------
SORT:
cat /etc/passwd | sort -t: -n +2
-t: gives the delimeter character (here :, deafult is the space)
-n numerical order
+2 sort by the 3rd column
-r reverse order
df -m | sort -n +3 | egrep '9.%|100%' sorts by the 4th column (%) of the filesstems, which are 90-100% full
cat animals | sort +0.1 sort the file animals by the second character of the first word
ls -lR |sort -nk 5|tail -20 sorts the 20 largest file
lspv | sort -k1.6n list hdisk in numerical order (lspv|sort -tk +1 -n <--it is the same (delimiter is "k")
lspv | sort -k1,1.5 -k1.6n list hdisks then vpaths in numeric order
--------------------------------------------------------------------------------
TAR:
tar -cvf /tmp/file.tar . saves where we are to the given path (-c: create, -v: verbose, -f: file)
tar -cvf conf.tar conf creates conf.tar of the dir conf
tar -xvf /tmp/file.tar extracts the tar file (-x: extract)
tar -xvf -C /home/bb /tmp/file.tar it will extract the tar file to /home/bb
tar -tvf /tmp/file.tar list (verify) the content of a tar file
tar -cf - * | gzip -9 > vmi.tar.gz makes tar and zip wehere we are
tar cvf - openssh5.8p1 | gzip -c > openssh5.8p1.tgz creates tgz in one command
tar: 0511-197 DirectorServer: Cannot write data extracted with the tar command:
A file cannot be larger than the value set by ulimit.
I changed these ulimit settings after that it was OK (dont't forget to logout and login again)
root@bb_lpar: /bb # chuser fsize=-1 fsize_hard=-1 root
root@bb_lpar: /bb # chuser data=-1 data_hard=-1 root
--------------------------------------------------------------------------------
TRUSS:
truss <command> it will show what system calls a command makes
truss -c -p <pid> it will trace a process (-c: counts the system calls rather than displaying them, -p: pid)
truss -d -p <pid> -o
truss -t open lsps -a shows whatis needed for the given command (here lsps -a)
--------------------------------------------------------------------------------
XARGS:
lspv|awk '{print$1}'|xargs it will list the elements in a line separated with space
cat list | xargs -t rm will rm all the files which are in the file list
ls | xargs -t -I {} mv {} {}.old it will rename to .old all the file in the current dir
-t it echoes the constructed command (trace mode) (it is optional)
-I {} insert each line of the ls to that place where the {} symbol appear
lsdev -Cc disk | xargs -n1 rmdev -dl removes all the listed disks
-n1 1 element will be passed each time to xargs (if n2 then the command will be created with 2 elements)
--------------------------------------------------------------------------------
ZIPPING:
gzip-V shows gzip version
gzip file1 zip
gzip -d file1.gz unzip
gzip -9 filename will zip (and remove the file automatically)
gunzip filename unzipping it
gzip -c file > file.gz it creates a zip file but leave the original file as well
> filename after that original file can be emptied
compress file1 the original file will be deleted and a new compressed file will be created with a .Z at the end
zcat file1.Z displays the compressed files (without uncompression)
uncomress file1.Z uncompressing a file (the compressed one will be deleted)
if you receive this:
gunzip SysDir6_2.tar.gz
gunzip: SysDir6_2.tar: File too large
this is because gzip 1.2.4 (or lower gzip versions) need a patch to accept large files, workaround for this problem:
gzip -d -c SysDir6_2.tar.gz| tar xvf -
--------------------------------------------------------------------------------
OTHER:
file <filename> shows the type of a file
diff file1 file2 compares only text files
cmp file1 file2 compares all types of files
dircmp dir1 dir2 compares directories
time cp file1 /home show the time to accomplish the command (godd for performance analysis)
ps $$ shows which shell is in use
echo $SHELL shows the current shell
printenv view environmental variables
cat -vet file shows tabs, enters... as viewable characters
-v displays non-printing characters as visible characters
-t displays tab as ^I
-e displays enter as $
!!! sh -xv <command...> for troubleshooting, if a command fails, you can see where exactly it failed in the command script!!!
(sh -xv exportvg rootvg)
dd if=/dev/zero of=/home/user/bb/4GB_file bs=1m count=4000 it creates a 4GB file
lmktemp <filename> <size_in_bytes> it creates a file with given size
alias dir='ls' creates an alias
unalias dir removes an alias
set - unset
df -g | awk '{sum = sum + $3} END {print sum}' it sums up the fs in gigabyte (by the 3rd column)
for i in `ls -l | grep old | awk '{print $9}'` ; do du -sk $i; done | awk '{sum = sum + $1} END {print sum}'
No comments:
Post a Comment