รวมคำสั่ง Linux Command
description
Transcript of รวมคำสั่ง Linux Command
Linux Command
File/Directory Basics
lsList files
cpCopy files
mvRename files
rmDelete files
lnLink files
cdChange directory
pwdPrint current directory name
mkdirCreate directory
rmdirDelete directory ()
File Viewing
catView files text file
lessPage trough files
headView file beginning
tailView files ending
nlNumber lines
odView binary files
xxdView binary files
gvView Postscript/PDF files PDF
xdviView TeX DVI files TeX
File Creation and Editing
emacsText editor GNU
vimText editor vi
umaskSet default file protections/ permission mode
sofficeEdit Word/Excel/PowerPoint docs Word/Excel/PowerPoint
abiwordEdit Word documents Word
gnumericEdit Excel documents Excel
File Properties
statDisplay file attributes//
wcCount bytes/words/lines
duMeasure disk usage
fileIdentify file types
touchChange file timestamps
chownChange file owner
chgrpChange file group
chmodChange file protections
chattrChange advanced file attributes
IsattrList advanced file attributes
File Location
findLocate files
slocateLocate files via index
whichLocate commands
whereisLocate standard files
File Text Manipulation
grepSearch text for matching lines
cutExtract columns
pasteAppend columns
trTranslate characters
sortSort lines
uniqLocate indentical lines
teeCopy stdin to file and to stdout simultaneously stdout
File Compression
gzipCompress files (GNU Zip) .gz
CompressCompress files (Unix) Unix
bzip2Compress files (BZip2) .bz2
zipCompress files (Windows Zip) WinZip
File Comparison
diffCompare files line by line
commCompare sorted files
cmpCompare files byte by byte
md5sumCompute Checksums md5
Disks and Filesystems
dfShow free disk space
mountMake a disk accessible
fsckCheck a disk for errors
syncFlush disk caches
Backups and Remote Storage
mtControl a type drive
dumpBack up a disk
restoreRestore a dump
tarRead/write type archives
cdrecordBurn a CD
rsyncMirror a set of files
Printing
lprPrint files
lpqView print queue
lprmRemove print jobs
Spelling Operations
lookLook up spelling
aspellCheck spelling interactively
spellCheck spelling in batch
Processes
psList all processes
wList users' processes
uptimeView the system load
topMonitor processes
xloadMonitor system load
freeDisplay free memory
killTerminate processes
niceSet process priorities
reniceChange process priorities
Scheduling Jobs
sleepWait for some time
watchRun programs at set intervals
atSchedule a job
crontabSchedule repeated jobs
Hosts
unamePrint system information
hostnamePrint the system's hostname/
ifconfigSet/display network information/
hostLook up DNS DNS
whoisLookup domain registrants
pingCheck if host is reachable
tracerouteView network path to a host
Networking
sshSecurely log into remote hosts ()
telnetLog into remote hosts()
scpSecurely copy files between hosts()
stfpSecurely copy files between hosts()
ftpCopy files between hosts()
evolutionGUI email client
muttText-based email client text
mailMinimal email client
mozillaWeb browser
lynxText-only web browser text
wgetRetrieve web pages to disk
slrnRead Usenet news usenet
gaimInstant messaging/IRC
talkLinux/Unix chat
writeSend messages to a termainal
mesgProhibit talk/write/ write
Audio and Video
gripPlay CDs and rip MP3s MP3
xmmsPlay audio files
cdparanoiaRip audio
audacityEdit audio/
xcdroastBurn 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.2chmod : (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.htmcd / :: 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 aLinux-based GNUsystem.Get help C-h (Hold down CTRL and press h)Undo changes C-x u Exit Emacs C-x C-cGet a tutorial C-h t Use Info to read docs C-h iOrdering manuals C-h RETActivate 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 a A 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 :: thaiw :: --------------------------------------------------------------------------------1.9 cat : type DOS--------------------------------------------------------------------------------
cat /etc/passwd :: /etc/passwdcat /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 ip server --------------------------------------------------------------------------------
ifconfigeth0 Link encap:Ethernet HWaddr 00:20:18:C0:06:C4inet addr:202.29.78.12 Bcast:202.29.78.255 Mask:255.255.255.0UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:673054 errors:0 dropped:0 overruns:0 frame:0TX packets:666268 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:100RX bytes:74892865 (71.4 Mb) TX bytes:680121131 (648.6 Mb)Interrupt:9 Base address:0xcf00eth0:1 Link encap:Ethernet HWaddr 00:20:18:C0:06:C4inet addr:202.29.78.1 Bcast:202.29.78.255 Mask:255.255.255.0UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1Interrupt: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 -aActive Internet connections (servers and established)Proto Recv-Q Send-Q Local Address Foreign Address Statetcp 0 0 *:mysql *:* LISTENtcp 0 0 *:http *:* LISTENtcp 0 0 *:ftp *:* LISTENtcp 0 0 *:ssh *:* LISTENtcp 0 0 *:smtp *:* LISTENtcp 0 0 *:https *:* LISTENtcp 0 0www.isinthai.com:ssh 202.29.78.200:1225 ESTABLISHEDActive UNIX domain sockets (servers and established)Proto RefCnt Flags Type State I-Node Pathunix 2 [ ACC ] STREAM LISTENING 855 /var/lib/mysql/mysql.sockunix 2 [ ACC ] STREAM LISTENING 119 /dev/logunix 2 [ ] STREAM CONNECTED 3007unix 2 [ ] STREAM CONNECTED 859
--------------------------------------------------------------------------------1.12 service : running --------------------------------------------------------------------------------
service --status-allhttpd (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 talk talk server --------------------------------------------------------------------------------
xinetd -dService configuration: ftpid = ftpflags = IPv4socket_type = streamProtocol (name,number) = (tcp,6)Nice = 10Groups = noBind = All addresses.Server = /usr/sbin/vsftpdServer argv = vsftpdOnly from: All sitesNo access: No blocked sitesLogging to syslog. Facility = authpriv, level = infoLog_on_success flags =HOST PIDLog_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 cprm y :: y directory rm -r directoryname :: directory sun directory confirm rm -rf directoryname :: directory Redhat directory confirm rm -f * :: yesmv x /root :: x /root
--------------------------------------------------------------------------------1.16 ping : ip internet--------------------------------------------------------------------------------
pingwww.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=1Destination Host UnreachableFrom 202.29.78.12 icmp_seq=2 DestinationHost Unreachable From 202.29.78.12 icmp_seq=3 Destination Host Unreachable
--------------------------------------------------------------------------------1.17 env : environment --------------------------------------------------------------------------------
env
HISTSIZE=1000SSH_CLIENT=202.29.78.100 1091 22OLDPWD=/usr/sbinQTDIR=/usr/lib/qt3-gcc3.2SSH_TTY=/dev/pts/0USER=burinLS_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/binMAIL=/var/spool/mail/burinPWD=/etcINPUTRC=/etc/inputrcLANG=en_US.UTF-8HOME=/rootSHLVL=2LOGNAME=burinLESSOPEN=|/usr/bin/lesspipe.sh %sG_BROKEN_FILENAMES=1_=/bin/env
--------------------------------------------------------------------------------1.18 lynx :Text browser source download --------------------------------------------------------------------------------
lynxwww.thaiall.com:: www.thaiall.com text modelynxhttp://www.yonok.ac.th:: www.yonok.ac.th text modelynx -dumphttp://www.yonok.ac.th:: interactive view lynx -dump -width=500http://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.65Non-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.65nslookupwww.thaiall.comName:www.thaiall.comAddress: 66.150.1.141
--------------------------------------------------------------------------------1.20 tail : cat --------------------------------------------------------------------------------
tail index.html :: index.html Current directorytail --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 23telnetwww.school.net.th21 :: port 21 FTP porttelnet 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. [email protected]+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% /homenone 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 Kbdu -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 directoryfind / -name hello* :: hellofind /bin -size 626188c :: 626188 RH8 bash
--------------------------------------------------------------------------------2.6 gzip : gz z tar .tar.gz--------------------------------------------------------------------------------
gzip -d x.tar.gz :: gzman 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 tarman 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 thaiallrpm -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.0CPU states: 0.5% user, 1.3% system, 0.0% nice, 98.0% idleMem: 31328K av, 28872K used, 2456K free, 0K shrd, 1032K buffSwap: 1718912K av, 2608K used, 1716304K free 16528K cached
PID USER PRI NI SIZE RSS SHARE STAT LIB %CPU %MEM TIME COMMAND18306 root 14 0 852 852 672 R 0 1.5 2.7 0:00 top18229 root 1 0 1684 1536 1240 S 0 0.3 4.9 0:00 sshd1 root 0 0 160 116 92 S 0 0.0 0.3 0:08 init2 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 dnsntsysv :: - setup, services ( RH )--------------------------------------------------------------------------------2.13 route :--------------------------------------------------------------------------------
# route
Kernel IProuting tableDestination Gateway Genmask Flags Metric Ref Use Iface202.29.78.0 * 255.255.255.0 U 0 0 0 eth0127.0.0.0 * 255.0.0.0 U 0 0 0 lodefault 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