You are on page 1of 10

Linux Command

File/Directory Basics
ls

List files

cp

Copy files

mv

Rename files

rm

Delete files

ln

Link files

cd

Change directory

pwd

Print current directory name

mkdir

Create directory

rmdir

Delete directory

( )

File Viewing
cat

View files

text file

less

Page trough files

head

View file beginning

tail

View files ending

nl

Number lines

od

View binary files

xxd

View binary files

gv

View Postscript/PDF files

PDF

xdvi

View TeX DVI files

TeX

File Creation and Editing


emacs

Text editor

GNU

vim

Text editor

vi

umask

Set default file protections

permission mode
soffice

Edit Word/Excel/PowerPoint docs

Word/Excel/PowerPoint

abiword

Edit Word documents

Word

gnumeric

Edit Excel documents

Excel

File Properties
stat

Display file attributes

//

wc

Count bytes/words/lines

du

Measure disk usage

file

Identify file types

touch

Change file timestamps

chown

Change file owner

chgrp

Change file group

chmod

Change file protections

chattr

Change advanced file attributes

Isattr

List advanced file attributes

File Location
find

Locate files

slocate

Locate files via index

which

Locate commands

whereis

Locate standard files

File Text Manipulation


grep

Search text for matching lines

cut

Extract columns

paste

Append columns

tr

Translate characters

sort

Sort lines

uniq

Locate indentical lines

tee

Copy stdin to file and to stdout simultaneously

stdout

File Compression
gzip

Compress files (GNU Zip)

.gz

Compress

Compress files (Unix)

Unix

bzip2

Compress files (BZip2)

.bz2

zip

Compress files (Windows Zip)

WinZip

File Comparison
diff

Compare files line by line

comm

Compare sorted files

cmp

Compare files byte by byte

md5sum

Compute Checksums

md5

Disks and Filesystems


df

Show free disk space

mount

Make a disk accessible

fsck

Check a disk for errors

sync

Flush disk caches

Backups and Remote Storage


mt

Control a type drive

dump

Back up a disk

restore

Restore a dump

tar

Read/write type archives

cdrecord

Burn a CD

rsync

Mirror a set of files

Print files

Printing
lpr

lpq

View print queue

lprm

Remove print jobs

Spelling Operations
look

Look up spelling

aspell

Check spelling interactively

spell

Check spelling in batch

ps

List all processes

List users' processes

uptime

View the system load

top

Monitor processes

xload

Monitor system load

free

Display free memory

kill

Terminate processes

nice

Set process priorities

renice

Change process priorities

Processes

Scheduling Jobs
sleep

Wait for some time

watch

Run programs at set intervals

at

Schedule a job

crontab

Schedule repeated jobs

uname

Print system information

hostname

Print the system's hostname

ifconfig

Set/display network information

host

Look up DNS

DNS

whois

Lookup domain registrants

ping

Check if host is reachable

traceroute

View network path to a host

Hosts

Networking
ssh

Securely log into remote hosts

()

telnet

Log into remote hosts

()

scp

Securely copy files between hosts

()

stfp

Securely copy files between hosts

(
)

ftp

Copy files between hosts

(
)

evolution

GUI email client

mutt

Text-based email client

text

mail

Minimal email client

mozilla

Web browser

lynx

Text-only web browser

text

wget

Retrieve web pages to disk

slrn

Read Usenet news

usenet

gaim

Instant messaging/IRC

talk

Linux/Unix chat

write

Send messages to a termainal

mesg

Prohibit talk/write

/ write

Audio and Video


grip

Play CDs and rip MP3s

MP3

xmms

Play audio files

cdparanoia Rip audio

audacity

Edit audio

xcdroast

Burn CDs


1.1

ls : home directory

------------------------------------------------------------------------------- account linux home directory


linux ls parameter -al --sort

ls -alt :: alt
ls -alt | more :: 1
ls -al --sort=time | more ::
ls -R | more :: directory
. ls ls -l

D Column ls -al directory


-------------------------------------------------------------------------------1.2

chmod : (Owner), (Group), (Other)

------------------------------------------------------------------------------- ls RWXRWXRWX


webmaster
CGI
CGI server
Perl (x)
chmod 755 hello.pl chmod 775 fileforyou.pl chmod +x test.pl 3
R Read
W Write
X Execute

--- : (
0)
--X : (
1)
R-- : (
4)
RW- : (
6)
R-X : ( 5)
RWX : (
7) RWXRWXRWX 9
3
3
3

RWX------ :
(
700)
RWXRWX--- :
(
770)
RWXR-XR-X : ( 755)
R--R--R-- : (
444)

chmod 777 index.php :: 3
chmod 755 * -Rf :: direcroty


-------------------------------------------------------------------------------1.3

man :
(Manual)

------------------------------------------------------------------------------- unix linux


parameter
linux man




man man :: man
man ls :: ls
man useradd :: useradd
-------------------------------------------------------------------------------1.4

mkdir, rmdir, cd : directory

------------------------------------------------------------------------------- dos
directory
directory
3 mkdir directory (Make directory) rm directory

(Remove directory) cd directory (Change directory)



mkdir hello :: directory hello
rmdir hello.htm :: hello.htm
cd / :: directory root
cd .. :: directory 1
cd ~/x :: x home directory /home/thaiall/x home directory /home/thaiall
-------------------------------------------------------------------------------1.5

pico : editor text vi

------------------------------------------------------------------------------- pico enter


^ Ctrl
pico xx xx

xx xx Ctrl-X
vi
pico pine pico
pine CD rpm -i pine*
-------------------------------------------------------------------------------1.6

emacs : editor text vi

------------------------------------------------------------------------------- pico
pico
emacs ctrl-h ctrl-x + ctrl-c
pico editor emacs
pico emacs
Welcome to GNU Emacs, one component of a Linux-based GNU system.
Get help
C-h (Hold down CTRL and press h)
Undo changes
C-x u
Exit Emacs
C-x C-c
Get a tutorial C-h t
Use Info to read docs C-h i
Ordering manuals C-h RET
Activate menubar F10 or ESC ` or M-`
(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key.
If you have no Meta key, you may instead type ESC followed by the character.)
-------------------------------------------------------------------------------1.7

vi : editor text

-------------------------------------------------------------------------------Text editor linux pico mail pine vi linux man vi



esc
enter
i


dd


x
1
cw

:w

:q!
:wq vi
-------------------------------------------------------------------------------1.8

id, finger, who, w :

-------------------------------------------------------------------------------
id uname :: account uname

finger uname :: account uname last login email


finger @www.isinthai.com :: login
who |grep thai :: thai
w ::
-------------------------------------------------------------------------------1.9

cat : type DOS

-------------------------------------------------------------------------------
cat /etc/passwd :: /etc/passwd
cat /etc/passwd | more :: /etc/passwd
passwd suwit:x:500:500:Suwit:/home/suwit:/bin/bash prasert:x:501:501::
/home/prasert:/bin/bash bcom101:x:502:502::/home/bcom302:/bin/bash
-------------------------------------------------------------------------------1.10

ifconfig :

Network interface

------------------------------------------------------------------------------- ifconfig
eth0
Link encap:Ethernet HWaddr 00:20:18:C0:06:C4
inet addr:202.29.78.12 Bcast:202.29.78.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:673054 errors:0 dropped:0 overruns:0 frame:0
TX packets:666268 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:74892865 (71.4 Mb) TX bytes:680121131 (648.6 Mb)
Interrupt:9 Base address:0xcf00
eth0:1 Link encap:Ethernet HWaddr 00:20:18:C0:06:C4
inet addr:202.29.78.1 Bcast:202.29.78.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:9 Base address:0xcf00
ip
1 ip #/sbin/ifconfig eth0:1 202.29.78.1
IP 9.10 /etc/rc.d/rc.local
-------------------------------------------------------------------------------1.11

netstat :

------------------------------------------------------------------------------- netstat -a
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address
Foreign Address
State
tcp
0
0 *:mysql
*:*
LISTEN
tcp
0
0 *:http
*:*
LISTEN
tcp
0
0 *:ftp
*:*
LISTEN
tcp
0
0 *:ssh
*:*
LISTEN
tcp
0
0 *:smtp
*:*
LISTEN
tcp
0
0 *:https
*:*
LISTEN
tcp
0
0 www.isinthai.com:ssh 202.29.78.200:1225
ESTABLISHED
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags
Type
State
I-Node Path
unix 2
[ ACC ] STREAM LISTENING 855 /var/lib/mysql/mysql.sock
unix 2
[ ACC ] STREAM LISTENING 119 /dev/log
unix 2
[]
STREAM CONNECTED 3007
unix 2
[]
STREAM CONNECTED 859
-------------------------------------------------------------------------------1.12

service : running

------------------------------------------------------------------------------- service --status-all


httpd (pid 2160 2159 2158 2155 2114 583 579 578 577 576 575 573) is running...
mysqld (pid 446 429 427 414) is running...
sendmail (pid 1700 1690) is running...
sshd (pid 2970 358) is running...
xinetd (pid 3923 369) is running...
-------------------------------------------------------------------------------1.13

xinetd : xinetd
/etc/xinetd.d


ip

server

talk talk server


------------------------------------------------------------------------------- xinetd -d
Service configuration: ftp
id = ftp
flags = IPv4
socket_type = stream
Protocol (name,number) = (tcp,6)
Nice = 10
Groups = no
Bind = All addresses.
Server = /usr/sbin/vsftpd
Server argv = vsftpd
Only from: All sites
No access: No blocked sites
Logging to syslog. Facility = authpriv, level = info
Log_on_success flags = HOST PID
Log_on_failure flags = HOST
-------------------------------------------------------------------------------1.14

whereis :
PATH find

-------------------------------------------------------------------------------
whereis usermod :: usermod run
whereis ifconfig :: ifconfig /sbin/ifconfig
-------------------------------------------------------------------------------1.15

cp, rm, mv :

-------------------------------------------------------------------------------
cp x y :: x y x
cp
rm y :: y directory

rm -r directoryname :: directory sun directory confirm


rm -rf directoryname :: directory Redhat directory confirm
rm -f * :: yes
mv x /root :: x
/root
-------------------------------------------------------------------------------1.16

ping : ip internet

-------------------------------------------------------------------------------
ping www.thaiall.com :: www.thaiall.com IP
ping 202.29.78.100 -c 5 :: 5
ping 202.29.78.2 :: ip PING 202.29.78.2 (202.29.78.2)
from 202.29.78.12 : 56(84) bytes of data. From 202.29.78.12 icmp_seq=1
Destination Host Unreachable From 202.29.78.12 icmp_seq=2 Destination
Host Unreachable From 202.29.78.12 icmp_seq=3 Destination Host Unreachable
-------------------------------------------------------------------------------1.17

env : environment

-------------------------------------------------------------------------------
env
HISTSIZE=1000
SSH_CLIENT=202.29.78.100 1091 22
OLDPWD=/usr/sbin
QTDIR=/usr/lib/qt3-gcc3.2
SSH_TTY=/dev/pts/0
USER=burin
LS_COLORS=no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;.... :
PATH=/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin
MAIL=/var/spool/mail/burin
PWD=/etc
INPUTRC=/etc/inputrc
LANG=en_US.UTF-8
HOME=/root
SHLVL=2
LOGNAME=burin
LESSOPEN=|/usr/bin/lesspipe.sh %s
G_BROKEN_FILENAMES=1
_=/bin/env
-------------------------------------------------------------------------------1.18

lynx : Text browser source download

-------------------------------------------------------------------------------
lynx www.thaiall.com :: www.thaiall.com text mode
lynx http://www.yonok.ac.th :: www.yonok.ac.th text mode
lynx -dump http://www.yonok.ac.th :: interactive view
lynx -dump -width=500 http://piology.org/.procmailrc.html|grep '^|'|cut -c3- ::
-------------------------------------------------------------------------------1.19

nslookup : name server ip domain name

------------------------------------------------------------------------------- Redhat dig host host yn1.yonok.ac.th dig yn1.yonok.ac.th nslookup exit >

nslookup 202.28.18.65
Non-authoritative answer:
65.18.28.202.in-addr.arpa name = mars.uni.net.th.
Authoritative answers can be found from:
18.28.202.in-addr.arpa nameserver = mars.uni.net.th.
18.28.202.in-addr.arpa nameserver = ns.netserv.chula.ac.th.
mars.uni.net.th internet address = 202.28.18.65
nslookup www.thaiall.com
Name: www.thaiall.com
Address: 66.150.1.141
-------------------------------------------------------------------------------1.20

tail : cat

-------------------------------------------------------------------------------
tail index.html :: index.html Current directory
tail --lines=5 /var/log/messages :: /var/log/messages
root
tail /var/log/html/access.log :: 10 default
tail --lines=100 /var/log/html/access_log > access_bak :: backup
mv
-------------------------------------------------------------------------------1.21

telnet : server port


server telnet SSH

-------------------------------------------------------------------------------
telnet 202.202.202.202 :: 202.202.202.202 port port 23
telnet www.school.net.th 21 :: port 21 FTP port
telnet mail.loxinfo.co.th 25 :: smtp
telnet class.yonok.ac.th 110 :: pop service windows server 2003 Microsoft Windows POP3 Service Version 1.0 ready. USER aa@class.yonok.ac.th +OK PASS xxxxxxx +OK User successfully logged on
-------------------------------------------------------------------------------2.1

df : Harddisk

------------------------------------------------------------------------------- Harddisk upload user ( server clear )



df ::
Filesystem
1K-blocks
Used Available Use% Mounted on
/dev/hda5
505605 82764 396737 18% /
/dev/hda1
101089
9180 86690 10% /boot

/dev/hda3
1423096 41956 1308848 4% /home
none
30740
0 30740 0% /dev/shm
/dev/hda2
3889924 1551872 2140456 43% /usr
/dev/hda6
1027768 952876 22684 98% /var
-------------------------------------------------------------------------------2.2

du : directory

------------------------------------------------------------------------------- directory

du :: directory

du -all :: directory
du | sort -g ::
directory sort Kb
du -b :: byte directory
-------------------------------------------------------------------------------2.3

ps : Process

------------------------------------------------------------------------------- run bot server



ps :: process

ps -ef :: process
ps -ax :: process
ps -aux :: process

-------------------------------------------------------------------------------2.4

kill : process
process kill process

------------------------------------------------------------------------------- process process kill ( super user )



kill -9 process :: process ps -ef

kill -9 1255 :: process 1255
-------------------------------------------------------------------------------2.5

find : directory

-------------------------------------------------------------------------------
find / -name hello.pl ::
hello.pl directory
find / -name hello* :: hello
find /bin -size 626188c ::
626188 RH8 bash
-------------------------------------------------------------------------------2.6

gzip : gz z tar .tar.gz

-------------------------------------------------------------------------------
gzip -d x.tar.gz ::
gz
man gzip :: gzip
gzip -d radius-1.16.1.tar.Z :: ftp.livingston.com/pub/le/radius/
gzip -dc x.tar.Z|tar xvf - ::
2 gzip tar x.tar.z
-------------------------------------------------------------------------------2.7

tar : tar

-------------------------------------------------------------------------------
tar xvf x.tar :: tar directory
tar xvfz squid-2.3-200103110000-src.tar.gz :: gz tar
gzip tar
man tar :: tar
tar zcvf abc.tar.gz /etc :: copy /etc abc.tar.gz
tar zxvf abc.tar.gz :: abc.tar.gz directory /etc
-------------------------------------------------------------------------------2.8

last : login

-------------------------------------------------------------------------------
last |grep reboot :: reboot
last |more :: login
-------------------------------------------------------------------------------2.9

grep :

-------------------------------------------------------------------------------
more /etc/passwd|grep thaiall :: /etc/passwd thaiall
rpm -qa|grep ftp :: ftp
last |grep reboot :: reboot
-------------------------------------------------------------------------------2.10

date : date [OPTION] [MMDDhhmm[[CC]YY][.ss]]

-------------------------------------------------------------------------------
date +%x :: 04/27/01
date +%d :: 27
date 04271340 :: 27 4 13.40 . (mmddhhmmccyy)
hwclock --systohc :: date restart hardware clock hardware
-------------------------------------------------------------------------------2.11

top :

-------------------------------------------------------------------------------
top :: process Redhat 8.0

CPU states: 0.5% user, 1.3% system, 0.0% nice, 98.0% idle
Mem: 31328K av, 28872K used, 2456K free,
0K shrd, 1032K buff
Swap: 1718912K av, 2608K used, 1716304K free
16528K cached
PID USER PRI NI SIZE RSS SHARE STAT LIB %CPU %MEM TIME COMMAND
18306 root
14 0 852 852 672 R
0 1.5 2.7 0:00 top
18229 root
1 0 1684 1536 1240 S
0 0.3 4.9 0:00 sshd
1 root
0 0 160 116 92 S
0 0.0 0.3 0:08 init
2 root
0 0 0 0 0 SW
0 0.0 0.0 0:01 kflushd
-------------------------------------------------------------------------------2.12

ntsysv

setup : -

-------------------------------------------------------------------------------
setup :: system services server httpd, imap, ipop3, iptables, named, network, sendmail, servers, services, vsftpd, xinetd web, mail, ftp dns
ntsysv :: - setup, services ( RH )
-------------------------------------------------------------------------------2.13

route :

-------------------------------------------------------------------------------
# route
Kernel IP routing table
Destination Gateway
Genmask
Flags Metric Ref Use Iface
202.29.78.0 *
255.255.255.0 U 0
0
0 eth0
127.0.0.0
*
255.0.0.0
U 0
0
0 lo
default
202.29.78.254 0.0.0.0
UG 0
0
0 eth0
--------------------------------------------------------------------------------

2.14

shutdown, reboot :

-------------------------------------------------------------------------------
shutdown -h now halt :: ( 1 )
reboot shutdown -r now :: clear
-------------------------------------------------------------------------------2.15

runlevel :
/etc/inittab level : level chkconfig 2.18

-------------------------------------------------------------------------------
#/sbin/runlevel :: level
#cat /etc/inittab :: level
-------------------------------------------------------------------------------2.16

fsck : linux

-------------------------------------------------------------------------------
#fsck / :: harddisk / harddisk
#fsck /dev/hdc :: harddisk
/dev/hdc harddisk
-------------------------------------------------------------------------------2.17

chown, chgrp :

------------------------------------------------------------------------------- 1.2 chmod 3



#chown burin:users x :: x burin users
#chgrp users y :: x users
-------------------------------------------------------------------------------2.18

chkconfig : level

------------------------------------------------------------------------------- level /etc/inittab level level start linux level



# /etc/inittab
# Default runlevel. The runlevels used by RHS are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#id:5:initdefault:
id:3:initdefault:

#/sbin/chkconfig --add mysql :: mysql system services
#/sbin/chkconfig --list ::
level
#/sbin/chkconfig --level 3 sendmail on :: sendmail level 3 (Text mode)
#/sbin/chkconfig --level 5 sendmail on :: sendmail level 5 (X Windows)
-------------------------------------------------------------------------------2.19

mount, umount : partition Diskette Handy drive

------------------------------------------------------------------------------- mount harddisk server 1 harddisk hdc fdisk -l partition 1 hdc /x


#mkdir /x #mount /dev/hdc1 /x /x h

You might also like