sendmail -bi Creates new aliase db from /etc/aliase file. newaliases sendmail -bp Displays the contents of the mail queue mailq sendmail -q Processe the sendmail queue NOW sendmail -bt -d0.4 < /dev/null Prints out sendmail version, compile defines and system information refresh -s sendmail Restart sendmail, will re-read /etc/sendmail.cf kill -l (sendmail PID) stopsrc -s sendmail Stops the sendmail daemon startsrc -s sendmail "-bd -q30" Starts the sendmail daemon
Translate
Friday, 31 January 2014
SENDMAIL
DOS DISKETTES
dosdir Reads directory listing of a diskette dosdir (directory) Reads directory listing of a named directory dosread -D/dev/fd0 C41.TXT c41.txt Gets C41.TXT from diskette drive fd0 dosread -D/dev/fd0 DIRECTORY/C41.TXT c41.txt (-D option can be dropped if using fd0) doswrite -D/dev/fd0 (unixfile) (dosfile) Writes a file to diskette dosdel (dosfile) Deletes a dos file on diskette dosformat Formats the diskette
PERFORMANCE MONITORING / TUNING
vmstat (drive) (interval) (count) Reports virtual memory statistics. vmstat hdisk0 5 20 vmstat -s Diplays number of paging events since system start. vmstat -f Diplays number of forks since system start. vmstat -i Diplays number of interupts by device since system start. iostat (drive) (interval) (count) Reports i/o and cpu statistics. iostat hdisk0 5 20 iostat -d (drive) (interval) (count) Limits report to drive statistics. iostat -t (interval) (count) Limits report to tty statistics. sar -u -P ALL 10 10 Displays %usr %sys %wio %idle for all processors /usr/samples/kernel/vmtune Displays "Virtual Memory Manager" settings
ERROR LOGGING / LOGS
/usr/lib/errdemon -l Displays errorlog attributes.
/usr/lib/errdemon Starts error logging.
/usr/lib/errstop Stops error logging.
errpt Displays summary errorlog report.
errpt -a Displays detailed errorlog report.
errpt -j (identifier) Displays singe errorlog report.
Note : errorlog classes are H=Hardware S=Software O=Information V=Undetermined
errclear (days) Deletes all error classes in the errorlog.
errclear -d (class) (days) Deletes all error class entries in errlog.
Note : The errclear command will delete all entries older than the numbers of
days specified in the days paramenter. To delete ALL entries used 0.
errlogger "message up to 230 chrs"
Enters an operator notifaction message into the errorlog.
alog -L Lists all logs define in the alog db
alog -o -t (type) Display contents of log (type)
alog -o -t boot
cat /tmp/boot.log | alot -q -t (type) Copies contects of a file to a log
MISCELLENEOUS
http://www.rs6000.ibm.com/cgi-bin/ds_form Web based man pages
compress -c file.txt > file.Z Create a compressed file.
uuencode (infile) (extract-file-name) > (output file)
Converts a binary file to an ASCII file for transfer by modem or email
uudecode (encoded file)
Extracts a binary file from encoded file and calls it the extract-file-name
examples :-
uuencode maymap maymap > maymap.enc
uudecode maymap.enc
od -c /tmp Displays contents of the /tmp directory file
ls -i Lists files with their inode numbers
echo * Lists files, can be used if ls is corrupt/missing
chtz (timezone eg GMT0BST) Changes the timezone in /etc/environment file
chlang (language eg En_GB) Changes the language in /etc/environment file
ar -v -t (archive file) List contents of an archive
ar -v -x (archive file) Extracts the archive
ar -v -t /usr/lib/libC-r.a Lists contents of the libC_r.a library
find /source -print | cpio -pdm /target
Copying directories using cpio, creates /target/source directory.
dump -nTv (binary executable) Displays the contents of an executable file
dump -c Displays string information
dump -o Displays object file headers
dump -l Displays line numbers
dump -s Displays the text section
snap -ao /dev/rmt0 Create a snapshot onto tape
snap -ad (directory) Create a snapshot into a named directory other
than the default (/tmp/ibmsupt)
/usr/dt/bin/dtconfig -d Disables desktop logins
/usr/dt/bin/dtconfig -e Enables desktop logins
/var/dt/Xpid PID of the dtlogin process
LICENSES / SOFTWARE INSTALLATION
lslicense Displays number of current user licenses
chlicense -u (number) Changes the number of user licenses
( ftp,rexec and rsh (without -i flag) do not need an AIX user license to be
able to access the system. )
oslevel Returns operating system level
4 . 3 . 3 . 0 <--------- Preventive Maintenance Level
| | |
| | +----------------Modification
| +--------------------Release
+------------------------Version
oslevel -l 4.3.3.0 Displays all filesets that are "downlevel"
whence (program) Returns full path of program
whereis (program) Returms full path of program
what (program) Displays identifying info from the executable
like version number, when compiled.
lslpp -L all list all installed software
lslpp -L (program set name) Check if software installed
lslpp -f Lists filesets vs packages
lslpp -ha Lists installation history of filesets
lslpp -w /usr/bin/swapon Lists the fileset that the file belongs to
lppchk -c Checks file checksums against SWVPD
lppchk -l Checks symbolic links against SWVPD
instfix -ik (fix number eg IX66617) Checks id fix is installed
instfix -ik 4330-02_AIX_ML
instfix -i | grep ML Displays all ML's installed
instfix -k IX38794 -d /dev/cd0 Installs a fix from cdrom
/usr/sbin/install_assist Smitty Installation Assistant
/usr/sys/inst.images/sys.bundles Software bundle files
alt_disk_install -c hdisk1 Clones a running rootvg onto hdisk1
alt_disk_install -w Wakes up alt vg
alt_disk_install -s Sends alt vg to sleep !
alt_disk_install -x Removes alt vg from disk
/usr/lpp/bosinst/blvset -d /dev/hdisk0 -p 4.2
Resets the pad string in the BLV to the correct AIX version. Needed if the
migration option is missing when installing.
installp -ad (device) (fileset) (level) Install apply and commit fileset
installp -pad (device) (fileset) (level) Preview install
installp -u (fileset) Remove fileset
installp -ld (device) List all software on device
example:-
installp -pad /dev/rmt0 X11.base 4.3.3.0
installp -C Cleans up after a premature cancel or interrupted installation.
TERMINALS / DISPLAYS
/usr/share/lib/terminfo Directory with all support terminal info files.
tty Displays what the tty/pty number of the terminal is.
termdef reports the termtype setup in smit for the tty port
that termdef is run on.
chdev -l (device eg tty1) -a term=vt100 Sets tty to a vt100 terminal type
penable tty0 adds getty line into /etc/inittab for tty0 and starts getty
pdisable tty0 disables the getty line and disables getty
penable / pdisable -a option is for all
stty erase ^? Set backspace key for vt100 terminals
stty erase ^H Set backspace key for wyse50 terminals
lscons Displays the console device
chcons -a login=enable (device eg /dev/tty1) Changes the console device
lsdisp Display adapter device information
chdisp Change default display used by LFT subsystem
Create ttys on ports 0 to 7 on adapter sa2 :-
for i in 0 1 2 3 4 5 6 7
do
mkdev -c tty1 -t tty -s rs232 -p sa2 -w$i -a login=enable -a term=vt100
done
portmir -t /dev/tty0 Mirror current terminal onto /dev/tty0
portmir -o Turns off port mirroring
NETWORK
host (ip or hostname) Resolves a hostname / ip address
hostname Displays hostname
hostname (hostname) Sets the hostname until next reboot
lsdev -Cc if Lists all available/defined network interfaces
chdev -l (device name) -a hostname=(hostname) Changes hostname permanently
chdev -l inet0 -a hostname=thomas
ifconfig (device name) Displays network card settings
ifconfig (device name) up Turns on network card
chdev -l (device name) -a state=up Turns on network card
ifconfig (device name) down Turns off network card
ifconfig (device name) detach Removes the network card from the
network interface list
ifconfig en0 inet 194.35.52.1 netmask 255.255.255.0 up
ifconfig lo0 alias 195.60.60.1 Create alias ip address for loopback
route (add/delete) (-net/-host) (destination) (gateway)
Adds or deletes routes to other networks or hosts, does not update
the ODM database and will be lost at reboot.
route add -net 194.60.89.0 194.60.90.4
chdev -l inet0 -a "net,-hopcount,1,-netmask,255.255.255.0,207.156.168.0,10.0.15.254"
(destination) ( gateway )
Adds route and adds entry into ODM, route survives a reboot,
route -rn Display route table
odmget -q "attribute=route" CuAt Displays routes in the ODM.
lsattr -EHl inet0 Displays routes set in ODM and hostname
odmget -q "name=inet0" CuAt Displays routes set in ODM and hostname
refresh -s inetd Refresh inetd after changes to inetd.conf
kill -1 (inetd PID) Refresh inetd after changes to inted.conf
netstat -i Displays interface statistics
entstat -d (ethernet adapter eg en0) Displays ethernet statistics
arp -a Displays ip to mac address table from arp cache
no -a Displays network options use -o to set individual options or
-d to set individual options to default.
no -o option=value (this value is reset at reboot)
no -o "ipforwarding=1"
traceroute (name or ipaddress) Displays all the hops from source to
destination supplied.
ping -R (hostname or ipaddress) Same as traceroute except repeats.
spray (hostname or ipaddress) Send a stream of packets to a host
stopsrc -g tcpip Stops all running TCP/IP daemons
/etc/tcp.clean Stops all running TCP/IP daemons and removes all
lock files
/etc/rc.tcpip Start all TCP/IP daemons.
Do not use startsrc -g tcpip as this will start all
TCP/IP daemons including routed & gated
N.F.S.
exportfs Lists all exported filesystems exportfs -a Exports all fs's in /etc/exports file exportfs -u (filesystem) Un-exports a filesystem mknfs Configures and starts NFS services rmnfs Stops and un-configures NFS services mknfsexp -d /directory Creates an NFS export directory mknfsmnt Creates an NFS mount directory mount hostname:/filesystem /mount-point Mount an NFS filesystem nfso -a Display NFS Options nfso -o option=value Set an NFS Option nfso -o nfs_use_reserved_port=1
BACKUPS
MKSYSB
------
mkszfile -f Creates /image.data file (4.x onwards)
mkszfile -X Creates /fs.size file (3.x)
mksysb -i (device of file) Creates a mksysb image
mksysb does not save any raw data and will not backup a filesystem that
is not mounted.
SAVEVG
------
savevg -if (device or file) (vg) Creates a savevg image
restvg -q -f (device or file) Restore from a savevg image
Ensure that the restvg command is run from /
mkvgdata (vg) Creates new vgname.data file
CPIO ARCHIVE
------------
find (filesystem) -print | cpio -ocv > (filename or device)
eg find ./usr/ -print | cpio -ocv > /dev/rmt0
CPIO RESTORE
------------
cpio -ict < (filename or device) | more Lists archive
cpio -icdv < (filename or device)
cpio -icdv < (filename or device) ("files or directories to restore")
eg cpio -icdv < /dev/rmt0 "tcpip/*" Restore directory and contents
cpio -icdv < /dev/rmt0 "*resolve.conf" Restore a named file
TAR ARCHIVE
-----------
tar -cvf (filename or device) ("files or directories to archive")
eg tar -cvf /dev/rmt0 "/usr/*"
TAR RESTORE
-----------
tar -tvf (filename or device) Lists archive
tar -xvf (filename or device) Restore all
tar -xvf (filename or device) ("files or directories to restore")
use -p option for restoring with orginal permissions
eg tar -xvf /dev/rmt0 "tcpip" Restore directory and contents
tar -xvf /dev/rmt0 "tcpip/resolve.conf" Restore a named file
AIX ARCHIVE
-----------
find (filesystem) -print | backup -iqvf (filename or device)
Backup by filename.
eg find /usr/ -print | backup -iqvf /dev/rmt0
backup -(backup level 0 to 9) -f (filename or device) ("filesystem")
Backup by inode.
eg backup -0 -f /dev/rmt0 "/usr" -u option updates /etc/dumpdates file
AIX RESTORE
-----------
restore -qTvf (filename or device) Lists archive
restore -qvxf (filename or device) Restores all
restore -qvxf (filename or device) ("files or directories to restore")
(use -d for restore directories)
restore -qvxf /dev/rmt0.1 "./etc/passwd" Restore /etc/passwd file
restore -s4 -qTvf /dev/rmt0.1 Lists contents of a mksysb tape
BACKUPS ACROSS A NETWORK
------------------------
To run the backup on a local machine (cpio) and backup on the remote
machine's (remhost) tape drive (/dev/rmt0)
find /data -print | cpio -ocv | dd obs=32k | rsh remhost \
"dd ibs=32k obs=64k of=/dev/rmt0"
To restore/read the backup (cpio) on the remote machine
dd ibs=64k if=/dev/rmt0 | cpio -icvt
To restore/read the backup (cpio) on the local machine from the remote
machine's (remhost) tape drive (/dev/rmt0)
rsh remhost "dd ibs=64k obs=32k if=/dev/rmt0" | dd ibs=32k \
| cpio -icvt
To run the backup (cpio) on a remote machine (remhost) and backup to
the local machines tape drive (/dev/rmt0)
rsh remhost "find /data -print | cpio -ocv | dd ibs=32k" \
| dd ibs=32k obs=64k of=/dev/rmt0
tar cBf - . | rsh remhost "dd ibs=512 obs=512 of=/dev/rmt0"
Same as above but using tar instead of cpio.
Copying diskettes and tape
COPYING DISKETTES ----------------- dd if=/dev/fd0 of=(filename) bs=36b dd if=(filename) of=/dev/fd0 bs=36b conv=sync or flcopy COPYING TAPES ------------- dd if=/dev/rmt0 of=(filename) dd if=(filename) of=/dev/rmt0 or tcopy
VI Commands
:g/xxx/s//yyy/ global change where xxx is to be changed by yyy sed 's(ctrl v ctrl m)g//g' old.filename > new.filename Strips out ^M characters from ascii files that have been transferred as binary. To enter crontrol characters type ctrl v then ctrl ? where ? is whatever ctrl character you need.
DEVICES
lscfg lists all installed devices
lscfg -v lists all installed devices in detail
lscfg -vl (device name) lists device details
bootinfo -b reports last device the system booted from
bootinfo -k reports keyswitch position
1=secure, 2=service, 3=normal
bootinfo -r reports amount of memory (/ by 1024)
bootinfo -s (disk device) reports size of disk drive
bootinfo -T reports type of machine
ie rspc,rs6ksmp,rspc or chrp
lsattr -El sys0 -a realmem reports amount of useable memory
mknod (device) c (major no) (minor no) Creates a /dev/ device file.
mknod /dev/null1 c 2 3
lsdev -C lists all customised devices ie installed
lsdev -P lists all pre-defined devices ie supported
lsdev -(C or P) -c (class) -t (type) -s (subtype)
chdev -l (device) -a (attribute)=(new value) Change a device attribute
chdev -l sys0 -a maxuproc=80
lsattr -EH -l (device) -D Lists the defaults in the pre-defined db
lsattr -EH -l sys0 -a modelname
rmdev -l (device) Change device state from available to defined
rmdev -l (device) -d Delete the device
rmdev -l (device) -SR S stops device, R unconfigures child devices
lsresource -l (device) Displays bus resource attributes of a device.
cfgmgr Configures devices
cfgmgr -i /dev/cd0 Configure devices and install drivers from /dev/cd0
if required
cfgmgr -S Run in serial, used with a larger number of disks
cfgmgr -l scsi0 Configure devices on adapter scsi0 only
diag Run hardware diagnostic menu
smitty diag Run hardware diagnostic menu
( 7020-40P and 7248-43P machines cannot run diagnostics, use diagnostics
in the SMS menus instead )
diag -d (device) Run diagnostics against a device.
lsslot Displays all hot swap slots
lsslot -c pci Lists all pci hot swap slots
lsslot -c pci -a Lists all available pci hot swap slots
drslot Reconfgiures PCI hot-plug slots
drslot -i -c pci -s U0.1-P1-I3 Display a slot, flashes the LED next to
the slot so that it can be identified.
Power Management (PCI machines)
-------------------------------
pmctrl -a Displays the Power Management state
rmdev -l pmc0 Unconfigure Power Management
mkdev -l pmc0 Configure Power Management
TAPE DRIVES
rmt0.x where x = A + B + C
A = density 0 = high 4 = low
B = retension 0 = no 2 = yes
C = rewind 0 = yes 1 = no
tctl -f (tape device) fsf (No) Skips forward (No) tape markers
tctl -f (tape device) bsf (No) Skips back (No) tape markers
tctl -f (tape device) rewind Rewind the tape
tctl -f (tape device) offline Eject the tape
tctl -f (tape device) status Show status of tape drive
chdev -l rmt0 -a block_size=512 changes block size to 512 bytes
(4mm = 1024, 8mm = variable but
1024 recommended)
dd if=/dev/rmt0 bs=128k count=1 | wc -c
Displays the block size of an unknow tape. Set block size to 0 first.
bootinfo -e answer of 1 = machine can boot from a tape drive
answer of 0 = machine CANNOT boot from tape drive
diag -c -d (tape device) Hardware reset a tape drive.
diag -c -d rmt0
tapechk (No of files) Checks Number of files on tape.
< /dev/rmt0 Rewinds the tape !!!
PRINTERS / PRINT QUEUES
splp (device) Displays/changes printer driver settings splp /dev/lp0 export $LPDEST="pqname" Set default printer queue for login session lsvirprt Lists/changes virtual printer attributes. lsallq Displays all queues rmvirprt -q queuename -d queuedevice Removes a virtual printer qpri -#(job No) -a(new priority) Change a queue job priority. qhld -#(job No) Put a hold on hold qhld -r #(job No) Release a held job qchk -A Status of jobs in queues lpstat lpstat -p(queue) Status of jobs in a named queue qcan -x (job No) Cancel a job from a queue cancel (job No) enq -U -P(queue) Enable a queue enable (queue) enq -D -P(queue) Disable a queue disable (queue) qmov -m(new queue) -#(job No) Move a job to another queue startsrc -s qdaemon Start qdaemon sub-system lssrc -s qdaemon List status of qdaemon sub-system stop -s qdaemon Stop qdaemon sub-system
FILE SYSTEMS
Physical Volumes (PV's)
-----------------------
lspv Lists all physical volumes (hard disks)
lspv (pv) Lists the physical volume details
lspv -l (pv) Lists the logical volumes on the physical volume
lspv -p (pv) Lists the physical partition usage for that PV
lspv -M (pv) Lists the PP allocation table for that PV.
If the PV state is "missing" but the disk is okay, use "varyonvg vg" to change
the state of the PV to "active".
chdev -l (pv) -a pv=yes Makes a new hdisk a pysical volume.
chpv -v r (pv) Removes a disk from the system.
chpv -v a (pv) Adds the removed disk back into the system.
chpv -a y (pv) Changes pv allocatable state to YES
chpv -a n (pv) Changes pv allocatable state to NO
migratepv (old pv) (new pv) Moves all LV's from one PV to another PV, both
PV's must be in the same volume group.
Migratepv cannot migrate striped logical volumes, use cplv and rmlv.
replacepv (old pv) (new pv) (4.3.3 onwards)
INITTAB
telinit S Switches to single user mode.
telinit 2 Switches to multi user mode.
telinit q Re-examines /etc/inittab
lsitab -a Lists all entries in inittab
lsitab (ident eg tty1) Lists the tty1 entry in inittab
mkitab ("details") Creates a new inittab entry
chitab ("details") Ammends an existing inittab entry
rmitab (ident eg tty1) Removes an inittab entry.
chitab "tty1:2:respawn:/usr/bin/getty /dev/tty1"
ODM
odmget -q "name=lp1" CuDv |more Gets lp1 info from pre-defined database. odmget -q "name-lp1" CuAt |more Gets lp1 info from customised database. odmdelete -o CuAt -q "name=lp1" Deletes lp1 info from customised db. odmget -q "name=lp1" CuAt > lp1.CuAt Export ODM info to text file. odmadd lp1.CuAt Import ODM info from text file. odmshow CuAt Displays fields and record structures of CuAt odmchange odmdrop
REMOTE USERS
ruser -a -f (user) Adds entry into /etc/ftpusers file ruser -a -p (host) Adds entry into /etc/host.lpd file ruser -a -r (host) Adds entry into /etc/hosts.equiv file ruser -d -f (user) Deletes entry in /etc/ftpusers file ruser -d -p (host) Deletes entry in /etc/host.lpd file ruser -d -r (host) Deletes entry in /etc/hosts.equiv file ruser -s -F Shows all entries in /etc/ftpusers file ruser -s -P Shows all entries in /etc/host.lpd file ruser -s -R Shows all entries in /etc/hosts.equiv file ruser -X -F Deletes all entries in /etc/ftpusers file ruser -X -P Deletes all entries in /etc/host.lpd file ruser -X -R Deletes all entries in /etc/hosts.equiv file
USERS / ENVIRONMENT
passwd -f Change current users gecos (user description)
passwd -s Change current users shell
chfn (username) Changes users gecos
chsh (username) (shell) Changes users shell
env Displays values of environment variables
printenv
id Displays current user's uid and gid details
id (user) Displays user uid and gid details
whoami Displays current user details
who am i (or who -m)
who Displays details of all users currently logged in.
w
who -b Displays system reboot time
uptime Displays number of users logged in, time since last
reboot, and the machine load averages.
lsuser ALL Lists all users details
lsuser (username) Lists details for user
lsuser -a(attribute) (username or ALL) Lists user attributes
lsuser -a home ALL
mkuser -a(attributes) (newuser) Add a new user
chuser (attributes) (user) Change a user
chuser login=false (user) Lock a user account
rmuser -p (user) Removes a user and all entries in security files
usrck -t ALL Checks all the user entires are okay.
fuser -u (logical volume) Displays processes using the files in that LV
fuser -k /dev/lv02 Will send a kill signal to all processes using
/dev/lv02
lsattr -D -l sys0 -a maxuproc Displays max number of processes per user
chdev -l sys0 -a maxuproc=(number) Changes max number of processes per user
chlang (language) Changes the language settings for system or user.
En_GB = PC850 code pages
en_GB = ISO8859 code pages (Great Britain)
C = posix
su - (user) Switch to new user and change to the new users environment.
su (user) Switch to new user, current environment is propated to the
new shell.
SECURITY
nulladm /var/adm/wtmp To recreate/clear down the wtmp file.
groups Lists out the groups that the user is a member of
setgroups Shows user and process groups
chmod abcd (filename) Changes files/directory permissions
Where a is (4 SUID) + (2 SGID) + (1 SVTX)
b is (4 read) + (2 write) + (1 execute) permissions for owner
c is (4 read) + (2 write) + (1 execute) permissions for group
d is (4 read) + (2 write) + (1 execute) permissions for others
-rwxrwxrwx -rwxrwxrwx -rwxrwxrwx
||| ||| |||
- - -
| | |
Owner Group Others
-rwSrwxrwx = SUID -rwxrwSrwx = SGID drwxrwxrwt = SVTX
chown (new owner) (filename) Changes file/directory owners
chgrp (new group) (filename) Changes file/directory groups
chown (new owner).(new group) (filename) Do both !!!
umask Displays umask settings
umask abc Changes users umask settings
where ( 7 - a = new file read permissions)
( 7 - b = new file write permissions)
( 7 - c = new file execute permissions)
eg umask 022 = new file permissions of 755 = read write and execute for owner
read ----- and execute for group
read ----- and execute for other
mrgpwd > file.txt Creates a standard password file in file.txt
passwd Change current user password
pwdadm (username) Change a users password
pwdck -t ALL Verifies the correctness of local authentication
lsgroup ALL Lists all groups on the system
mkgroup (new group) Creates a group
chgroup (attribute) (group) Change a group attribute
rmgroup (group) Removes a group
SCHEDULING
crontab -l List out crontab entrys
crontab -e Edit crontab entrys
crontab -l > (filename) Output crontab entrys to a file
crontab (filename) Enter a crontab from a file
crontab -r Removes all crontab entrys
crontab -v Displays crontab submission time.
/var/adm/cron/cron.allow File containing users allowed crontab use.
/var/adm/cron/cron.deny File containing users denied crontab use.
/var/adm/cron/crontab Directory containing users crontab entries.
/var/adm/cron/log Cron log file.
at (now + 2 minutes, 13:05, etc) {return} Schedule a job using at
Command or schell script {return}
{CTRL D}
echo "shutdown -Fr" | at now + 1 minute
at -l
atq Lists out jobs scheduled to run via at command
at -r (at job No)
atrm (at job No) Removes an at job scheduled to run.
/var/adm/cron/at.allow File containing users allowed at use.
/var/adm/cron/at.deny File containing users denied at use.
/var/adm/cron/atjobs Directory containing users at entries.
PAGING SPACE (PS's)
lsps -a Lists out all paging space
lsps -s Displays total paging and total useage
lsps (ps)
swappon /dev/ps Activates a paging device eg /dev/paging00
swappoff /dev/ps Deactivates a paging device ( AIX 5.x only )
mkps -s(No of PP's) -n -a (vg)
mkps -s(No of PP's) -n -a (vg) (pv)
-n = don't activate/swapon now -a = activate/swapon at reboot
mklv -b n -t paging -y hd6 (vg) (No of PP's) (pv)
Creates paging space using the mklv command.
chps -a n (ps) Turns off paging space.
chps -s(No of PP's) (ps) Increases paging space.
chps -d(No of PP's) (ps) Decreases paging space ( AIX 5.x only )
chlv -n (new name) (old name) Change paging space name
rmps (ps) Remove paging space. PS must have been turned off
and then the system rebooted before it can be removed.
Note : Need to change the swapon entry in /sbin/rc.boot script if you are
changing the default paging space from /dev/hd6. You also need to
do a "bosboot -a -d /dev/hdiskx" before the reboot.
/etc/swapspaces File that lists all paging space devices that are
activated/swapon during reboot.
SYSTEM DUMP
1, AIX 4.2.1 and greater supports system dump to paging space. 2, AIX 4.3.3 and greater supports system dump to mirrored paging space. 3, Primary dump device must be in the rootvg 4, Secondary dump device can be outside rootvg unless it is a paging device. sysdumpdev -l Lists current dump destination. sysdumpdev -e Estimates dumpsize of the current system in bytes. sysdumpdev -L Displays information about the previous dump. sysdumpstart -p Starts a dump and writes to the primary dump device. sysdumpstart -s Starts a dump and writes to the secondary dump device. (MCA machine can also dump if key is in service position and the reset button is pressed) sysdumpdev -p (dump device) -P Sets the default dump device, permanently Analyse dump file :- echo "stat\n status\n t -m" | crash /var/adm/ras/vmcore.0 snap -gfkD -o /dev/rmt0 Copy dump to tape to send to IBM support, uses tar.
BOOT LOGICAL VOLUME (BLV) / PROCESSORS / KERNEL
Mirroring does not work with the BLV as it is not a true logical volume,
bosboot must be run against the other disk after mirroring the rootvg.
bootlist -m (normal or service) -o displays bootlist
bootlist -m (normal or service) (list of devices) change bootlist
bootinfo -b Identifies the bootable disk
bootinfo -t Specifies type of boot
bosboot -a -d (/dev/pv) Creates a complete boot image on a physical volume.
mkboot -c -d (/dev/pv) Zero's out the boot records on the physical volume.
savebase -d (/dev/pv) Saves customised ODM info onto the boot device.
lslv -m hd5 Find out which disk the BLV is on.
bootinfo -y Displays which kernel can be used, 32 or 64 bit
genkex Reports all loaded kernel extensions.
lsdev -Cc processor Lists all processors
lsattr -EHl proc0 Displays attributes of processor 0. AIX 5.1L will
display processor clock frequency.
Mirroring
mklv -y (lv) -c(copies 2 or 3) (vg) (No of PP's) (PV Name optional) Creates a mirrored named logical volume. mklvcopy -s n (lv) (copies 2 or 3) (pv) Creates a copy of a logical volume onto another physical volume. The physical volume MUST be in the same volume group as the orginal logical volume ! rmlvcopy (lv) (copies 1 or 2) Removes logical volume copies. rmlvcopy (lv) (copies 1 or 2) (pv) From this pv only! syncvg -p (pv) Synchronize logical partion copies syncvg -l (lv) syncvg -v (vg) mirrorvg (vg) (pv) Mirrors the all the logical volumes in a volume group onto a new physical volume. New physical volume must already be part of the volume group. chfs -a splitcopy=/backup -a copy=2 /data1 Splits off a copy of a 3 way mirror and mount read only for use as an
File Systems (FS's)
lsfs Lists all filesystems
lsfs -q (fs) Lists the file system details
lsjfs Displays data about all filesystems in CSV style format
mount Lists all the mounted filesystems
mount (fs or lv) Mounts a named filesystem
mount -a Mounts all filesystems
mount all
mount -r -v cdrfs /dev/cd0 /cdrom mounts cd0 drive over /cdrom
crfs -v jfs -d(lv) -m(mount point) -A yes
Will create a file system on the whole of the logical volume, adds entry into
/etc/filesystems and will create mount point directory if it does not exist.
( use -v jfs2 for JFS2 filesystems )
crfs -v jfs -g(vg) -m(mount point) -a size=(size of fs) -A yes
Will create a logical volume on the volume group and create the file system on
the logical volume. All at the size stated. Will add entry into
/etc/filesystems and will create the mount point directory if it does not exist.
Use attribute "-a log=/dev/log01" to specify a jfslog devices
Use attrubute "-a bf=true" for a large file enabled filesystem
chfs -A yes (fs) Change file system to Auto mount in
/etc/filesystems
chfs -a size=(new fs size)(fs) Change file system size
chfs -m (new-mount-point) (fs) Change the file system mount point.
rmfs (fs) Removes the file system and will also remove the
LV if there are no onther file systems on it.
defrag -q (fs) Reports the fragment status of the file system.
defragfs -r (fs) Runs in report only defrag mode (no action).
defragfs (fs) Defragments a file system.
fsck (fs) Verify a file system, the file system must be unmounted!
fsck (-y or -n) (fs) Pre-answer questions either yes or no !
fsck -p (fs) Will restore primary superblock from backup copy if the
superblock is corrupt.
( or dd count=1 bs=4k skip=31 seek=1 if=/dev/lv00 of=/dev/lv00 )
Logical Volumes (LV's)
lslv (lv) Lists the logical volume details lslv -l (lv) Lists the physical volume which the LV is on lsattr -EHl (lv) Displays more logical volume details mklv (vg) (No of PP's) (pv Name optional) Create a logical volume mklv -y (lv) (PP's) (pv name optional) Creates a named logical volume ( use -t jfs2 when creating an LV for a JFS2 filesystem ) chlv -n (new lv) (old lv) Rename a logical volume chlv -x (number) (lv) Change max no of PP's chlv -s n (lv) Turns of strickness on the LV extendlv (lv) (extra No of PP's) Increase the size of an LV rmlv (lv) Remove a logical volume cplv -v (vg to copy to) -y (new lv) (lv) Copy an LV to a new LV If copying a filesystem LV, umount the filesystem before copying, otherwise you will have to fsck the the new LV before the filesystem can be mounted. If copying a striped LV to an LV that is already created, and the stripe size is different ( or not even striped ), then these new parameters are maintained when the data is copied to the new LV. cplv -e (new lv) (old lv) Copy to an existing LV ( new lv must have type as copy use chlv -t copy (new lv) to change ) mklv/extendlv -a = PP alocation policy -am = middle -ac = center -ae = edge -aie = inner edge -aim = inner middle migratepv -l (lv) (old pv) (new pv) Move a logical volume between physical volumes. Both physical volumes must be in the same volume group ! mklv -y (lv) -t jfslog (vg) (No of PP's) (pv Name optional) Creates a JFSlog logical volume. logform (/dev/lv) Initialises an LV for use as an JFSlog getlvcb -AT (lv) Displays Logical Volume Control Block information
Volume Groups (VG's)
lsvg Lists all volume groups
lsvg (vg) Lists the volume group details
lsvg -l (vg) Lists all logical volumes in the volume group
lsvg -p (vg) Lists all physical volumes in the volume group
lsvg -o Lists all varied on volume groups
varyonvg (vg) Vary On a volume group
varyonvg -f (vg) Forces the varyon process
varyonvg -s (vg) Vary on a VG in maintenance mode. LV commands can be
used on VG, but LV,s cannot be opened for I/O.
varyoffvg (vg) Vary Off a volume group
synclvodm (vg) Tries to resync VGDA, LV control blocks and ODM.
synclvodm -v (vg) Rebuilds the LVCB.
(the vg needs to be varied on before running synclvodm)
mkvg -y(vg) -s(PP size) (pv) Create a volume group
mkvg -y datavg -s 4 hdisk1
reducevg (vg) (pv) Removes a volume group
reducevg -d (vg) (pv) Removes a volume group and delete all LV's on the PV
reducevg (vg) (PVID) Removes the PVID disk reference from the VGDA when a
disk has vanished without the reducevg (vg) (pv)
command being run first.
reducevg -df (vg) (pv) Deletes all LV's from the VG and removes the VG
from the disk. If the last disk in the VG then
the VG is deleted.
extendvg (vg) (new pv) Adds another PV into a VG.
exportvg (vg) Exports the volume group, removes the VG entries and
removes all FS entries from /etc/filesystems but
leaves the mount points.
Note : Cannot export a VG if it has active paging space, turn off paging,
reboot before exporting VG. Exporting removes entries from filesystems
file but does not remove the mount points.
chvg -a y (vg) Auto Vary On a volume group at system start.
chvg -u (vg) Unlocks a locked volume group.
lqueryvg -Atp (pv) Details volume group info for the hard disk.
importvg -y (vg name) (pv) Import a volume group from a disk.
importvg (pv) Same as above but VG will be called vg00 etc.
4.3 onwards, importvg will automatically varyon the VG.
chvg -Q (y/n) (vg name) Turns on/off Quorum checking on a VG.
reorgvg (vg) (lv) Reorganised a fragmented LV, must state an LV at the
command line else the first LV in the VG is picked.
Does not reorg the PP's of striped LV's.
SOURCE CODE CONTROL SYSTEM (SCCS)
SCCS Overview
The source code control system allows versions of a program to be stored in a special file, so that any version may be retrieved. There are a few commands involved (not all of them listed here). All source code files start with 's.'
The source code control system allows versions of a program to be stored in a special file, so that any version may be retrieved. There are a few commands involved (not all of them listed here). All source code files start with 's.'
- get -r<revision> <source code file>
- - get a program out of source code to read only. Missing out the -r flag gets the most recent version. e.g.
$ get $SCUK/s.parser.c # extracts file parser.c from source code file $SCUK/s.parser.c as read only. See get -e for editing. - get -e <source code file>
- - get a piece of code out for edit, so that the code may be modified and a new version created using 'delta'. e.g.
$ get -e $SCUK/s.parser.c # extracts file parser.c from source code file $SCUK/s.parser.c for editing. See get for read-only. - delta <source code file>
- - you must be in the directory with the modified piece of code when you execute this command. This adds the latest version to the source code file. e.g.
$ delta $SCUK/s.parser.c # writes file parser.c to the source code file $SCUK/s.parser.c . See get -e for information on how to extract the file from source code. - prs <source code file>
- - show comments/details on source code file.
- admin -r <revision no> -i <program> <source code file>
- - create a new source code file with progam. -r specifies the initial revision of the program and may be missed out (default is 1.1 I think). Must be spaced correctly! admin is also used for sccs administration, but it gets to fear and loathing time pretty fast. e.g.
admin -iparser.c $SCUK/s.parser.c # creates a new source code file called $SCUK/s.parser.c from the file parser.c - unget <source code file>
- - cancels a get -e
SCREEN COMMUNICATION
$ echo "Hello" # will print Hello on your screen
$ echo "Hello" > /dev/tty616 # will print Hello on someone elses screen (warning - can crash their screen!)
$ echo $DESTF10 # will print the value of the environment variable DESTF10
$ echo "\033Fdemo demo" # will echo demo to the status bar at the top of a wyse terminal
See also file shellscripts
- tput cnorm - turns the screen cursor on
- tput civis - turns the screen cursor off
- tput clear - clears the screen
- tput smso - turns all new text to bold
- tput rmso - turns all bold text off
$ ls | tee /tmp/x # would output ls normally and put a copy in /tmp/x. The option '-a' is used to append rather than replace files.
TAPES AND DISKS
Please see this page for more information on disks in AIX
- dd if=<filename or device> of=<filename or device> bs=<Block Size> conv=sync
- - direct (and I mean DIRECT) copy, normally to tape. Archaic syntax and very rarely used. flags:
- if - input filename or device
- of - output filename
- bs - block size
- conv - ??
$ dd if=/etc/hosts of=/dev/rmt0 bs=1024 conv=sync # write hosts file to tape using dd - cpio
- stands for copy in-out, and is extremely powerful if you can cope with the innumerable flags that you have to use(!)
$ cpio -iBcvumd "etc/hosts" </dev/rmt0 # Grab /etc/hosts file from tape
$ find /etc -print | cpio -oBcv >/dev/rmt0 # Write the contents of the /etc directory to tape
$ find /etc -print | cpio -pdumv /usr2/etcbackup/ # copy directory /etc to /usr2/etcbackup and retain all permissions.
meaning of the flags:- i - input
- o - output
- B - Block size of 5120 bytes
- c - read/write header info
- v - list file names
- u - unconditional copy - overwrites existing file.
- m - keep modification dates
- d - creates directories as needed.
- t - generate listing of what is on the tape.
- p - preserve permissions.
- tapeutil -f <devicename> <commands>
- - A program which came with the tape library to control it's working. Called without arguments gives a menu. Is useful for doing things like moving tapes from the slot to the drive. e.g.
$ tapeutil -f /dev/smc0 move -s 10 -d 23 # which moves the tape in slot 10 to the drive (obviously, this will depend on your own individual tape library, may I suggest the manual?). - doswrite -a <unix file> <dos file>
- - copy unixfile to rs6000's floppy disk drive in DOS format. -a option expands certain characters, for certain ascii conversions.
- dosdir <directory>
- - show list of files on a dos floppy disk. Useful with option -l (long format). Like dos command 'dir'
- dosread -a <DOS file> <unix file>
- - copy dos file in floppy disk drive to unix - if UNIXFILE is omitted, it outputs to the screen.
- dosdel <DOS file>
- - delete dos file on floppy disk.
- dosformat
- - format dos floppy disk (High Density)
- tar
- - Read/Write stuff to archive.
tar cvf /dev/rmt0 <filenames> # will write files to tape
tar xvf /dev/rmt0 will read files from tape
tar tvf /dev/rmt0 will give a listing of what's on the tape. If you're using an archive file then replace /dev/rmt0 in the examples above with the name of the archive file.
CONNECTIVITY
$ rlogin hollandrs # log in to machine called hollandrs
Useful with -l option to specify username - e.g.
$ rlogin cityrs -l ismsdev # log in to machine cityrs as user ismsdev For further info about trust network see .rhosts file and /etc/resolv.conf (I think).
- -f (to force the copy to occur)
- -r (to recursively copy a directory)
- -p (to attempt to preserve permissions when copying)
$ su - root # become root
$ su root # gain permissions of root but don't change the current environment variables
$ su - vlink # switch to user vlink
If you are root, you may su to any other user without being prompted for a password. su without arguments is the same as 'su root'. Note that the 'su' option is not available on all UNIX machines as it can crash some of them.
- -q ping quietly
- -i<no> wait no of seconds between each packet sending. The default is 1 second. If you are using ping to keep an ISDN line up then using something like $ ping -i 5 -q hollandrs is ideal.
- -f Never use this! Sends as many packets as it possibly can as fast as possible, used for network debugging and is likely to slow networks horribly when used. Known as 'flood' pinging.
- -c <no> send no of packets before giving up
$ rsh altos more /tmp/chk # will run the command more the file /tmp/chk on the machine called altos. Useful in pipes for example. rsh on its own will execute a login. Use option '-l' to specify logon name. You can also use rcmd and remsh on other flavours of unix.
SYSTEM COMMANDS
$ stty intr ^A # would change the interrupt key to being control-A
$ stty quit ^L #would set the quit key (normally ^\) to control-L. other key changes are:
- erase (normally ^H)
- xon (normally ^Q)
- xoff (normally ^S)
- eof (normally ^D)
lspv without arguments will produce a list of all the hard-disks used. lspv <hard-disk-name> will produce a list of information about the hard disk. lspv -l <hard-disk-name> will show any logical volumes which are mapped on to that drive.
- -C list Configured devices
- -P list Possible devices
# Script to add a tty. Options that need amending are:
# -l name of tty to be created - e.g '-l tty600' wil create
# a tty called 'tty600'
# -p RAN name
# -w Port number on RAN
# -a Attributes (e.g. to set up auto login, etc.)
mkdev -c tty -t 'tty' -s 'rs232' -l tty433 -p sa2 -w 2 -a term='wyse50' -a forcedcd='enable' -a login='enable' -a speed='19200'e.g. To create a printer (raw device):
mkdev -c printer -t 'osp' -s 'rs232' -p 'sa3' -w '10' -l label2 -a xon='yes' -a dtr='no' -a col=500
It is highly recommended that you make and change devices using smit
- -o <object> to specify a target instead of a.out
- -O optimise
- -w or -W all warning flags.
- -f shuts the system down immediately (rather than waiting for a minute)
- -R reboot the system immediately after halt
GENERAL INFORMATION COMMANDS
- -t <tty> - show all processes running on a terminal
- -ef - show all processes
- -u <loginname> - show all processes owned by a user
- -flp <processid> - show as much information as you can about a process number
- -aux - show processes in order of usage of the processors. Useful to see what processes are hogging system resources.
$ at now + 5 minutes
echo "Phone Julie McNally" > /dev/tty616
^D
job compjmd.389748732 will be run at ???Will echo to tty616 the message "Phone Julie McNally" in 5 minutes. e.g.2
$ at 0331235930
echo "April fools day!" > /dev/console
^Dwill echo "April fools day!" to the console at 11:59 and 30 seconds, on the 31st of march. Format for this is: [YYYY]MMDDhhmmss. at jobs are sometimes used in the place of crontab's because if the machine is off when the crontab is meant to take place, the job never happens. at jobs automatically start when the machine is switched on if the machine was down at the time. typing at -l will show you all the at jobs you have queued, at -r <atjob> will remove an at job (only the owner or root is allowed to do this).
EXTREMELY USEFUL COMMANDS
$ ls -l
| Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7 |
| -rw-rw-rw- | 1 | root | staff | 28 | Jan 16 09:52 | README |
| -rw------- | 1 | compjmd | staff | 4304 | Jun 24 12:21 | tabledict |
| drwxrwxrwx | 2 | compjmd | staff | 512 | Jul 1 16:30 | testdir |
| -rwxrwx--- | 1 | compjmd | system | 0 | Jul 1 16:30 | a.out |
... is a sample listing.
- Part 1: Permissions - see chmod for explanation of these. If the first field is set, then the file in question is not really a file at all, but something else, key:
- -: normal file
- d: directory
- l: symbolic link created by 'ln'
- c or b: device of some sort
- Part 2: Number of links to this file (directories always have 2+).
- Part 3: The owner of the file - e.g. If the owner is 'compjmd' and permissions are set to -rw------- then only the user 'compjmd' may read or write to that file. Again, if owner is "compjmd" and permissions are -r-x------ then only the user compjmd may read or execute that file. Only the owner of a file or root may chmod it.
- Part 4: The group ownership of the file - (bloody hell, this is getting complicated). On a unix system there are certain 'groups' which users can belong to, held in the file '/etc/group'. You will notice that in this file there will be a main group, e.g. 'staff' which contains every user. Which means that any user listed under staff is in that group.....right...every file has a group attached to it. Which means that if a file had permissions ----rw---- and a group reference of 'system', then only users who were part of the group system could modify that file. To see which groups the current user belongs to do id. Sorry if this wasn't comprehensible but you should never need to use this anyway(!).
- Part 5: Size of the file in bytes
- Part 6: Time of last modification
- Part 7: The name of the file
- ls -a show files starting with '.' too
- ls -A show files starting with '.' but not '.' or '..'
- ls -c must be used with either option l and/or t - displays/sorts by modification time
- ls -d do not show subdirectory listings
- ls -i display the i-node number of each file
- ls -t Put the listing in time order (see options u and c)
- ls -r Put the listing in reverse order - usually used with a -t
- ls -u must be used with either options l and/or t - displays/sorts by last-access time
$ vi +/"love it or loathe it" handycommands
Users new to vi hate it. I personally managed to get through University without using it ever (I used Joe's own editor instead). If I accidentally went into vi, I had to ^Z and kill the job. Sigh. Five years of using vi means that I'm getting a little better at it now... (I'm actually typing this now in a vi-clone for Windows).
$ grep D7523 mcall_reps.out # will find all the lines in mcall_reps.out that have the string "D7523" in it. Also incredibly useful for things like pipes,e.g.
$ du | grep cred # (in /home directory will show all users that have 'cred' in their title). You may use regular expression matching - e.g.
$ grep "main.*{" x.c # would match any line containing 'main' and an open curly brackets at any point in the line afterwards. There are two variations to grep - fgrep and egrep which do virtually the same things as grep, but are either faster (having less options) or more complex (but slower). See also section on Wildcards
Options:
- -v : show all lines that do not contain pattern.
- -y : don't bother matching case
- -i : don't bother matching case
- -c : show count of matching lines rather than the lines themselves
- -l : show filename's instead of matching lines.
$ man ps # will list the manual page for the command ps
OTHER FILE HANDLING COMMANDS
$ type sendmail
sendmail is /usr/sbin/sendmail
This command is merely an alias for 'whence -v'
Use option: -v for verbose mode
$ chmod 666 handycommands
changes the permissions (seen by ls -l) of the file handycommands to -rw-rw-rw-
r = 4, w = 2, x = 1. In the above example if we wanted read and write permission for a particular file then we would use r + w = 6. If we then wanted to have the file have read-write permissions for User, Group and All, then we would have permissions of 666. Therefore the command to change is that above.
$ chmod 711 a.out
Changes permissions to: -rwx--x--x
Additional explanation of file permissions and user/group/all meaning are given in the description of ls -l
You may specify chmod differently - by expressing it in terms of + and - variables. For example
$ chmod u+s /usr/bin/su
will modify the "sticky bit" on su, which allows it to gain the same access on the file as the owner of it. What it means is "add s permission to user". So a file that started off with permissions of "-rwxr-xr-x" will change to "rwsr-xr-x" when the above command is executed. You may use "u" for owner permissions, "g" for group permissions and "a" for all.
chown informix *.dat # change all files ending .dat to be owned by informix
chgrp sys /.netrc # change file /.netrc to be owned by the group sys
or find <dirname> -print | cpio -pdumv <dirname2>; rm -r <dirname>
$ mkdir /tmp/jon/ # create directory called /tmp/jon/
$ find . -name "system.log" -print # will find all files (with full path names) called system.log - Wildcards are allowed, e.g.
$ find /tmp -name "sl.*" -atime +0 -print # will print out all files in /tmp/ that start sl. and which haven't been accessed for a day. Helpful for finding lost files, or finding stuff in enormous directories. Other useful options include:
- -atime +<days> - finds files that haven't been accessed for 1+days also, ctime (creation time) and mtime (modify time)
- -prune - stay in current directory - don't look in dirs off the directory specified in path names - e.g.
$ find /tmp -user "compgnc" -prune -print # will find all files in /tmp which user compgnc owns and will not search lower directories (e.g. /tmp/usr) - -size +<blocks> - finds files that are bigger than <blocks>
- -exec rm {} \; - remove all files found...dangerous command - e.g.
$ find /tmp -name "sl.*" -atime +0 -prune -print -exec rm {} \; # will remove all files in /tmp starting 'sl.' that haven't been accessed for a day. Spacing of this command is important! Most exec commands are possible:
$ find /usr2/calltest -name "*.4gl" -print -exec grep "CHECK" {} \; | pg - -ok - like exec only it prompts for confirmation after each occurence. e.g.
$ find /tmp/disk7 -name "*" -print -ok doswrite -a {} {} \; # Please note that you MUST end any exec or ok option with an escaped semicolon (\;). - -user <username> - finds all files owned by <username>
- -group <groupname> - finds all files with a group of <groupname>
$ ln -s /usr/uniplex/compgnc /u/compgnc/uni # would create a link called 'uni' in the directory /u/compgnc. From then on, typing cd uni would cd to /usr/uniplex/compgnc. You can also give two files the same name. e.g.
$ ln make.e_enquiry makefile # would link the two files so that they are identical, and when you change one, you change the other. You may also create a symbolic link to a host(!). Instead of typing 'rlogin hpserver' every time, by typing
$ ln -s /usr/bin/rsh hpserver # will create a link so that whenever you type 'hpserver' it will execute a remote shell on the machine.
Option -f forces the link to occur
$ head -45 label1.out | lp -dlocal1
$ tail -f vlink.log # follow end of vlink.log file as it is created.
- -l (lines)
- -c (chars)
- -w (words)
$ split -5000 CALLS1 # will split file CALLS1 into smaller files of 5000 lines each called xaa, xab, xac, etc.
$ cat handycommands | tr "\t" " " # will take the file handycommands and translate all tabs into spaces. Useful when messing about with awk or you need to convert some input (e.g. that from tty) to a unique filename that does not contain special characters. e.g.
$ tty | tr "/" "." # produces for example .dev.pts.7
Used for debugging shells, seeing error messages which flash off the screen too quickly, etc.
$ cut -d "|" -f1,2,3 active.unl # will take the file active.unl which is delimited by pipe symbols and print the first 3 fields options:
- -d <delimiter>
- -f <fields>
$ cut -c8-28 "barcode.txt" # would cut columns 8 to 28 out of the barcode.txt file.
Name:
Employee Number:and another file with the lines:
Fred Bloggs
E666then by doing:
$ paste file1 file2 > file3 # this would then produce (in file3).
Name: Fred Bloggs
Employee Number: E666Note that paste puts horizontal tabs between the files, so you may need a sed 's/ //g' command to get rid of these.
$ sort /tmp/list_of_names # will sort the file into alphabetical order, and display it to the screen. Useful with option '-u' to filter out duplicates.
INPUTS, OUTPUTS AND WILDCARDS
Unix commands generally get their information from the screen, and output to it. There are three main 'streams' which unix uses to get/place it's information on. These streams are called:- stdin (Standard Input) - normally, what you type into the screen
- stdout (Standard Output) - normally, what is output to the screen
- stderr (Standard Error) - normally, error messages which go to the screen
any of these may be redirected by the following symbols:- < <filename> take input from <filename> rather than the screen. e.g.
$ ksh < x # will read all commands from the file x and execute them using the Korn shell. - > <filename> take output from the command and place it in <filename>. e.g.
$ ls > x will place the output of the command 'ls' in the file x - >> <filename> take output from the command and append it to <filename>. e.g.
$ ls /tmp >> x will place the output of the command 'ls' and append it to the file x - 2> <filename> take any error messages from the command and put it in <filename>. e.g.
$ ls /tmp 2>/dev/null would throw away any error messages that are produced by ls (sorry, /dev/null is a file that, if written to, the information disappears never to be seen again). - command1 | command2 Pipe - Takes the standard output of the first command, and turns it into the standard input of the second command. The output of the second command will then be put on the standard output (which, again, may be a pipe) e.g.
$ ls | more will send the output of 'ls' into the command 'more', thus producing a directory listing which stops after every page. This method is called piping.
command1 & - the ampersand (&) forces command1 to run in the background. so that you may continue to type other commands in the shell, while command1 executes. It is not advisable to run a command in the background if it outputs to the screen, or takes it's input from the screen
See also tee which allows splitting of the input stream and output to several different places at once.
Wildcards
- B Bib Baby Fox Fib
There are various wildcards which you may use. One is '*' which means 0 or more characters. e.g. 'B*' will match 'B,Bib and Baby' from the list above, another wildcard is '?' which matches 1 character, e.g. '?ib' will match 'Bib and Fib'. Wildcards differ depending on the program in use: awk derivatives (awk,sed,grep,ex,vi,expr and others) have the following special characters:- ^ beginning of the line
- $ end of the line
- . any character
- * one or more of the preceding character
- .* any number of characters
- \n Carriage return
- \t Tab character
- \<char> Treat <char> as is (so, \$ would try to match a '$')
Chargeable calls in bundle: $47.50
Chargeable calls out of bundle: $20.50
Other bundle charges: $0.00
Total Charge: $20.50
$ grep "^Charg.*bundle.*\$.*"
would match the first two lines.
In english - match all lines which start with 'Charg', then have any number of characters and then the word 'bundle', then have any number of characters, and then a dollar symbol, and then have any number of characters following to the end of the line
BASIC FILE HANDLING
- -l (long format)
- -a (list . files too)
- -r (reverse order)
- -t (newest appears first)
- -d (do not go beyond current directory)
- -i (show inodes)
Helpful keys for pg:
- 1 (go to top)
- $ (go to bottom)
- h (help)
- / (Search)
- ? (Search back)
- q (quit)
- -1 (back a page)
$ pwd
/usr/live/data/epx/vss2
To change the current working directory use cd
$ cp /etc/hosts /etc/hosts.backup # make a backup of the hosts file
$ cp /etc/motd /tmp/jon/ # Copy file /etc/motd to directory /tmp/jon/
Options
- -f (to force the copy to occur)
- -r (to recursively copy a directory)
- -p (to attempt to preserve permissions when copying)
$ mv /tmp/jon/handycommands.txt . # move handycommands in /tmp/jon to current directory
$ mv -f vihelp vihelp.txt # Move file vihelp to vihelp.txt (forced)
Options
- -f (to force the move to occur)
- -r (to recursively move a directory)
- -p (to attempt to preserve permissions when moving)
.
$ rm /tmp/jon/*.unl # remove all *.unl files in /tmp/jon
$ rm -r /tmp/jon/usr # remove all files recursively Options
- -f (to force the removal of the file)
- -r (to recursively remove a directory)
$ du /etc # list recursively all directories off /etc
712 /etc/objrepos
64 /etc/security/audit
536 /etc/security
104 /etc/uucp
8 /etc/vg
232 /etc/lpp/diagnostics/data
240 /etc/lpp/diagnostics
248 /etc/lpp
16 /etc/aliasesDB
16 /etc/acct
8 /etc/ncs
8 /etc/sm
8 /etc/sm.bak
4384 /etc The sizes displayed are in 512K blocks. To view this in 1024K blocks use the option -k
$ lp /etc/motd # send file /etc/motd to default printer
$ cat /etc/motd # display file /etc/motd to screen
*******************************************************************************
* *
* *
* Welcome to AIX Version 4.1! *
* *
* *
* Please see the README file in /usr/lpp/bos for information pertinent to *
* this release of the AIX Operating System. *
* *
* *
******************************************************************************* cat is also useful for concatenating several files. e.g.
$ cat fontfile IN* > newfile # appends fontfile and all files beginning with IN to newfileThough this might seem an essentially useless command, because most unix commands always take a filename argument, it does in fact come in extremely useful at more advanced levels. Awards are given out occasionally for the most useless usage of cat. If an option of '-' is specified, cat will take its input from stdin.
Subscribe to:
Posts (Atom)