Useful Unix commands
To search text in files and all subdirectories
find [directory] -name [files] | xargs grep [text to search for]
Example to find “insert” in the odb directory (search all files in that directory):
find odb -name “*” | xargs grep “insert”
Run job in batch now
at -s now < thejob.sh
List users in group
getent group <goupname>
or simply vi /etc/group to view groups and members
or if logged in as the user, simply enter “id”
Show current process active
ps -efa
Show process information
psrinfo -v
Show who you are currently logged in as
/usr/ucb/whoami
Show who you initially logged in as
who am i
Show version of unix
uname -a
Display System Configuration
sysdef
or
prtconf
Print VTOC
prtvtoc /dev/dsk/c0t0d0s0
Query Disk space
df -k disk space in kilobytes
du -sk disk space summary in kilobytes
Remove all files and sub-directories
rm -r *
Move all files from one directory to another using tar pipe
from directory /var
mkdir /var1
cd /var
tar cf – . | (cd /var1 && tar xBf -)
Directory compare (don’t show files that are the same)
dircmp -s /var /var1
Give User execute permission on a file
chomod u+x filename gives execute permission to the owner.
Find command to find in current directory and sub directory
find . -name “dbmslogmnr.sql” -print
DATE Command
date mmddHHMM[[cc]yy]
example “date 022610221998”
Get DATE from another unix box
rdate pluto
Find Command for certain size files
find . -size +10000c
This example say find all the file > 10000 bytes.
Find command to find a word in the directory and sub directory
find . -exec grep -ls pkzip {} \;
Commands to take tar backups
tar -cvf /dev/rmt/0 /usr /var /lib [Taking into tape ]
tar -cvf backup_file.tar /usr /var /lib [ Taking disk image]
tar -xvf filename.tar [ Restore contents of a tar file ]
List contents of tar backup
tar -tvf /dev/rmt/0 [ List contents of a tar tape ]
tar -tvf filename.tar [ List contents of a tar file ]
Bind a process to processor
pbind –b processor_no process_id
Find out total RAM installed on your machine
$prtconf |grep size
Find no. of processors installed on your sun box and processing speed
Ans: $psrinfo –v
Find out how many disks are available on your system
$ format (for sysadmins)
$ iostat –E (for users – count only the disks which has disk size correctly)
Commands to shutdown the system
shutdown, init , halt, reboot
Show type of file system
df -n
Process info and manipulation
pgrep, pkill, prstat -a
Processor information and more
mpstat, prtdiag, psrinfo -v
Information about binaries
what, ldd, strings
Which package does ls belong to
pkgchk -lp /usr/bin/ls
Compare directories, sync utilities
dircmp, rsync, filesync
Basic system information
uname -X
List users
listusers
Current nfs mount
nfsstat -m (or check /etc/rmtab)
Clear nfs locks
clear locks
Process types commands
apptrace – for tracing library calls
dtrace – debugger, new in version 10
pargs – get list of arguments and environment variables with which process was started
pfiles – list of file descriptors, associated with process
pgrep – get the PID’s of processes by name i.e. Something like ps -efl|grep -v grep|grep process_name
pkill – send signal to process. For example pkill -9 init 😛
pldd – list dynamic libraries, associated with process, similar to ldd for executable
plockstat – see list of locked by process files. Lock can be mutex i.e. exclusive and reader/writer for shared access
pmap – get memory map (segments) of process
preap – try to kick-off zombie process
prstat – fullscreen view of processes sorted by different criteria, similar to Linux top command
prun – continue hold with pstop process
ps – print process information and status. In Solaris exist SYSV and BSD variants, respectively /usr/bin/ps and /usr/ucb/ps
psig – list signals that can be handled by process
pstack – get backtrace stack of process for debugging purposes
pstop – temporary hold process
ptree – print the tree of processes
pwait – wait till process finish
pwdx – list working directory for process, like pwd command
truss – for tracing user/library/system calls and signals
Basic Unix Commands
diff file1 file2
Shows the DIFFerences between 2 files
du
shows the Disk Usage on the current directory. Note that Newer versions of Unix display usage in 512-byte units. Most users prefer to see Kbytes. To do that, use the command “du -k”. If you want this all the time, put “alias du du -k” in .cshrc.
grep string files
search all the specified files for the specified string. (Actually, you can specify a fairly complicated search pattern, but you will have to do “man grep” for details on that.)
lpr file
print file on the Line Printer – Solaris
Common options for ls:
-a
all files [normally files starting . not shown]
-l
long form – give lots of information
-t
time-sorted – most recent first
-R
Recursively look into directories
The “-a” option requires some explanation. Filenames starting with “.” are for files that you don’t normally want to see. These include .login and .logout, which list commands that get done automatically every time you log in or out, and files giving default options for various other programs. The designers of Unix figured you would want to set up these options and then forget about them. Thus a normal “ls” will not show files whose names start with “.”. “ls -a” will show all files, including those that start with “.”.
Printing
Once you know the printer name, and any conversions needed, you can issue the print command. If the file is plain text or it’s already been converted to Postscript, you can issue a simple print command, e.g.
lpr -P printer filename