Linux BASH command line options.
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4060
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
This list is from the great website Go to that page if you want to learn more on any one of these commands, on their site each command is hyperlinked to a fuller explanation, basically the help file for that command, plus some examples, which are very useful. We posted this here just to have the whole list in one place on our site, thanks ss64 for your great work in assembling this.

More advanced stuff on functions, found at the advance shell scripting guide. And here's more from

Very in depth resource from And more at

For debugging, see How to Debug Bash Scripts

For more bash information, look at the links in the following posts. You can also find a good beginners tutorial here. And here's a more in-depth bash tutorial.

:: Quote ::
An A-Z Index of the Linux BASH command line
A =============================
alias Create an alias
awk Find and Replace text within file(s)
B =============================
break Exit from a loop
builtin Run a shell builtin
C =============================
cal Display a calendar
case Conditionally perform a command
cat Display the contents of a file
cd Change Directory
chgrp Change group ownership
chmod Change access permissions
chown Change file owner and group
chroot Run a command with a different root directory
cksum Print CRC checksum and byte counts
clear Clear terminal screen
cmp Compare two files
comm Compare two sorted files line by line
command Run a command - ignoring shell functions
continue Resume the next iteration of a loop
cp Copy one or more files to another location
cron Daemon to execute scheduled commands
crontab Schedule a command to run at a later time
csplit Split a file into context-determined pieces
cut Divide a file into several parts
D =============================
date Display or change the date & time
dc Desk Calculator
dd Data Dump - Convert and copy a file
declare Declare variables and give them attributes
df Display free disk space
diff Display the differences between two files
diff3 Show differences among three files
dir Briefly list directory contents
dircolors Colour setup for `ls'
dirname Convert a full pathname to just a path
dirs Display list of remembered directories
du Estimate file space usage
E =============================
echo Display message on screen
ed A line-oriented text editor (edlin)
egrep Search file(s) for lines that match an extended expression
eject Eject CD-ROM
enable Enable and disable builtin shell commands
env Display, set, or remove environment variables
eval Evaluate several commands/arguments
exec Execute a command
exit Exit the shell
expand Convert tabs to spaces
export Set an environment variable
expr Evaluate expressions
F =============================
factor Print prime factors
false Do nothing, unsuccessfully
fdformat Low-level format a floppy disk
fdisk Partition table manipulator for Linux
fgrep Search file(s) for lines that match a fixed string
find Search for files that meet a desired criteria
fmt Reformat paragraph text
fold Wrap text to fit a specified width.
for Expand words, and execute commands
format Format disks or tapes
free Display memory usage
fsck Filesystem consistency check and repair.
function Define Function Macros
G =============================
gawk Find and Replace text within file(s)
getopts Parse positional parameters
grep Search file(s) for lines that match a given pattern
groups Print group names a user is in
gzip Compress or decompress named file(s)
H =============================
hash Remember the full pathname of a name argument
head Output the first part of file(s)
history Command History
hostname Print or set system name
I =============================
id Print user and group id's
if Conditionally perform a command
import Capture an X server screen and save the image to file
info Help info
install Copy files and set attributes
J =============================
join Join lines on a common field
K =============================
kill Stop a process from running
L =============================
less Display output one screen at a time
let Perform arithmetic on shell variables
ln Make links between files
local Create variables
locate Find files
logname Print current login name
logout Exit a login shell
lpc Line printer control program
lpr Off line print
lprint Print a file
lprintd Abort a print job
lprintq List the print queue
lprm Remove jobs from the print queue
ls List information about file(s)
M =============================
m4 Macro processor
man Help manual
mkdir Create new folder(s)
mkfifo Make FIFOs (named pipes)
mknod Make block or character special files
more Display output one screen at a time
mount Mount a file system
mtools Manipulate MS-DOS files
mv Move or rename files or directories
N =============================
nice Set the priority of a command or job
nl Number lines and write files
nohup Run a command immune to hangups
P =============================
passwd Modify a user password
paste Merge lines of files
pathchk Check file name portability
popd Restore the previous value of the current directory
pr Convert text files for printing
printcap Printer capability database
printenv Print environment variables
printf Format and print data
ps Process status
pushd Save and then change the current directory
pwd Print Working Directory
Q =============================
quota Display disk usage and limits
quotacheck Scan a file system for disk usage
quotactl Set disk quotas
R =============================
ram ram disk device
rcp Copy files between two machines.
read read a line from standard input
readonly Mark variables/functions as readonly
remsync Synchronize remote files via email
return Exit a shell function
rm Remove files
rmdir Remove folder(s)
rpm Remote Package Manager
rsync Remote file copy (Synchronize file trees)
S =============================
screen Terminal window manager
sdiff Merge two files interactively
sed Stream Editor
select Accept keyboard input
seq Print numeric sequences
set Manipulate shell variables and functions
shift Shift positional parameters
shopt Shell Options
shutdown Shutdown or restart linux
sleep Delay for a specified time
sort Sort text files
source Run commands from a file `.'
split Split a file into fixed-size pieces
su Substitute user identity
sum Print a checksum for a file
symlink Make a new name for a file
sync Synchronize data on disk with memory
T =============================
tac Concatenate and write files in reverse
tail Output the last part of files
tar Tape ARchiver
tee Redirect output to multiple files
test Evaluate a conditional expression
time Measure Program Resource Use
times User and system times
touch Change file timestamps
top List processes running on the system
traceroute Trace Route to Host
trap Run a command when a signal is set(bourne)
tr Translate, squeeze, and/or delete characters
true Do nothing, successfully
tsort Topological sort
tty Print filename of terminal on stdin
type Describe a command
U =============================
ulimit Limit user resources
umask Users file creation mask
umount Unmount a device
unalias Remove an alias
uname Print system information
unexpand Convert spaces to tabs
uniq Uniquify files
units Convert units from one scale to another
unset Remove variable or function names
unshar Unpack shell archive scripts
until Execute commands (until error)
useradd Create new user account
usermod Modify user account
users List users currently logged in
uuencode Encode a binary file
uudecode Decode a file created by uuencode
V =============================
v Verbosely list directory contents (`ls -l -b')
vdir Verbosely list directory contents (`ls -l -b')
W =============================
watch Execute/display a program periodically
wc Print byte, word, and line counts
whereis Report all known instances of a command
which Locate a program file in the user's path.
while Execute commands
who Print all usernames currently logged in
whoami Print the current user id and name (`id -un')
X =============================
xargs Execute utility, passing constructed argument list(s)
Y =============================
yes Print a string until interrupted
MISC ===========================
.period Run commands from a file
### Comment / Remark

Back to top
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
More Command Line :: bash resources
There's a nice system command line tutorial . That gives good examples, howtos, etc. They also have a linux file command tutorial as well. Both are from the linux howto articles at Here's a nice example:

:: Quote ::
$ find /home -name '*.out'

Remember, however, that you will probably get numerous "Permission denied" error messages unless you run the command as supersuser.
One of the most powerful search tools is the -exec action used with grep:
$ find . -name '*.html' -exec grep '' {} \;

Here we have asked find to start in the current directory, look for an html file, *.html, and execute -exec the grep command on the current file, {}. When using the -exec action, a semicolon, ;, is required, as it is for a few other actions when using find. The backslash, \, and quotes are needed to ensure that BASH passes these terms through so they are interpreted by the command rather than the shell.

Here's some more samples, more focused on shell scripting, if/switche etc, this one is at
And here's another tutorial, covers more general areas, including a good explanation of the linux file system:
:: Quote ::
/bin Essential user command binaries (for use by all users)
/boot Static files of the boot loader, only used at system startup
/dev Device files, links to your hardware devices like /dev/sound, /dev/input/js0 (joystick)
/etc Host-specific system configuration
/home User home directories. This is where you save your personal files
/lib Essential shared libraries and kernel modules
/mnt Mount point for a temporarily mounted filesystem like /mnt/cdrom
/opt Add-on application software packages
/usr /usr is the second major section of the filesystem. /usr is shareable, read-only data. That means that /usr should be shareable between various FHS-compliant hosts and must not be written to. Any information that is host-specific or varies with time is stored elsewhere.
/var /var contains variable data files. This includes spool directories and files, administrative and logging data, and transient and temporary files.
/proc System information stored in memory mirrored as files.

By the way, there's a really good newbie to 'just wanting a quick review/overview' tutorial of bash/sh programming. [note: that site was using a copyrighted book, so it's been taken down.]

Usually I'm not a huge SAMS press fan, in fact I dislike most of their stuff, but this is a nice online manual that will be very useful to anyone wanting to get into, or improve, their bash / sh skills.

Which means most of us, LOL...

:: Quote ::
One of the main strengths of UNIX is that it comes with a large collection of standard programs. These programs perform a wide variety of tasks from listing your files to reading email. Unlike other operating systems, one of the key features of UNIX is that these programs can be combined to perform complicated tasks and solve your problems.

One of the most powerful standard programs available in UNIX is the shell. The shell is a program that provides you with a consistent and easy-to-use environment for executing programs in UNIX. If you have ever used a UNIX system, you have interacted with the shell.

The main responsibility of the shell is to read the commands you type and then ask the UNIX kernel to perform these commands. In addition to this, the shell provides sophisticated programming constructs that enable you to make decisions, repeatedly execute commands, create functions, and store values in variables.
The simple tools are easy to learn. You probably already know how to use many of them. The power tools take longer to learn, but when you get the hang of them, you’ll be able to tackle any problem. This book teaches you how to use both the simple tools and the power tools. The main focus is on the most powerful tool in UNIX, the shell.

This is a really nice online book, it includes pretty much everything you'd want to know if you're starting out, including a brief history of shells, what they are, how they started, who made them, and all that.

It's nice to know for example just what the difference between a bash shell and a sh shell is.

I also have to admit that I wasn't even completely clear on exactly what a shell is in the first place, technically speaking, this book completely explained it, in a way that made total sense to me.

The best thing, however, is that, like most SAMS books, this one is really too simple, but since it's online, you don't have to buy it, you just run through all the chapters and examples, and at the end, you'll have a decent idea of how to use your command line shell prompt, and you'll even have a decent idea of just what all those commands, like ls, cp, rm, mv, awk, grep, |, and so on, actually do.
Back to top
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4060
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
Regular Expressions
Here's a nice regex introduction, covers, with good examples, use of grep especially, or egrep. That's very useful stuff, I am still learning how to use grep + regex more effectively.

Here's another one on Regular Expressions.

Special characters and variables
And here's one on Special Characters

And on all those weird escape things, Escaping, like this one:
:: Code ::

And the truly surreal, and super slow, by the way, Parameter Substitution, where the weird netherworlds of bash can be dived into:
:: Code ::
echo "a = $a"      # a = xyz

echo "var02 = ${var02}"
echo "Length of var02 = ${#var02}"

strip_leading_zero () #  Strip possible leading zero(s)
{                     #+ from argument passed.
  return=${1#0}       #  The "1" refers to "$1" -- passed arg.
}                     #  The "0" is what to remove from "$1" -- strips zeros.

but don't spend much time here or you'll go insane, like the authors of bash obviously did.

sed and other string manipulations
While researching a particularly complex function, I came across some good resources for string manipulations:
Sed - An Introduction and Tutorial
Advanced Shell Scripting: sed
Advanced Shell Scripting:Text Processing Commands

The last is good for an overview of all the main stuff, grep, cut, uniq, sort, and so on. The first sed item is a very in-depth overview of sed and how to use it, it helped me solve a very complex problem with relatively little pain.

Math / Arithmetic Functions
And if you want to do some arithmetic or math, here's a decent math howto. This uses the enormously cleverly named bc and cd programs.

:: Code ::
number=($(dmesg|grep hd -c)/2);echo $number | bc -l

Will give output of the number / 2, as expected.

If you didn't use the bc piped, it gives you something like this: 12/2

Which is not what you want.

Timer functions
And of course you'll be needing to do some timer stuff, you can get a good list of timer functions. I especially like usleep and sleep, which basically let you fine tune bash to make it wait as long as you want. Easy to implement, put a pause of specified length into your scripts.

Advanced Information
Excellent overview of Internal Commands and Builtins. Covers set, unset, exit, I/O, echo, printf, read, let (for arithmetic), eval, getopts, and assorted other things you thought you knew but probably don't.

Good one on bash console colors
Here's more specific stuff, this one on input/output redirection.
Read on getopts[
more on grep

complex comparison, like 5.43 > 5.42, thanks to
:: Code ::
x=3.1; y=3.2; echo "$x $y" | awk '{if ($1 > $2) print $1; else print $2}'

Check variables set
This is a neat trick:
:: Code ::
> How do I check if an environment variable is set?

[ -n "${VAR+x}" ] ## Fails if VAR is unset

[ -n "${VAR:+x}" ] ## Fails if VAR is unset or empty

[ -n "${VAR-x}" ] ## Succeeds if VAR is unset

[ -n "${VAR:-x}" ] ## Succeeds if VAR is unset or empty

Thanks to for that one.
Back to top
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4060
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
from here:

Bash string padding with SED
technology.pngI know, I mentioned a bit of this earlier, but it deserves its own post.

You can left and right pad strings in BASH with spaces using SED. You do not have to use printf or anything else (despite what everyone else says).(Derived from instructions here ( ) , which talk more about centering than padding.)

This is the important part of the code:
:: Code ::
Left justify with string length of 80
sed -e :a -e 's/^.\{1,80\}$/& /;ta'
Right justify with string length of 80
sed -e :a -e 's/^.\{1,80\}$/ &/;ta'
Center with string length of 80.
sed -e :a -e 's/^.\{1,80\}$/ & /;ta'

Back to top
Display posts from previous:   

All times are GMT - 8 Hours