CS246-Linux Command Summary: Commands
CS246-Linux Command Summary: Commands
Fall 2014
Commands
Command
exit
passwd
clear
man command
Meaning
log out
change your password
clear screen
show the manual page for command
history
!!
!c
whoami
date
pwd
ls
cp file1 file2
mv file1 file2
rm file
cd dir
mkdir dir
rmdir dir
echo string
chmod perms file
chfn
chsh
ps
kill pid
who
finger username
time command
fg
find dir -name pattern
Options
man -k word
mention word
ls -a
show all files, including hidden files
ls -l
show in long format
cp -r dir1 dir2
recursively copy dir1 to dir2
ps -a
show all users processes
ps -A
show ALL processes (incl. system processes)
kill -9 pid
more forceful kill, for stubborn processes
Tools
Tool
cat f1 f2 ...
more file
diff f1 f2
cmp f1 f2
wc file
Purpose
display files f1, f2, ... one after the
other
display file one screen at a time
compare files f1 and f2 ; outputs instructions for converting f1 to f2
compare files f1 and f2 ; outputs the
first position where they differ
count the number of words, lines, and
characters in file
sort file
uniq file
Options
cat -n f1 f2 ...
diff -w f1 f2
wc -c file
wc -l file
wc -w file
grep -E pat
grep -n pat
grep -v pat
ignores whitespace
Programs
Program
vi file
emacs file
pico file
pine (or alpine)
wget url
xpdf file
lpr file
Purpose
invoke vi text editor on file
invoke emacs text editor on file
invoke pico text editor on file
read email
fetch file from the web at url
display pdf file
print file to printer
lpq
lprm jobno
ssh machine
Options
Variables
Variable
${PWD}
${HOME}
${SHELL}
${PRINTER}
${PATH}
${$}
${0}
${1}, ${2}, . . .
${#}
${@}
${?}
Meaning
present working directory (equivalent to executing pwd)
your home directory (equivalent to )
your default shell
your default printer
your default search path for commands
current scripts process ID
name of currently-running script
arguments 1, 2, . . . of current script/function
number of args supplied to currently-running script/function (not including script name)
all args supplied to currently-running script/function as separate strings (not including script name)
return code of most recently-executed command/function
Permissions
Symbol
u
g
o
a
+
=
r
w
x
Meaning
files owner
members of the files group, other than the owner
other users
all users (equivalent to ugo)
add permission bit
revoke permission bit
set permission bits exactly
read permission. for filesfiles contents can be read. for directoriesdirectorys contents can be
listed
write permission.
for filesfiles contents can be modified.
for directoriesfiles can be
added/renamed/removed in the directory
execute permission. for filesfile may be executed as a program or script. for directoriesdirectory
can be traversed (i.e. can cd into the directory)
Meaning
string equality
string inequality
integer equality
integer inequality
integer greater than
integer greater than or equal to
integer less than
integer less than or equal to
and
or
not
parentheses for grouping
file exists and is a directory
file exists
file exists and is a regular file
file exists and is readable
file exists and is writable
file exists and is executable
Globbing Patterns
Operator
*
?
[abxy]
[!abxy]
[a-z]
{pat1,pat2}
Meaning
matches 0 or more characters
matches one character
matches exactly one of the characters in brackets
matches any character except the ones in the brackets
matches any character in the given range
matches either pat1 or pat2 (technically not a glob; note no spaces)