Bourne/Bash/Korn Commands

A Short Catalog of Bourne/bash/Korn Shell Commands

Command
OS
Description
Example
Explanation
alias Creates an “alias” for a command and set of options alias rm=”rm -i” Set in .bashrc, forces deletes into interactive mode
cancel -a printer Removes all print requests from the current user on the specified printer cancel -a bobsprt Removes all the requests from the current user to the printer named bobsprt
cancel request_id Stops print jobs or removes them from the queue (request_ids are obtained using lpstat) cancel 5438 Stops the print job with the id 5438 whether it is printing or if it is sitting in the queue
cancel -u login_id Removes any print requests queued belonging to the user cancel -u bob Cancels all queued print requests for user bob
cat file Prints a file to the screen (all at once). Use more or less to see a page at a time. cat /etc/passwd Prints the password file to the screen.
cat file1 file2 file3 Think “concatenate” – Shows the three files in consecutive order as one document (can be used to combine files) cat cheese milk This prints the cheese file to the screen first and immediately follows it with the milk file.
cd directory Changes your current directory to the directory specified cd bin Changes directory to the bin directory
For example, if current directory=/home/users/bob/bin and you execute cd .. the new directory will be = /home/users/bob cd .. Moves you to the directory that contains the directory you are currently in
or executing cd ../.. results in the new directory= /home/users. cd ../..
cd – Moves you to the directory you just came from
cd ~ Moves you to your home directory (the directory you start from initially)
cd Moves you to your home directory (the directory you start from initially)
chexp # filename Keeps the file(s) from expiring (being erased) on the target computer for # days chexp 365 nr* Keeps the target computer from deleting all files starting with nr for 1 year (365 days)
chexp 4095 nr* Makes all files whose name starts with nr never expire or be deleted (infinite)
clear Clears the window and the line buffer clear None
compress filename Compresses the file to save disk space. none None
cp -f name target Forces existing pathnames to be destroyed before copying the file none No example or description needed
Copies a file (file1) and names the copy the new name (newname) cp old new Makes a copy of the file/directory named old and names the copy new, all within the current directory
NOTE: If you copy a file to a newfile name and newfile already exists, the newfile contents will be overwritten.
cp file dir2/ Places a copy of file in dir2/ and it retains its original name
cp ../dir1/* . Copies everything from the dir1 directory located just below where you currently are and places the copy “here” ( . ) in your current directory
NOTE: When clicking in the scroll bar, the left button scrolls down, the right scrolls up, and the middle snaps the scroll bar to the mouse position for dragging up and down.
cp -p name target Preserves all permissions in the original to the target cp -p execut1 execut2 Copies execut1 executable file and calls the copy execut2, which also has executable permissions
cp -R directory target Copies a directory and names the copy the new name (target) cp -R old/ junk/ Makes a copy of the directory named old and names the directory copy junk
cut cuts characters or fields from a file cut -f1 myfile Returns the first field (tab-delimited) of each line of myfile
cut -c1 myfile
cut -c1-8 myfile
Returns the first character, or chars 1-8, of myfile
cut -f2 myfile Returns the second field of each (tab-delimited) line of myfile
cut -d: -f1 myfile Returns the first field of a colon-delimited myfile (any delimiter may be specified)
date Writes the current date to the screen date Mon Nov 20 18:25:37 EST 2000
df system Reports the number of free disk blocks df ~ , df $HOME Both commands will print the total kb space, kb used, kb available, and %used on the home system (your system).
dir Same as ls -la ; adopted from DOS! dir
du Disk usage: du -sc Dumps information about file system size, i.e. disk usage
echo Prints text to the terminal echo “Hello”
echo *
Prints “Hello”
Prints a directory listing (surprise)
See the excellent SS64.com page.
ed The line editor utility
emacs filename Another text editor none None
eval `resize` Tells the target computer that you’ve resized the window during telnet none None
fdisk, sfdisk, cfdisk Utility for partitioning disks fdisk Opens a user interface to manage disk partitions
find Finds files on disk find / -name file_name Specify a location to start in the first argument. Use -name to search for a file name.
finger Displays info about all system users finger
finger username Displays info about username finger glenn
fsck Performs a file system check (similar to checkdisk)
grep grep is useful when you use it in a | “pipe” ps -ef | grep bob Finds all processes in full listing and then prints only the ones that match the string bob to the screen
You can also redirect its output to a file. grep -i jan b_days>mymonth Searches the file b_days for case-insensitive matches to jan and places the matching lines into a file called mymonth
grep -c string file Searches and prints only the number of matches to the screen grep -c hayes bankletter Searches the file bankletter for the string hayes and prints the number of matches to the screen
grep -i string file Searches without regard to letter case grep -i hi file1 Searches file1 for hi, Hi, hI, and HI and prints all matches to the screen
grep -n string file Prints to the screen preceded by the line number grep -n abc alpha Searches alpha for abc and prints the matches’ lines and line numbers to the screen
grep string file Searches input file(s) for specified string and prints the line with matches grep mike letter Searches for the string mike in the file named letter and prints any line with mike in it to the screen
grep -v string file All lines that do not match are printed grep -v lead pencils Prints all lines in pencils that do not contain the string lead
grep -x string file Only exact matches are printed grep -x time meetings Prints only lines in meetings that match time exactly
head file Prints the first 10 lines of the file to the screen head addresses Prints the first 10 lines of addresses to the screen
Number of lines can be modified head -25 addresses Prints the first 25 lines of addresses to the screen
help Lists shell commands (not scripts) help Prints a listing of built-in shell commands
history Prints your command history
id Prints your user id info id
info Gives help on built-in shell commands
kill -9 process_id Destroys the process with the said id kill -9 6969 PID # 6969 doesn’t have a chance here.
kill process_id Stops the process with the said id kill 6969 Kills the process with PID 6969
killall process_name Kills all processes with the provided name killall httpd Kills all httpd processes
lilo Linux Loader lilo reinstalls LILO in the boot sector, after editing lilo.conf
linuxconf The Linux Configurator linuxconf
lp (-option) file(s) Like pr, this prints designated files on the connected printer(s) (options not required and options may be combined). lp junkfile Prints the file junkfile to the default printer in default one-sided, single-sided, single-spaced format
lp -ddest file(s) Prints the file(s) to a specific destination lp -dbobsq zoom Sends the file zoom to the bobsq print queue to print
lp -nnumber file(s) Allows user to designate the number of copies to be printed lp -n5 crash Prints five copies of crash in default settings
lp -ooption file(s) lp -ohalf output Divides the paper into two halves for printing output
lp -oquarter output Prints four pages of output per side of paper
lp -olandscape output Prints output in landscape orientation
lp -oportrait output Prints output in portrait orientation
Allows printer-specific options to be used (i.e., double-sided or two pages per side, etc.) lp -od output Prints the output file double-sided on the printout
lp -obold output Prints output in bold print
lp -ttitle file(s) Places title on the banner page lp -tBobs cash Prints Bobs on the banner page of the file printout named cash
lpconfig -d queue Makes the said queue the default queue lpconfig -d vpprnt Makes vpprnt the default print queue
lpconfig printer_id queue Configures remote printers to a local print queue lpconfig prntr1 bobprt Configures a printer named prntr1 to accept print requests from a local queue named bobprt
lpconfig -r queue Removes the said queue from the local system lpconfig -r bobprt Removes bobprt queue from the local system if the person removing the queue is the owner or “root”
lpstat (-options) Prints printer status information to screen (options not required) lpstat Prints status of all requests made to the default printer by the current server
lpstat -d Shows the default printer for the lp command none None
lpstat -r Lets you know if the line printer scheduler is running none None
lpstat s Prints the queues and the printers they print to none None
lpstat -t Shows all print status information none None
lpstat -u”user1, user2″ Prints the status of requests made by the specified users lpstat -u”bob” Prints status of all requests made by the user with the id bob
ls (-option-optional) Lists all the nonhidden files and directories ls Lists all nonhidden files and directories in the current directory
ls (-option-optional) ls bin Lists all nonhidden files and directories in the bin directory
ls -a Lists all files and directories including hidden ones ls -a Lists all files and directories, including hidden, in the current directory
ls -a temp Lists all files and directories in the temp directory.
ls -al NOTE: Options can be combined using ls Lists all files (including hidden (-a)) in long format (-l)
ls -l or ll Lists all nonhidden files and directories in long format ls -l Lists all nonhidden files and directories in the current directory in long format
ll
ls -l work Lists all nonhidden files and directories in the work directory in long format
ll work
ls -r Lists all files and directories in reverse alphabetical order ls -r Lists all nonhidden files and directories in the current directory in reverse alphabetical order
ls -r abc Lists all nonhidden files and directories in the abc directory in reverse alphabetical order
ls -t Lists all nonhidden files in the order they were last modified ls -t Lists all the nonhidden files in the current directory in the order they were last modified from most recent to last
ls -t work Lists all the nonhidden files in the work directory in the order they were last modified from most recent to last
make compilecommand Performs the pre-compile and compile functions make Used at several stages of compilation. Used in preparing a custom Linux kernel.
mc
minicom Opens a graphical utility in a shell, which is used to test PPP connections like modems.
mkdir dirname Creates a directory mkdir junk Makes a directory named junk in your current directory
You can also designate where the directory is to reside. mkdir ~/left Makes a directory in your home directory named left
modprobe Adds a kernel module while running

modprobe module

modprobe -r module

modprobe -a

modprobe -k

Loads module

Removes module

Lists all modules

Auto-cleans all modules

more input This prints to screen whatever is input-useful because it only shows one screen at a time. more groceries This will list the groceries file to the screen.
scroll bar continues to the next screen
return moves one line forward
Q quits
G goes to the end
1G goes to the beginning
Ctrl u moves up ½ screen
Ctrl d moves down ½ screen
mount drive Mount a drive mount /mnt/cdrom Mounts the CDrom drive
mouseconfig Sets up the mouse mouseconfig
mv initial final Renames files and directories mv temp script_1 Renames the file (or directory) temp to the name script_1 in the current directory
Also moves files to other directories mv script.exe ~/bin Moves the script.exe file to the bin directory that is in the home (~) parent directory and it keeps its initial name
You can do multiple moves. mv script_1 script.exe ~/bin Moves both script_1 and script.exe to the bin directory
netcfg Configure the network; not found on all Linux systems, but common on other Unix like Solaris netcfg
nislookup Returns DNS information nislookup google.com Returns the IP address if DNS is working
dhclient DHCP client program
passwd Change your password pswd
paste Paste corresponding lines of files together paste file1 file2 Outputs line 1 of file1 “pasted” to line 1 of file2, and so forth line by line
pr -h “header” filename Prints the file with a specified header rather than the filename pr -h “users” userlist Prints userlist with users as the header
pr (option) filename Prints the specified file to the default printer (options are not required but can be combined in any order) Options can be combined using pr pr userlist Prints the contents of userlist to the default printer
pr +k filename Starts printing with page k pr +5 userlist Prints the contents of userlist starting with page 5
pr -a filename Prints in multicolumns across the page (use with -k) pr -3a userlist1 Prints userlist in three columns across the page
pr -d filename Prints in double space format pr -d userlist Prints userlist with double space format
pr -k filename Prints in k columns pr -2 userlist Prints the contents of userlist in 2 columns
ps Shows certain information about active processes associated with the current terminal ps Shows a listing of process IDs, terminal identifier, cumulative execution time, and command name
ps -e Shows information about all processes ps -e Shows a listing of process IDs, terminal identifiers, cumulative execution time, and command names for all processes
ps -ef Shows all processes in a full listing ps -ef Shows all current processes in full listing
ps -f Shows a full listing of information about the processes listed ps -f Shows UID (user or owner of the process), PID (process ID–use this number to kill it), PPID (process ID of the parent source), C (processor utilization for scheduling), STIME (start time of the process), TTY (controlling terminal for the process), TIME (cumulative time the process has run), and COMMAND (the command that started the process)
ps -u user_id Shows all processes that are owned by the person with the pertinent user_id ps -u bob Shows all the processes that belong to the person with the userid bob
pump RH7 and older

A BOOTP and DHCP client daemon

pump Renews DHCP lease
pwd Prints the current directory to the screen pwd May print something like “/home/bob”
qstat Displays the status of a process that has been submitted the Network Queuing System (basically a batch job) qstat Shows the status of the requests submitted by the invoker of the command-this will print requestname, requestid, the owner, relative request priority, and request state (is it running yet?)
qstat -a Shows all requests
qstat -l Shows requests in long format
qstat -m Shows requests in medium-length format
qstat -u bob Shows only requests belonging to the user bob
qstat -x Queue header is shown in an extended format
read Captures user input echo -n “Enter the name of an animal: “
read ANIMAL
echo -n “You are a(n) $ANIMAL”
restart /etc/init.d/nfs restart Restarts a service, in this cast the nfs
rm -f file1 file2 rm xyz abc Deletes the files named xyz and abc
rm * Deletes everything nonhidden
Forces deletion without prompt regardless of permissions rm -f program Removes the file program without regard to permissions, status, etc.
rm file1 file2 file3 Removes (deletes) file(s) NOTE: Options can be combined using rm rm xyz Deletes a file named xyz
rm -fR name, rm -Rf name ****dangerous**** This combination will force the removal of any file and any directory including anything inside of it rm -Rf c_ya Forces removal without prompts of the c_ya directory and anything inside of it
rm -i file1 file2 Prompts before deletion of files. *******USE -i AT FIRST******* rm -i * Prompts at each nonhidden file and lets you decide whether or not to delete it
rm -r directory, rm -R directory Remove a directory along with anything inside of it rm -r bin , rm -R bin Each of these will remove the bin directory and everything inside of it.
rm -Ri directory Deletes the contents of a directory and the directory if it is empty by prompting the user before each deletion rm -Ri rusure Deletes anything in the directory called rusure that you verify at the prompt, and if you remove everything in the directory, you will be prompted whether you want to remove the directory itself or not
rmdir directory Removes a directory like rm -r does if the directory is empty rmdir bin Removes the bin directory if it is empty
rmdir -p directory Removes a directory and any empty parent directories above it (-pi does the same thing but it prompts before each removal) rmdir -p /home/bin/dir1 Deletes the dir1 directory; if bin directory is empty, it is deleted, and if home directory is empty it is also deleted
sed The stream editor sed ‘s/Unix/UNIX/’ source_file/g Replaces Unix with UNIX in source_file
sort infile Sorts the contents of the input file in alphabetical order sort names Sorts the contents of names in alphabetical order
tail file Prints the last 10 lines of the file to the screen tail test.txt Prints the last 10 lines of test.txt to the screen
Number of lines can be modified here, too tail -32 test.txt Prints the last 32 lines of test.txt to the screen
test expression Tests a condition, and returns 0 (success) if it passes, non-0 if it fails test See Operators for a fuller listing
Used in if operations if test $name = Julio; then
test string = string
test string != string tests inequality
if test string ; then tests for the existence of string
test -n string string is not null
test -z string string is null
test int1 -eq int2 int1 equals int2
test int1 -ge int2 int1 greater than or equal to to int2
test int1 -gt int2 int1 is greater than int2
test int1 -le int2 int1 is less than or equal to int2
test int1 -lt int2 int1 is less than int2
test int1 -ne int2 int1 is not equal to int2
test -d file file is a directory
test -e file file exists
test -f file file is a regular file
test -r file file is readable by the process
test -s file file has nonzero length
test -w file file is writable by the process
test -x file file is executable
test -L file file is a symbolic link
timeconfig Configure the time service timeconfig
touch Update the last-modified date of the file named touch myfile If myfile exists, last-modified date is updated to now; if myfile doesn’t exist, it is created
type Find out where a bash command is taken from (cf. which); tells if an executable is a binary, script or link type bash bash is /bin/bash
type -a Print all locations of a command type -a bash
uncompress filename Expands a compressed file none
uptime Displays time the system has been running uptime
useradd Add a user to the domain useradd
users Lists current users users Lists all users on a single line
vi filename Text editor that exists on every UNIX system in the world none
vuepad filename Opens filename for editing/viewing in the vuepad editor none
which Prints the locations of shell commands (cf. type)
who Tells you who is logged onto your server who -imH Lists each user on a separate line, along with session information
who am I Tells you your user information who am I , whoami
Xconfigurator An X-Windows configuration tool Xconfigurator This opens an interface to configure your video card and monitor.
xterm Opens a new window (x-terminal) for you to work xterm This opens another window like the one you are currently working in.
Note: The size of the window takes precedence over position, so if you position it too close to the side of the screen, it will position at the edge with the correct size. xterm -geom 5×5+0+0 The third command will make a 5 by 5 window and position its top left-hand corner at the top left-hand corner of the screen. xterm will not compromise size when positioning.
xterm -bd huntergreen The second command sets the window border color to huntergreen.
xterm -fg red
Position +0+0 is the top left-hand corner of the screen, and the bottom right is approx. +1200+1000 depending on your resolution. xterm -geom 10×35+300+500 The second command will open a window 10 pixs wide by 35 pixs tall and position its top left-hand corner 300 pixs from the left edge and 500 pixs down from the top.
xterm -(areas) color Allows you to modify different colors in your xterm window xterm -bg white The first command sets the background color to white.
xterm +option +option resets the option to default Options can be combined using xterm
xterm -e program Executes the listed program in the new xterm window-when the program is finished, the new xterm window goes away xterm -e myprog.exe This opens an xterm window and executes the program myprog.exe from that window so that you may still work in your present window.
xterm -fn font Sets the font in the new xterm window xterm -fn courr18 Sets the font to courr18 (default is fixed)
xterm -geom xxy+px+py This option allows you to specify the size x pixels by y pixels and placement position x by position y of the new window when it opens. xterm -geom 80×80+0+50 The first command will open a window 80 pixels wide by 80 pixels tall and position its top left-hand corner at 0 pixels to the right of the left edge and 50 pixels down from the top of the screen.
xterm -help Displays the xterm options xterm -help Shows the options available
xterm -iconic Starts the new xterm as an icon (double-click to maximize) xterm -iconic -title xyz Opens an xterm in iconic form with the title xyz
xterm -option -option sets the option USING XTERM WILL ELIMINATE A LOT OF DESKTOP CLUTTER. I STRONGLY SUGGEST YOU LEARN TO USE IT IN YOUR SCRIPTS.
xterm -sb Opens an xterm that saves a set number of lines when they go off the top of the page and makes them accessible with a scroll bar xterm -sb Puts a scroll bar on the right side of the page for reviewing past lines in the window
xterm -sl number Specifies the number of lines to be saved once they go off the top of the screen (default is 64) xterm -sl 1000 The xterm will save 1,000 lines of work once it has moved off the immediate viewing area; it can be accessed using the scroll bar.
xterm -title label Allows you to label your window’s top title bar xterm -title SCRIPTS Opens an xterm window with the title SCRIPTS (default is whatever follows the -e option)