Previous Table of Contents Next


EXAMPLE COMMANDS

# Execute multiple commands on one line
  $ pwd ; ls tmp ; print "Hello world"
# Run the find command in the background
  $ find . -name tmp.out -print &
# Connect the output of who to grep
  $ who | grep fred
# Talk to fred if he is logged on
  $ { who | grep fred ; } && talk fred
# Send ls output to ls.out, even if noclobber is set
  $ ls >| ls.out
# Append output of ls to ls.out
  $ ls >> ls.out
# Send invite.txt to dick, jane, and spot
  $ mail dick jane spot < invite.txt
# List file names that begin with z
  $ ls z*
# List two, three, and four character file names
  $ ls ?? ??? ????
# List file names that begin with a, b, or c
  $ ls [a-c]*
# List file names that do not end with .c
  $ ls *[!.c]
# List file names that contain any number of consecutive x's
  $ ls *(x)
# List file names that contain only numbers
  $ ls +([0-9])
# List file names tha do not end in .c, .Z, or .o
  $ ls !(*.c|*.Z|*.o)
# Set NU to the number of users that are logged on
  $ NU=$(who | wc -l)
# Set HOSTS to the contents of the /etc/hosts file
  $ HOSTS=$(</etc/hosts)
# Set TOTAL to the sum of 4 + 3
  $ TOTAL=$((4+3))
# Change directory to jane's home directory
  $ cd ~jane
# Set the right-justify attribute on variable SUM and set it to 70
  $ typeset -R SUM=70
# Set and export the variable LBIN
  $ typeset -x LBIN=/usr/lbin
# Set the field width of SUM to 5
  $ typeset -R5 SUM
# Remove the lowercase attribute from MSYS
  $ typeset +l MSYS
# Unset variable LBIN
  $ unset LBIN
# Display the length of variable FNAME
  $ print ${#FNAME}
# Set SYS to the hostname if not set, then display its value
  $ print ${SYS:=$(hostname)}
# Display an error message if XBIN is not set
  $ : ${XBIN:?}
# Display the base directory in LBIN
  $ print ${LBIN##*/}
# Set array variable MONTHS to the month names
  $ set -A MONTHS jan feb mar apr may . . . dec
# Display element 3 of the XBUF array variable
  $ print ${XBUF[3]}
# Display the length of the TMP array element 2
  $ print ${#TMP[2]}
# Display $HOME set to /home/anatole
  $ print '$HOME set to' $HOME
# Display the value of $ENV
  $ print $ENV
# Display the last five commands from the history file
  $ history -5
# Retrieve last print command in vi edit mode
  $ set -o vi; <ESCAPE>/^print<RETURN>
# Bring background job 3 into the foreground
  $ fg %3
# Display all information about current jobs
  $ jobs -l
# Terminate job 5
  $ kill %5
# Increment variable X
  $ integer X; ((X+=1))
# Set variable X to 5 in base 2
  $ typeset -i2 X=5
# Set variable X to 20 modulo 5
  $ ((X=20%5))
# Set Y to 5*4 if X equals 3
  $ ((X==3 && (Y=5*4)))
# Terminate the Korn shell if no input given in 30 minutes
  $ TMOUT=1800
# Automatically export variables when defined
  $ set -o allexport
# Set diagnostic mode
  $ set -x
# Create an alias for the ls command
  $ alias l='ls -FAc | ${PAGER:-/bin/pg}'
# Create a tracked alias for the cp command
  $ alias -t cp
# Put the command number and current directory in the prompt
  $ typeset -x PS1="!:$PWD> "
# Check if variable X is set to a number
  $ [[ $X = +([0-9]) ]] && print "$X is a number"
# Check if VAR is set to null
  $ [[ -z $VAR ]] && print "VAR is set to null"
# Check if FILE1 is newer than FILE2
  $ [[ $FILE1 -nt $FILE2 ]]
# Check if VAR is set to ABC
  $ [[ $VAR = ABC ]]
# Check if the bgnice option is set
  $ [[ -o bgnice ]] && print "bgnice option set"
# Check if TMP is a readable directory
  $ [[ -d $TMP && -x $TMP ]]
# Check the number of arguments
  $ (($# == 0)) && { print "Need arg"; exit 1; }
# Display an error message, then beep
  $ print "Unexpected error!\a"
# Display a message on standard error
  $ print -u2 "This is going to standard error"
# Write a message to the command history file
  $ print -s "su attempted on $(date)"
# Take standard input from FILE
  $ exec 0<FILE
# Open file descriptor 5 for reading and writing
  $ exec <>5
# Display a prompt and read the reply into ANSWER
  $ read ANSWER?"Enter response: "
# Create a function md that creates a directory and cd's to it
  $ function md { mkdir $1 && cd $1 ; pwd }
# Set a trap to ignore signals 2 and 3
  $ trap "" 2 3
# Run dbtest in noexec mode
  $ ksh -n dbtest
# Set a trap to execute pwd after each command
  $ trap "pwd" DEBUG
# Set X to 1 and make it readonly
  $ readonly X=1
# Set VAR to 1 and export it
  $ export VAR=1
# Set the positional parametersto A B C
  $ set A B C
# Set the file size creation limit to 1000 blocks
  $ ulimit 1000
# Disable core dumps
  $ ulimit -c 0
# Add group write permission to the file creation mask
  $ umask 013
# Return information about the true command
  $ whence -v true


Previous Table of Contents Next
1