Você está na página 1de 4

CS246Linux Command Summary

Commands
Command
exit
passwd
clear
man command

Meaning
log out
change your password
clear screen
show the manual page for command

history
!!

show all previously-issued commands


execute most recently-issued command
execute most recently-issued command starting with c
display your login name
display current date and time
display current directory
list contents of current directory

!c
whoami
date
pwd
ls
cp file1 file2
mv file1 file2
rm file
touch 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

copy file1 to file2


move file1 to file2 (also use to rename)
remove file
update files last modified time to current time
change directory to dir
create new directory dir in current directory
remove directory dir
display string to screen
set permissions on file to perms
change personal info (name, address,
etc.) on Unix system
change your login shell
display current processes
kill process with number pid
show who is logged into this machine
show personal info for username
show amount of time taken executing
command
bring background job to the foreground
find all files whose names match pattern in dir and its subdirectories

Options

man -k word
mention word

show a list of man pages that

ls -a
show all files, including hidden files
ls -l
show in long format
cp -r dir1 dir2
recursively copy dir1 to dir2

can be used to recursively remove a directory, if -r


option is used
can be used to create an empty file if file does not exist
cd return to most recently visited directory
can specify more than one directory at once
only works if dir is empty; if not empty, use rm -r dir ;
can specify more than directory at once

ps -a
show all users processes
ps -A
show ALL processes (incl. system processes)
kill -9 pid
more forceful kill, for stubborn processes

useful if you accidentally ran vi or emacs with an &

Tools
Tool
cat f1 f2 ...
more file
diff f1 f2
cmp f1 f2
wc file

egrep pat file


head file
tail file
sort file
uniq 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
print all lines in file that contain pattern pat
print first 10 lines of file
like head, but prints last 10 lines of
file
sorts the lines of file
removes consecutive duplicate lines
from file

Options
cat -n f1 f2 ...

diff -w f1 f2

attaches line numbers

ignores whitespace

wc -c file
show just the number of characters
wc -l file
show just the number of lines
wc -w file
show just the number of words
egrep -n pat file
print matching lines with line numbers
egrep -v pat file
print lines that do not match pat
-num prints num lines (e.g. head -5 file)

sort -n file sorts strings of digits in numerical order


removes all duplicates if file is sorted

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

checks the print queue


removes job jobno (must belong
to you!) from print queue
make SSH connection to machine; opens a secure shell on remote machine; type exit to end
SSH connection
securely copy file1 on mach1 to
file2 on mach2

ssh machine

scp mach1 :file1 mach2 :file2

Options

lpr -Pljp 3016 file


MC3016

specifies the printers in

ssh -Y (or -X) machine


enable X forwarding
(must have X server running on local machine)

can omit mach1 if it is the local machine; similarly


for mach2

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)

Script Conditional Operators


Operator
=
!=
-eq
-ne
-gt
-ge
-lt
-le
-a
-o
!
\(, \)
-d
-e
-f
-r
-w
-x

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)

Directories
Directory
.
..
~
/
Starts with / or ~
Does not start with / or ~

Meaning
Current directory
Parent of current directory
Your home directory
Root directory
Absolute path
Relative path

Você também pode gostar