Friday, May 3, 2013

UNIX commands

To list disk usage
du -sg
du -sk
du -ksd in solaris to find the size of directory.

List all the directory usages in ascending order inside a particular directory in Solaris
du -sk *|sort -n

To get a formatted output on SunOS Solaris
df -F ufs -k
df -F ufs -k awk '{print $1}'
df -F ufs -k awk '{print $2}'
df -F ufs -k awk '{print $3}'
df -F ufs -k awk '{print $4}'
df -F ufs -k awk '{print $5}'
df -F ufs -k awk '{print $6}'

Print lines not containg #
crontab -l awk '!/#/'

Sum the fourth column
ls -lrt *2007*|awk '{ sum+=$5 }END{ print sum }'

Print the lines inside a tag e.g VirtualHost
awk '//' httpsd.conf

Using unix basic calculator
bc
scale=2
3/4
.75
^D to exit

Script to decrease the numeric contents of a file
var=`cat sample.txt`;
echo $var-1|bc > sample.txt

To list all processes that are using a file  which has been deleted from a given file system(e.g. /usr) in AIX
fuser -d /usr

Below command to add two files in parallel line by line -w 200 adjusts the default length of each line to 200
sdiff -w 200 1.txt 2.txt > 3.txt

To find all directories
find . -type d

find directories owned by a user
find - -type d -user username

Creating directories, recursively
mkdir -p /1/2/3

To list all the commands that are given permission to u by root
sudo -l

Changing the comment of a user
sudo usermod -c "username,#CUST#,ABC,Systems Administrator,F" username
Getting the error "UX: usermod: ERROR: username is in use. Cannot change it."
Then you can manually edit the /etc/passwd if you have permissions either using sudo or root for changing comments.

How to read mails for a user in UNIX ?
mailx
type ? for help
type d * at command prompt to clear all the mails .
This is useful in order to clean up /var (will perform clean up of /var/mail)

Recursive grep
find . -type f -exec grep HOST {} \;

Delete files with whose name begins with -
rm ./-badfile

find files accessed in last one day
find . -atime -1
find files not accessed in last one day
find . -atime +1

Display all the process that are currently using that file.
fuser filename

To know the architecture type on solaris
isainfo -kv
E.g.isainfo -kv
64-bit sparcv9 kernel modules

To know the default permissions of current directory
ls -lad
ls -ld

Display the system configuration like RAM etc.
prtconf on Sun Solaris
lsconf on AIX

Perfomance monitoring commands
vmstat
iostat
top on solaris and linux
topas on AIX
sar
netstat

To display the operation system name and version
uname
uname -a

What is /dev ?
The /dev directory contains the special device files for all the devices

pwck , grpck  are used for checking discrepancies in group and password files of solaris box.
The errors may not be that significant and they can be ignored even.

What are the files associated with name resolution on UNIX like systems ?
/etc/hosts
/etc/nsswitch.conf
/etc/resolv.conf

Where are Solaris System logs located ?
/var/adm/messages or you can run  dmesg command to view the logs.
/etc/syslog.conf has the System logs configuration.
/var/crash/  .Its not a readable file and you need Solaris crash analysis tool
 /var/log/syslog

No comments: