Linux Command Line
Linux Command Line
Command
Description
# apt-get update
# apt-get upgrade
# apt-get check
# apt-get clean
[man]
[man]
[man]
[man]
[man]
Command
Description
# bunzip2 file1.bz2
[man]
# bzip2 file1
# gunzip file1.gz
# gzip file1
# gzip -9 file1
# rar x file1.rar
extract a tarball
[man]
[man]
[man]
[man]
[man]
[man]
[man]
[man]
[man]
[man]
[man]
[man]
[man]
# unrar x file1.rar
[man]
# unzip file1.zip
[man]
[man]
Description
# dd if=/dev/sda of=/tmp/file1
[man]
[man]
[man]
[man]
[man]
Command
Description
# cd-paranoia -B
# cd-paranoia --
[man]
[man]
# cdrecord --scanbus
# dd if=/dev/hdc | md5sum
# mkisofs -J -allow-leading-dots -R -V
[man]
[man]
[man]
[man]
[man]
[man]
conversion
Command
Description
# recode -l | more
[man]
[man]
Command
Description
# dpkg -i [package.deb]
# dpkg -r [package]
# dpkg -l
# dpkg -s [package]
# dpkg -L [package]
# dpkg -S /bin/ping
[man]
[man]
Space
Command
Description
# df -h
[man]
[man]
# ls -lSr |more
search
Command
Description
# locate \*.ps
# whereis halt
# which halt
[man]
and Directory
Command
Description
# cd /home
# cd ..
# cd ../..
# cd
go to home directory
[man]
# cd ~user1
go to home directory
[man]
# cd -
go to previous directory
# cp file1 file2
copying a file
# cp dir/* .
# cp -a /tmp/dir1 .
# cp -a dir1 dir2
copy a directory
# cp file file1
# iconv -l
[man]
[man]
[man]
[man]
[man]
[man]
[man]
[man]
# ln -s file1 lnk1
# ln file1 lnk1
# ls
[man]
# ls -F
[man]
# ls -l
# ls -a
# ls *[0-9]*
# lstree
# mkdir dir1
# mkdir -p /tmp/dir1/dir2
# mv dir1 new_dir
# pwd
# rm -f file1
# rm -rf dir1
# rmdir dir1
# tree
[man]
[man]
[man]
[man]
[man]
[man]
[man]
[man]
[man]
[man]
[man]
Description
# badblocks -v /dev/hda1
# dosfsck /dev/hda1
# e2fsck /dev/hda1
# e2fsck -j /dev/hda1
# fsck /dev/hda1
# fsck.ext2 /dev/hda1
# fsck.ext3 /dev/hda1
# fsck.vfat /dev/hda1
# fsck.msdos /dev/hda1
SWAP
Command
Description
# mkswap /dev/hda3
# swapon /dev/hda3
[man]
[man]
[man]
[man]
a Filesystem
Command
Description
# fdformat -n /dev/fd0
# mke2fs /dev/hda1
# mke2fs -j /dev/hda1
# mkfs /dev/hda1
# mkswap /dev/hda3
[man]
[man]
[man]
(firewall)
Command
Description
# iptables -t filter -L
# iptables -t nat -L
# iptables -t filter -F
# iptables -t nat -F
# iptables -t filter -X
[man]
[man]
[man]
[man]
[man]
[man]
[man]
[man]
[man]
# iptables -t nat -A POSTROUTING -o eth0 -j configure a PAT (Port Address Traslation) on eth0
MASQUERADE
masking outbound packets [man]
# iptables -t nat -A PREROUTING -d
192.168.0.1 -p tcp -m tcp --dport 22 -j
DNAT --to-destination 10.0.0.2:22
Windows networks
(samba)
Command
Description
# mount -t smbfs -o
username=user,password=pass
//WinClient/share /mnt/share
# nbtscan ip_addr
[man]
# nmblookup -A ip_addr
[man]
# smbclient -L ip_addr/hostname
[man]
[man]
and debugging
Command
Description
# free -m
# kill -9 process_id
# kill -1 process_id
# last reboot
# lsmod
# lsof -p process_id
# lsof /home/user1
# ps -eafw
# ps -e -o pid,args --forest
# pstree
# smartctl -A /dev/hda
# smartctl -i /dev/hda
# strace -c ls >/dev/null
# tail /var/log/dmesg
# tail /var/log/messages
# top
[man]
[man]
[man]
[man]
[man]
[man]
[man]
[man]
[man]
[man]
[man]
[man]
a Filesystem
Command
Description
[man]
[man]
[man]
[man]
[man]
[man]
[man]
# mount -t smbfs -o
username=user,password=pass
//WinClient/share /mnt/share
# umount /dev/hda2
# umount -n /mnt/hda2
run umount without writing the file /etc/mtab useful when the file is read-only or the hard disk
is full [man]
Command
[man]
[man]
(LAN / WiFi)
Description
# dhclient eth0
[man]
# ethtool eth0
# host www.example.com
# hostname
# ifconfig eth0
configure IP Address
# ifdown eth0
# ifup eth0
# ip link show
# iwconfig eth1
# iwlist scan
# mii-tool eth0
# netstat -tup
# netstat -tupl
# netstat -rn
# nslookup www.example.com
# route -n
[man]
[man]
[man]
[man]
[man]
[man]
[man]
[man]
[man]
[man]
activate ip routing
# whois www.example.com
[man]
[man]
[man]
[man]
commands
Command
Description
# alias hh='history'
# apropos ...keyword
# chsh
# chsh --list-shells
# gpg -c file1
[man]
# gpg file1.gpg
[man]
# ldd /usr/bin/ssh
# man ping
[man]
[man]
# wget -r www.example.com
[man]
# wget -c www.example.com/file.iso
[man]
# whatis ...keyword
# who -a
Command
Description
# pacman -S name
[man]
# pacman -R name
[man]
on Files
Command
Description
# ls -lh
[man]
[man]
[man]
[man]
[man]
[man]
[man]
Command
Description
# rpm -U [package.rpm]
[man]
# rpm -F [package.rpm]
# rpm -e [package]
# rpm -qa
[man]
# rpm -V [package]
# rpm -Va
Command
Description
# init 0
shutdown system(2)
# logout
leaving session
# reboot
reboot(2)
# shutdown -h now
shutdown system(1)
# shutdown -c
# shutdown -r now
reboot(1)
# telinit 0
shutdown system(3)
[man]
[man]
[man]
[man]
[man]
[man]
[man]
on files
Command
Description
# chattr +a file1
# chattr +c file1
# chattr +d file1
# chattr +i file1
# chattr +s file1
# chattr +S file1
# chattr +u file1
# lsattr
[man]
[man]
information
Command
Description
# arch
# cal 2007
# cat /proc/cpuinfo
# cat /proc/interrupts
show interrupts
# cat /proc/meminfo
# cat /proc/swaps
# cat /proc/version
# cat /proc/net/dev
# cat /proc/mounts
# clock -w
# date
# date 041217002007.00
# dmidecode -q
[man]
[man]
[man]
[man]
[man]
[man]
[man]
[man]
[man]
[man]
[man]
(SMBIOS / DMI)
[man]
# hdparm -i /dev/hda
# lspci -tv
# lsusb -tv
# uname -m
# uname -r
[man]
[man]
[man]
[man]
[man]
Manipulation
Command
Description
# cat -n file1
[man]
[man]
[man]
# sed -n '/string1/p'
[man]
[man]
and Groups
Command
Description
# groupadd [group]
# groupdel [group]
delete a group
# grpck
# newgrp - [group]
# passwd
change password
# passwd user1
# pwck
# useradd user1
# userdel -r user1
[man]
[man]
[man]
[man]
[man]
[man]
[man]
file content
Command
Description
# cat file1
# head -2 file1
# less file1
# more file1
# tac file1
# tail -2 file1
[man]
[man]
[man]
# tail -f /var/log/messages
Command
Description
# yum -y update
# yum list
[man]
[man]
[man]
[man]
List a directory
ls {path}
ls {path_1} {path_2}
ls -l {path}
ls -a {path}
ls -F {path}
ls -R {path}
ls {path} > {filename}
ls {path} | more
dir {path}
Change to directory
cd {dirname}
cd ~
cd ..
cdup
Remove a directory
rmdir {dirname}
rm -r {dirname}
cp {file1} {file2}
cp -r {dir1} {dir2}
cat {newfile} >> {oldfile}
mv {oldname} {newname}
Delete a file
rm {filespec}
ls {filespec}
rm {filespec}
Make an Alias
alias {name} '{command}'
~
.
..
{command} | {command}
Unix permissions concern who can read a file or directory, write to it, and execute it.
Permissions are granted or withheld with a magic 3-digit number. The three digits
correspond to the owner (you); the group (?); and the world (everyone else).
Think of each digit as a sum:
execute permission
=1
write permission
=2
write and execute (1+2)
=3
read permission
=4
read and execute (4+1)
=5
read and write (4+2)
=6
read, write and execute (4+2+1)
=7
Add the number value of the permissions you want to grant each group to make a three
digit number, one digit each for the owner, the group, and the world. Here are some
useful combinations. Try to figure them out!
You can read and write; the world can't.
chmod 600 {filespec}
Good for files.
You can read, write, and execute; the
chmod 700 {filespec}
world can't. Good for scripts.
You can read and write; the world can
chmod 644 {filespec}
only read. Good for web pages.
You can read, write, and execute; the
world can read and execute. Good for
chmod 755 {filespec}
programs you want to share, and your
public_html directory.
Applications I use
finger {userid}
gopher
irc
lynx
ncftp
pico {filename}
pine
telnet {host}
tin
uudecode {filename}
uuencode {filename}
ytalk {userid}
System info
Show date and time.
Check system disk capacity.
Check your disk usage and show bytes
in each directory.
Read message of the day, "motd" is a
useful alias..
Show all environmental variables (in Cshell% - use set in Korn shell$).
Check your total disk use.
Find out system load.
Who's online and what are they doing?
date
df
du
more /etc/motd
printenv
quota -v
uptime
w
^^^
^^^
* executable
file size (bytes)
file name
/ directory
^
^
^
2560 Mar 7 23:25 public_html/
10297 Mar 8 23:42 index.html
^
user permission (rwx)
date and time last modified
group permission (rwx)
world permission (rwx)
h
m
bye
ls
dir
cdup
motd
history
more
quota -v
exit
ls -F
ls
cd ..
more /etc/motd
Save this in your home directory as htm2html (or whatever). Then make it userexecutable by typing chmod 700 htm2html. After this a * will appear by the file name
when you ls -F, to show that it's executable. Change to a directory with .htm files and
type ~/htm2html, and it will do its stuff.
Think about scripts whenever you find yourself doing the same tedious thing over and
over.
Some of these dotfiles are crucial. They initialize your shell and the programs you use,
like autoexec.bat in DOS and .ini files in Windows. rc means "run commands". These
are all text files that can be edited, but change them at your peril. Make backups first!
Here's some of what I get when I type ls -laF:
.addressbook
.cshrc
.gopherrc
.history
.login
.lynxrc
.ncftp/
.newsrc
.pinerc
.plan
.profile
.project
.signature
.tin/
.ytalkrc
my email addressbook.
my C-shell startup info, important!
my gopher setup.
list of past commands.
login init, important!
my lynx setup for WWW.
hidden dir of ncftp stuff.
my list of subscribed newsgroups.
my pine setup for email.
text appears when I'm fingered, ok to edit.
Korn shell startup info, important!
text appears when I'm fingered, ok to edit.
my signature file for mail and news, ok to edit.
hidden dir of my tin stuff for usenet.
my ytalk setup.
DOS
cd
attrib
comp
copy
del
rd
dir
edit
set
find
help
md
move
ren
date, time
chkdsk
type
type filename | more
sort
UNIX
cd
chmod
diff
cp
rm
rmdir
ls
pico
printenv
grep
man
mkdir
mv
mv
date
df
cat
more
sort
Linux Commands
A B C D E F G H I K L M N P Q R S T U V W XYZ
References and answers
back to beginning
A
alias Create your own name for a command
arch print machine architecture
ash ash command interpreter (shell)
awk (gawk) pattern scanning and processing language
B
basename Remove directory and suffix from a file name
bash GNU Bourne-Again Shell
bsh Command interpreter (Shell)
bc Command line calculator
bunzip2 Unzip .bz2 files
C back to commands top
cat Concatenate a file print it to the screen
chgrp Change the group designation of a file
chmod Change file permissions
chown Change the owner of a file
cjpeg Compress an image file to a JPEG file
clear Clear terminal screen (command line)
comm Compare two sorted files
stty cooked Formatting the display of text in a terminal
cp Copy command
cpio Copy files to and from archives
csh C Shell
cut Print selected parts of lines to standard output
D back to commands top
date Display date and time
dc Command line calculator
df Show amount of disk space free
diff Determine difference between two files
diff3 Determine difference between 3 files
dig Interrogate DNS name servers
djpeg Decompress a JPEG file to an image file
dmesg Print or control the kernel ring buffer (print out bootup messages)
N
namei Follow a pathname until a terminal point is found
nano An enhanced free Pico clone
nc arbitrary TCP and UDP connections and listens
(note that nc is also called the client interface
to the NEdit program but it is not the
command that invokes nedit-nc on current systems)
ncftp Browser program for the File Transfer Protocol
nedit-nc nedit-nc is the client interface to the NEdit text editor
netstat Display verbose info about network processes and ports
nice Run a command with modified priority
nisdomainname Show or set system's NIS/YP domain name
nslookup query internet domain name servers
P
paste Merge lines of files
pdf2dsc Generate a PostScript page list of a PDF document
pdf2ps Convert PDF file "input.pdf" to PostScript(tm) in "output.ps"
pdfinfo Print contents of the 'Info' dictionary (plus some other useful information) from
a PDF file
pdftotext Convert pdf files to plain text
perl (start) Practical Extraction and Report Language
pgawk The profiling version of gawk
pico Text editor that comes with Pine (from the University of Washington)
pine Email program used by The University of Washington
ping6 Ping
ping Send ICMP ECHO_REQUEST to network hosts
pinky A lightweight 'finger' program;
pr Format for printing
ps Processes running
ps2ascii Ghostscript translator from PostScript or PDF to ASCII
ps2epsi Generate conforming Encapsulated PostScript
ps2frag Obsolete shell script for the PSfrag system
ps2pdf12 Convert PostScript to PDF 1.2 (Acrobat 3 and later compatible) using
ghostscript
ps2pdf13 Convert PostScript to PDF 1.3 (Acrobat 4 and later compatible) using
ghostscript
ps2pdf14 Use ps2pdfwr: Convert PostScript to PDF without specifying Compatibility
Level, using ghostscript
ps2pdf Convert PostScript to PDF using ghostscript
ps2pdfwr Convert PostScript to PDF without specifying Compatibility Level, using
ghostscript
ps2pk creates a TeX pkfont from a type1 PostScript font
ps2ps ps2ps uses gs to convert PostScript(tm) file "input.ps" to simpler and (usually)
faster PostScript in "output.ps"
psbook Rearranges pages from a PostScript document into "signatures" for printing
books or booklets
pwd Print Working Directory
Q back to commands top
quota display disk usage and limits
R back to commands top
resize Xterm window size
readelf Displays information about ELF files
reboot Stop the system, poweroff, reboot
red red is a restricted ed: it can only edit files in the current directory and cannot
execute shell commands
rename Rename files
rmdir Remove a directory
rm Remove files or directories
rpm rpm command options
rundig Sample script to create a search database for ht://Dig
rview The GUI version of Vim in easy mode with restrictions
rvi Vi / Vim editor
S back to commands top
sed Stream editor
setfont Load EGA/VGA console screen font
set gid Set group id
set serial Get / set Linux serial port info
set uid Set user id
sfdisk Modified fdisk program
sftp Secure file transfer protocol (ftp)
sh Shell (BASH)
shred Safely remove data from disk drive
sleep Delay for a specified amount of time
slocate Security Enhanced version of the GNU Locate
sort Sort lines of a text file
ssh Secure shell connection command
stty change and print terminal line settings
stty raw Unformatted output to terminal
su Become super user ( root )
switchdesk Graphical and text mode interface for choosing desktop environment
sync Force changed blocks to disk, update the super block
ssh Secure shell connection command