Solaris Commonly Used Commands

0

Category:

#####################################################################################
Solaris System Administration Shell Commands
#####################################################################################

Debugging
#########

cat -v -t -e [file]
/* Show non-printing characters */
dumpadm -d swap
/* Configure swap device as dump device */

ld -l
/* Check if you have a particular library */

truss -f -p
/* Using multiple windows, this can be used to trace setuid/setgid programs */

truss executable
/* Trace doing of given command ( useful debugging ) */



Disk Commands
#############

/bin/mount -F hsfs -o ro /dev/sr0 /cdrom
/* Mount an ISO 9660 CDROM */

/usr/bin/iostat -E
/* Command to display drives statistics */

du -ad /var | sort -nr
/* Report the the disk used in /var in reverse order */

du -k .
/* Report disk usage in Kilobytes */

du -sk * | sort -nr | head
/* Shows the top ten largest files/directories */

du -sk *|sort -k1,1n
/* Reports total disk space used in Kilobytes in present directory */

du -sk .
/* Report total disk usage in Kilobytes */

fdformat -d -U
/* Format diskette */

newfs -Nv /dev/rdsk/c0t0d0s1
/* To view the superfblocks available */

prtvtoc /dev/rdsk/c0t0d0s2
/* Disk geometry and partitioning info */

prtvtoc /dev/rdsk/c0t0d0s2 | fmthard -s - /dev/rdsk/c0t1d0s2
/* Copy partition table from one disk to another */

quot -af
/* How much space is used by users in kilobytes */

volrmmount -i floppy
/* Mount a floppy or other media easily by its nickname. */



Driver Parameters
#################

ndd /dev/ip ip_forwarding
/* Show the ip_forwarding variable in the kernel */

ndd /dev/ip ip_forwarding 1
/* Set the ip_forwarding variable in the kernel */

ndd /dev/ip \?
/* Show all IP variables set in the kernel */



File Manipulation
#################

dos2unix | -ascii
/* Converts DOS file formats to Unix */

fold -w 180
/* To break lines to have maximum char */

split [-linecount] [file]
/* Split files into pieces */

[vi] : %s/existing/new/g
/* Search and Replace text in vi */

[vi] :set list
/* Show non-printing characters in vi */

[vi] :set nu
/* Set line numbers in vi */

[vi] :set ts=[num]
/* Set tab stops in vi */



File System
###########

/sbin/uadmin x x
/* Syncs File Systems and Reboots systems fast */

awk ' END {print NR}' file_name
/* Display the Number of lines in a file */

cat /dev/null > filename
/* Zero's out the file without breaking pipe */

dd if=/dev/rdsk/... of=/dev/rdsk/... bs=4096
/* Make a mirror image of your boot disk */

df -k | grep dg| awk '{print $6}' |xargs -n 1 umount
/* Unmount all file systems in disk group dg */

fsck -F ufs -o b=97472 /dev/rdsk/c0t0d0s0
/* Check and repair a UFS filesystem on c0t0d0s0, using an alternate superblock */

fsck -F ufs -y /dev/rdsk/c0t0d0s0
/* Check a UFS filesystem on c0t0d0s0, repair any problems without prompting. */

fsck -F ufs /dev/rdsk/c0t0d0s0
/* Check a UFS filesystem on c0t0d0s0 */

gzip -d -c tarball.tgz | (cd /[dir];tar xf - ) &
/* Unpacking tarballs to diff location */

gzip -dc file1.tar.gz | tar xf -
/* Unpack .tar.gz files in place */

ln [-fhns]
/* Creating hard links and soft links */

ls -al | awk '$3 == "oracle" || $3 == "root" {print $9}'
/* List all file names by testing owner */

ls -l | sort +4n
/* List files by size */

ls -la | awk '{ print $5," ",$9 }' | sort -rn
/* File sizes of current directory */

ls -lR | awk '{total +=$5};END {print "Total size: " total/1024/1024 "MB" }'
/* Recursive directory size calculations in MB */

mkisofs -l -L -r -o [image-name].iso [directory]
/* Create an ISO image of a directory */

mount -F ufs -o rw,remount /
/* Used to remount root to make it writeable */

mount -o remount,logging /spare
/* Re-mount the ro file system rw and turn on ufs logging */

mount DOS fdisk partition from Solaris
/* mount -f pcfs /dev/dsk/c0d0p1 /export/dos */

mv [filename]{,.new_suffix}
/* Renaming file */

pax -rw . /newdir
/* Efficient alternative for copying directories */

prtvtoc /dev/rdsk/c0t0d0s2 | fmthard -s - /dev/rdsk/c0t1d0s2
/* Cloning Partitiontables */

rpm -q --queryformat '%{INSTALLPREFIX}\n' [packagename]
/* [Linux] Locate binaries */

tar cf - . | (cd /newdir ; tar xf -)
/* Recursively copy files and their permissions */

tar cvf filename.tar
/* Create a tape (tar) archive */

tar xvf filename.tar
/* Extract a tape (tar) archive */

X=$(wc -l < filename); echo $X
/* Count number of lines in a file into a variable (ksh) */

zcat /* Extract the patch_file that is a compressed tar file */

zcat [cpio file] | cpio -itmv
/* Show the contents of a compressed cpio */



File Transfer
#############

find . -depth | cpio -pdmv /path/tobe/copied/to
/* Fast alternative to cp -pr */

find . -follow | cpio -pdumL /path/tobe/copied/to
/* Copy with symbolic links to be followed */

get filename.suffix |"tar xf -"
/* Undocumented Feature of FTP */

ssh cd /some/directory \&\& tar cf - | ssh cd /some/direstory \&\& tar xvf -
/* Move any file(s) without actually touching them */

put "| tar cf - ." filename.tar
/* Undocumented Feature of FTP */

sendport
/* FTP command for transferring large numbers of files within the same control session */



General
########

/bin/printf '%d\n' '0x'
/* Converts hexadecimal number to decimal. */

/usr/bin/catman -w
/* Create windex databases for man page directories */

FQ_FILENAME=; echo ${FQ_FILENAME%/*}
/* Extract directory from fully-qualified file name. */

mailx -H -u
/* List out mail headers for specified user */

ps -ef | grep -i $@
/* Access common commands quicker */

set filec
/* Set file-completion for csh */

uuencode [filename] [filename] | mailx -s "Subject" [user to mail]
/* Send files as attachments */

xauth -f /home/${LOGNAME} extract - ${DISPLAY} | xauth merge -
/* Allow root to xdisplay after su */



Hardware
########

cfgadm
/* Verify reconfigurable hardware resources */

m64config -depth 8|24
/* Sets the screen depth of your M64 graphics accelerator */

m64config -prconf
/* Print M64 hardware configuration */

m64config -res 'video_mode'
/* Change the resolution of your M64 graphics accelerator */

prtpicl -v | grep sync-speed
/* Discover SCSI sync speed */



Kernel
######

/usr/sbin/modinfo
/* Display kernel module information */

/usr/sbin/modload
/* Load a kernel module */

/usr/sbin/modunload -i
/* Unload a kernel module */

/usr/sbin/sysdef
/* Show system kernal tunable details */

nm -x /dev/ksyms | grep OBJ | more
/* Tuneable kernel parameters */



Memory
######

pagesize -a
/* Available page sizes for Solaris 9 */

prtconf | grep Mem
/* Display Memory Size of the local machine. */



Network Information
###################

arp -a
/* Ethernet address arp table */

arp -d myhost
/* Delete an ethernet address arp table entry */

lsof -iTCP@10.20.2.9
/* Display open files for internet address */

ndd /dev/arp arp_cache_report
/* Prints ARP table in cache with IP and MAC address */

netstat -a | grep EST | wc -l
/* Displays number active established connections to the localhost */

netstat -a | more
/* Show the state of all the sockets on a machine */

netstat -i
/* Show the state of the interfaces used for TCP/IP traffice */

netstat -k hme0
/* Undocumented netstat command */

netstat -np
/* Similar to arp -a without name resolution */

netstat -r
/* Show the state of the network routing table for TCP/IP traffic */

netstat -rn
/* Displays routing information but bypasses hostname lookup. */

snoop -S -ta [machine]
/* Snoop for network packets and get size and time stamp entries. */

traceroute
/* Follow the route to the ipaddress */



Network Tuning
##############

/sbin/ifconfig hme0:1 inet 10.210.xx.xxx netmask 255.255.0.0 broadcast 10.210.xxx.xxx
/* Virtual Interfaces */

/sbin/ifconfig hme0:1 up
/* Bring virtual interface up */

/usr/sbin/ndd -set /dev/hme adv_100fdx_cap 1
/* Nailling to 100Mbps */

ifconfig eth0 10.1.1.1 netmask 255.255.255.255
/* Add an Interface */

ifconfig eth0 mtu 1500
/* Change MTU of interface */

ndd -set /dev/ip ip_addrs_per_if 1-8192
/* To set more than 256 virtual ip addresses. */

ndd -set /dev/tcp tcp_recv_hiwat 65535
/* Increase TCP-receivebuffers on Sol2.5.1 systems with 100BaseTx */

ndd -set /dev/tcp tcp_xmit_hiwat 65535
/* Increase TCP-transmitbuffers on Sol2.5.1 systems with 100BaseTx */



Processes
#########

/usr/proc/bin/ptree
/* Print the parent/child process 'tree' of a process */

/usr/proc/bin/pwdx
/* Print the working directory of a process */

/usr/ucb/ps -aux | more
/* Displays CPU % usage for each process in ascending order */

/usr/ucb/ps -auxww | grep
/* Gives the full listing of the process (long listing) */

fuser -uc /var
/* Processes that are running from /var */

ipcs
/* Report inter-process communication facilities status */

kill -HUP `ps -ef | grep [p]roccess | awk '{print $2}'`
/* HUP any related process in one step */

lsof -i TCP:25
/* Mapping port with process */

pfiles
/* Shows processes' current open files */

pkill -n
/* Kill a process by name */

prstat -a
/* An alternative for top command */

ps -edf -o pcpu,pid,user,args
/* Nicely formatted 'ps' */

ps -ef | grep -i | awk '{ print $2 }'
/* Creates list of running PID by */

ps -ef | grep -i | awk '{ print $2 }'
/* Creates list of running PID by */

ps -ef | grep | grep -v grep | cut -c 10-15 | xargs kill -9
/* Find and kill all instances of a given process */

ps -ef | more
/* Show all processes running */

ps -ef|grep -v "0:00"|more
/* Gives you a list of any process with CPU time more than 0:00 */

ps -eo pid,args
/* List processes in simplified format */

ps -fu oracle|grep pmon
/* See which instances of Oracle are running */

top -b 1
/* Returns the process utilizing the most cpu and quits */



Resource Management
###################

/usr/bin/ldd [filename]
/* List the dynamic dependencies of executable files */

/usr/proc/bin/pmap pid
/* Report address space map a process occupies */



Route Configuration
###################

route add net 128.50.0.0 128.50.1.6 1
/* Add a route to the routing table */

route change 128.50.0.0 128.50.1.5
/* Changes the destination address for a route */

route delete net 128.50.0.0 128.50.1.6
/* Delete a route from the routing table */

route flush
/* Flush the routing table, which will remove all entries */

route get [hostname]
/* Which interface will be used to contact hostname */

route monitor
/* Monitor routing table lookup misses and changes */



Searching Items
###############

egrep "patterna|patternb"
/* Search for multiple patterns within the same file */

find -name "" -exec rm -rf {} \;
/* Recursively finds files by name and automatically removes them */

find . -type f -print | xargs grep -i [PATTERN]
/* Recursive grep on files */

find . ! -mtime - | /usr/bin/xargs rm -rf
/* Finds and removes files older than specified */

find . -exec egrep -li "str" {} \;
/* Find a string in files starting cwd */

find . -mtime -1 -type f
/* Find recently modified files */

find . -type f -exec grep "" {} \; -print
/* Find files (and content) containing within directory tree */

find . -type f -exec grep -l "" {} \;
/* Find files (and content) containing within directory tree */

find ./ \! -type f -exec ls -l {} \;|grep -v '^[l|p|s|-]'|grep -v 'total' | wc -l
/* Find number of directories under the current directory */

find / -fstype nfs -prune -o fstype autofs -prune -o -name filename -print
/* find without traversing NFS mounted file systems */

find / -mtime <# of days>
/* Find files modified during the past # of days */

find / -perm -2 -a ! -type l
/* Find files writable by 'others' */

find / -type f |xargs ls -s | sort -rn |more
/* List files taking up the most system space */

find / -user
/* Find all files owned by */

find / | grep [file mask]
/* Fast way to search for files */

find /proc/*/fd -links 0 -type f -size +2000 -ls
/* Find large files moved or deleted and held open by a process */

grep /var/sadm/install/contents| awk '{ print $1 ' ' $10 }'
/* Find which package contains a particular file */

ls -lR | grep
/* Fast alternative to find. */



Security
########

crypt abc && rm abc.cr
/* Decrypting a file that has been encrypted */

crypt abc.cr && rm abc
/* File encryption with crypt */

echo 'Please go away' > /etc/nologin
/* Stops users logging in */

find / -perm -0777 -type d -ls
/* Find all your writable directories */

find / -type f -perm -2000 -print
/* Find all SGID files */

find / -type f -perm -4000 -print
/* find all SUID files */

trap 'exit 0' 1 2 3 9 15
/* Trap specific signals and exit */

vi -x [filename]
/* Encrypt a file with vi editor */



Setting Term Options
#####################

stty erase ^?
/* Set the delete key to delete a character */

stty erase ^H
/* Set the backspace to delete a character */

stty sane
/* Reset terminal after viewing a binary file. */

tput rmacs
/* Reset to standard char set */



Snoop
#####

snoop -d pcelx0
/* Watch all the packets on a device */

snoop -i /tmp/mylog -o /tmp/newlog host1
/* Filter out all the host1 packets and write them to a new logfile */

snoop -i /tmp/mylog -v -p101
/* Show verbose info on packet number 101 in the logfile */

snoop -i /tmp/mylog host1 host2
/* View packets from a logfile between hosts1 and host2 */

snoop -o /tmp/mylog pcelx0
/* Save all the packets from a device to a logfile */

snoop -s 120
/* Return the first 120 bytes in the packet header */

snoop -v arp
/* Capture arp broadcasts on your network */

snoop port [port-number]
/* Monitor particular port for traffic */



Swap Files
##########

mkfile -nv 10m /export/disk1/myswap
/* Makes an empty 10 Megabyte swapfile in /export/disk */

mkfile -v 10m /export/disk1/myswap
/* Makes a 10 Megabyte swapfile in /export/disk */



Swap Space
##########

swap -a /export/disk1/swapfile
/* Add a swap file */

swap -d /dev/dsk/c0t0d0s4
/* Delete a swap device */

swap -l
/* List the current swap devices */

swap -s
/* List the amount of swap space available */



System Configuration
####################

/usr/sbin/eeprom auto-boot? false
/* Changes eeprom autoboot? setting without going to Ok prompt */

/usr/sbin/eeprom diag-switch? true
/* Set the system to perform diagnostics on the next reboot. */

/usr/sbin/eeprom local-mac-address?=true
/* Multiple Port Network Card Setting */

/usr/sbin/grpck
/* Check /etc/group file syntax */

/usr/sbin/pwck
/* Check /etc/passwd file syntax */

/usr/sbin/sys-unconfig
/* Clear host specific network configuration information */

/usr/sbin/useradd
/* Add a new user to the system */

drvconfig ; disks
/* Adding hot-plug disks to system */



System Information/Monitoring
#############################

/bin/echo "0t${stamp}>Y\n /* Convert UNIX timestamp to something human-readable */

/usr/platform/`/bin/uname -i`/sbin/prtdiag -v
/* System Diagnostics */

/usr/sbin/eeprom
/* Show eeprom parameters */

/usr/sbin/prtconf -vp
/* Show system configuration details */

coreadm -e log
/* Report global core */

grep "\-root" /var/adm/sulog | grep -v \+ | tail -25
/* List most recent attempts to switch to superuser account. */

isainfo -bv
/* Quickly checkout if machine is in 32 or 64 bit mode */

last
/* Tells who was or still is on the system */

logger -i
/* Log the process ID */

prtconf -pv | grep banner-name |awk -F\' ' { print $2 } ' | head -1
/* Show actual model name of machine */

prtpicl -v | grep wwn
/* A command to find persistent binding of storage */

psradm -f [processor id]
/* Take processor offline */

psrinfo | wc -l
/* Display number of processors */

sar -u
/* Report CPU Utilization */

sar [ -aA ] [ -o filename ] t [ n ]
/* Provides cumulative reports about system activity. */

telnet 13 | grep ':'
/* Get the time on remote Unix machine */

uname -a
/* Displays system information */

uname -X
/* Displays system information */

vmstat 10
/* Displays summary of what the system is doing every 10 seconds */

vmstat -p
/* to determine what kind of memory demand was causing a system to page */

who -b
/* Displays the date of the last system reboot. */

ypcat hosts | sort -n -t. +0 -1 +1 -2 +2 -3 +3 -4
/* Take the input of "ypcat hosts" or "cat /etc/inet/hosts" and sort by IP. */