Your SlideShare is downloading. ×
คำสั่งยูนิกส์ Command line
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

คำสั่งยูนิกส์ Command line

464
views

Published on


0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
464
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
40
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Command Line (Linux 1)ls dir DOS)list ls [option] [file]option ls-l Long Format Permission-a-F Directory execute ls –l ls -al ls -Fadduser User Unix,Linux adduser -g (group) -d (Directory) (User) adduser -g root -d /home/user1 user User Loginuser1 rootuseradd User Unix,Linux ( adduser) useradd -g (group) -d (Directory) (User) useradd -g root -d /home/user1 user User Loginuser1 rootuserdel User Unix,Linux userdel [option] (Username) userdel -r root user1 User Login User1 -r
  • 2. Home Directory User1passwd User Unix,Linux passwd [Username] passwd user1 ( User1 User Unix Loginalias Unix,Linux (SET DOS RUN alias [ alias copy=cp copy cpbash Bourne again shell Unix,Linux bash bash [Enter] ( Bourne again shell)bc Unix,Linux bc [-lwsqv] [option] [file] bc [Enter] 1+2 [Enter] 1^2 [Enter] a=3 [Enter] b=4 [Enter] a*b[Enter] x=2;y=5;x+y[Enter] [Ctrl-d] Install Packetcp copy DOS)
  • 3. copy cp source target #cp test.txt /home/user1cal Unix,Linux cal cal [Enter](cal -y [Enter](cat File Unix,Linux( Type DOS) cat cat /home/user1 | more home/user1C Compiler Compile C Unix,Linux ( Type DOS) cc [filename] cc /home/user1/industry.c Compile Cindustry.c Directory /home/user1cd
  • 4. Change Directory Unix,Linux ( CD DOS) cd [directory] cd /etc [Enter] Directory etccd ..[Enter] Directory 1chfin Change your finger information Unix,Linux( User chfn [username] chfn User1 User1chgrp Change Group Unix,Linux ( chgrp [-chfRv] (Group) (File) chgrp root /root/* Grouproot Group rootchmod Change Mode Unix,Linux( chmod [ File) test chmod 754 test chmod go+r-w test chmod o-r * Mode rwx = 7 ; rw - =6 ; r-x =5 ; r- - = 4 ; - wx = 3 ; - w - = 2 ; - - x=1;--=0 2
  • 5. 1.2. 2 1 User Group Other = ugo go-r-w+x Run -rwxrwxrwx = Read Write Execute 111 101 100 = 754 Group Executechown Change Owner Unix,Linux ( chown [ File) chown user1 filename filename User1chown -R user1.rootdirname Subdirname.chsh chsh Unix,Linux ( Shell User) chsh [Username] chsh user1 [Enter] /bin/bash [Enter]clear
  • 6. clear Unix,Linux (cls dos) clear clear [Enter]cal Unix,Linux cal cal [Enter](cal -y [Enter](mesgmesg status terminalmesg y terminalmesg n terminaldate date 17 May 2004df df Unix,Linux ( df [option] [file] df [Enter]dmesg dmesg Unix,Linux ( Boot)
  • 7. dmesg dmesg | more [Enter] Linux Driver CD-Romecho echo Unix,Linux (ECHO DOS) echo ( echo my name is user1echo Hello > /dev/tty2 Hello 2ed ed Unix,Linux ( Text file edlin DOS) ed (fileName) ed /home/user/test ( q) pico vi emacsemacs emacs Unix,Linux ( Text file ) emacs (fileName) emacs /home/user/test (help Ctrl - h ; Ctrl - x Ctrl -c)exit exit Unix,Linux (
  • 8. exit exitfinger finger Unix,Linux ( User LoginWho finger [username] finger user1 user1fsck fsck Unix,Linux ( Linux filesystem Scandisk Dos) fsck [option] sbin/fsck -a /dev/hd1ftp ftp Unix,Linux ( ftp (IP or Name of FTP Server ) ftp 132.209.1.2 [Enter]Login:anonymous , Password: Username@YourDomain.com ls - ; pwd - dir. ;cd - dir ;lcd -local dir ;mput* - ;mget – ;bye -
  • 9. grep grep Unix,Linux ( grep (option) grep -i ftp /etc/test ftp" etc/testgroupadd groupadd Unix,Linux ( User) groupadd (GroupName ) #groupadd staff User Staffgroupdel groupdel Unix,Linux ( User) groupadd (GroupName ) #groupdel staff User Staffgzip/gunzip gzip/gunzip Unix,Linux( gzip gunzip (-cdfhlLnNrtv19 ) [file] -- #gzip -9vr /home/samba/* Sub/home/samba gz#gunzip -dvr /home/samba/*gz Sub /home/sambahalt halt Unix,Linux (
  • 10. halt [-n] [-w] [-d] [-f] [-I] [-p] #halt Shutdown ; init0 , reboothistory history Unix,Linux( Command line F7 DOS Dos key) history [n] [-r wan [filename] ] #history 20 20ifconfig history Unix,Linux( Network Lan Card) ifconfig [option] #ifconfigipchains ipchains Unix,Linux ( Firewall) ipchains [parameter] command [option] #ipchains -L Set IPchainsjobs jobs Unix,Linux ( Firewall) jobs
  • 11. #sleep 20 & jobskill kill Unix,Linux ( Process) kill [option] (process ID) ps -A PID ProcessKill -9login login nnn nnn PID -9Unix,Linux ( User Login) login [fp] (UserName) #login:rootmkdir directory ( dos)make directory mkdirmkdir [option] [file] option mkdir-m Permissioin ( chmod-p Parent Directory directory relative absolute pathmkdir /home
  • 12. mkdir -p -m755 ~/home/user1mv Directory dos) move mv source target mv *.tar /backupmv test.txt old.txtmv bin oldbinmore cat more more file more=qh help more test.txtman man Unix,Linux ( man (Command) #man ls
  • 13. q; Spacebar] ;mount mount Unix,Linux ( mount (-t type) DeviceDriverMountPoint # Mount 1 CdRom mount -t iso9660 /dev/cdrom/mnt/cdrom# Mount CdRom 2 mount /dev/cdrom ( mount CDmnt/CdRom Unmount)rmdir directory ( dos)remove directoryrmdir [option] [file] option mkdir -p Child ParentDirectorydirectory relative absolute path rmdir/hometar backup restore file tardirectory file permission( UNIX) tape archive tar [option]... [file]...
  • 14. option echo-c backup)-t backup-v-f file-x restore tar -xvf data.tartalk 2 Talk talk user[@host] [tty] hostytalk 2 tty Log in 1 talk m2k@nanastreet.comwrite write user [tty] write
  • 15. writeEOF CTRL+C interrupt writeEnter write m2kwho am i login login whoami who am i ( SUN OS UNIXfile file DOS/Windows UNIX Context file Content file [option]... file file /bin/sh file report1.doc
  • 16. free free [-b|-k|-m] option free-b byte-k kilobyte-m megabyte free free –b free -kpwd Directory cd DOS) print work directory pwduname OS cpu uname -ahostname hostnametty terminal ttyid id
  • 17. LINUX UNIX (Linux 2)1.1 ls : home directory-------------------------------------------------------------------------------- account linux home directorylinux ls parameter -al --sortls -alt :: altls -alt | more :: 1ls -al --sort=time | more ::ls -R | more :: directoryls ls -l D Column ls -aldirectory--------------------------------------------------------------------------------1.2 chmod : Owner), Group), Other)-------------------------------------------------------------------------------- ls RWXRWXRWX webmaster
  • 18. 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 9333RWX------ : 700)RWXRWX--- :770)RWXR-XR-X : 755)R--R--R-- : 444)
  • 19. chmod 777 index.php :: 3chmod 755 * -Rf :: direcroty--------------------------------------------------------------------------------1.3 man : Manual)-------------------------------------------------------------------------------- unix linux parameterlinux manman man :: manman ls :: lsman useradd :: useradd--------------------------------------------------------------------------------1.4 mkdir, rmdir, cd : directory-------------------------------------------------------------------------------- dos directory directory 3 mkdir directory (Make directory) rm directory(Remove directory) cd
  • 20. directory (Change directory)mkdir hello :: directory hellormdir hello.htm :: hello.htmcd / :: directory rootcd .. :: directory 1cd ~/x :: x home directory home/thaiall/x homedirectory home/thaiall--------------------------------------------------------------------------------1.5 pico : editor text vi-------------------------------------------------------------------------------- pico enter ^ Ctrl pico xxxx xx xx Ctrl-X vi pico pine picopine CD rpm -i pine*
  • 21. --------------------------------------------------------------------------------1.6 emacs : editor text vi-------------------------------------------------------------------------------- picopico emacs ctrl-h ctrl-x+ ctrl-c pico editor emacs picoemacsWelcome to GNU Emacs, one component of a Linux-basedGNU system.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 thecharacter.)--------------------------------------------------------------------------------1.7 vi : editor text--------------------------------------------------------------------------------Text editor linuxpico mail pine vi linux man
  • 22. viescenteriaAddx 1cw:w:q!:wq vi--------------------------------------------------------------------------------1.8 id, finger, who, w :--------------------------------------------------------------------------------id uname :: account unamefinger uname :: account uname last login emailfinger @www.isinthai.com :: loginwho |grepthai :: thaiw ::--------------------------------------------------------------------------------1.9 cat : type DOS
  • 23. --------------------------------------------------------------------------------cat /etc/passwd :: etc/passwdcat /etc/passwd | more :: etc/passwd passwd suwit:x:500:500:Suwit:/home/suwit:/bin/bashprasert: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--------------------------------------------------------------------------------
  • 24. 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 0 www.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) isrunning...mysqld (pid 446 429 427 414) is running...
  • 25. 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 talkserver-------------------------------------------------------------------------------- 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
  • 26. --------------------------------------------------------------------------------1.14 whereis : PATH find--------------------------------------------------------------------------------whereisusermod :: usermod runwhereisifconfig :: ifconfigsbin/ifconfig--------------------------------------------------------------------------------1.15 cp, rm, mv :--------------------------------------------------------------------------------cp x y :: x y xcprm y :: y directoryrm -r directoryname :: directory sundirectory confirmrm -rfdirectoryname :: directory Redhatdirectory confirmrm -f * :: yesmv x /root :: x root--------------------------------------------------------------------------------1.16 ping : ip internetping www.thaiall.com :: www.thaiall.comIP
  • 27. ping 202.29.78.100 -c 5 :: 5ping 202.29.78.2 :: ipPING 202.29.78.2 (202.29.78.2)from 202.29.78.12 : 56(84) bytes of data. From 202.29.78.12icmp_seq=1Destination Host Unreachable From 202.29.78.12 icmp_seq=2DestinationHost Unreachable From 202.29.78.12 icmp_seq=3 Destination HostUnreachable--------------------------------------------------------------------------------1.17 env : environment--------------------------------------------------------------------------------envHISTSIZE=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=/root
  • 28. SHLVL=2LOGNAME=burinLESSOPEN=|/usr/bin/lesspipe.sh %sG_BROKEN_FILENAMES=1_=/bin/env--------------------------------------------------------------------------------1.18 lynx : Text browser source download--------------------------------------------------------------------------------lynx www.thaiall.com :: www.thaiall.com text modelynx http://www.yonok.ac.th :: www.yonok.ac.th textmodelynx -dump http://www.yonok.ac.th :: interactive viewlynx -dump -width=500 http://piology.org/.procmailrc.html|grep ^||cut -c3- ::--------------------------------------------------------------------------------1.19 nslookup : name server ip domainname-------------------------------------------------------------------------------- Redhat dig host hostyn1.yonok.ac.th dig yn1.yonok.ac.thnslookup exit >nslookup 202.28.18.65Non-authoritative answer:65.18.28.202.in-addr.arpa name = mars.uni.net.th.
  • 29. 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.65nslookup www.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 roottail /var/log/html/access.log :: 10 defaulttail --lines=100 /var/log/html/access_log>access_bak :: backup mv--------------------------------------------------------------------------------1.21 telnet : server portserver telnet SSH--------------------------------------------------------------------------------telnet 202.202.202.202 :: 202.202.202.202 port port 23
  • 30. telnet www.school.net.th 21 :: port 21 FTP porttelnet mail.loxinfo.co.th 25 :: smtptelnet class.yonok.ac.th 110 :: pop service windows server2003 Microsoft Windows POP3 Service Version 1.0 ready.USER aa@class.yonok.ac.th +OK PASS xxxxxxx +OK User successfullylogged on--------------------------------------------------------------------------------2.1 df : Harddisk-------------------------------------------------------------------------------- Harddisk upload userserver cleardf ::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
  • 31. du :: directorydu -all :: directorydu | sort -g :: directory sort Kbdu -b :: byte directory--------------------------------------------------------------------------------2.3 ps : Process-------------------------------------------------------------------------------- run bot serverps :: processps -ef :: processps -ax :: processps -aux :: process--------------------------------------------------------------------------------2.4 kill : process process kill process-------------------------------------------------------------------------------- process process kill superuser
  • 32. kill -9 process :: process ps -efkill -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 :: gzipgzip -d radius-1.16.1.tar.Z :: ftp.livingston.com/pub/le/radius/gzip -dc x.tar.Z|tarxvf - :: 2 gzip tar x.tar.z--------------------------------------------------------------------------------2.7 tar : tar--------------------------------------------------------------------------------
  • 33. tar xvf x.tar :: tardirectorytar xvfz squid-2.3-200103110000-src.tar.gz :: gztar gzip tarman tar :: tartar zcvf abc.tar.gz /etc :: copy /etc abc.tar.gztar zxvf abc.tar.gz :: abc.tar.gz directory/etc--------------------------------------------------------------------------------2.8 last : login--------------------------------------------------------------------------------last |grep reboot :: rebootlast |more :: login--------------------------------------------------------------------------------2.9 grep :--------------------------------------------------------------------------------more /etc/passwd|grepthaiall ::etc/passwd thaiallrpm -qa|grep ftp :: ftplast |grep reboot :: reboot--------------------------------------------------------------------------------2.10 date : date [OPTION][MMDDhhmm[[CC]YY][.ss]]--------------------------------------------------------------------------------date +%x :: 04/27/01
  • 34. date +%d :: 27date 04271340 :: 27 4 13.40mmddhhmmccyy)hwclock --systohc :: date restart hardwareclock hardware--------------------------------------------------------------------------------2.11 top :--------------------------------------------------------------------------------top :: processRedhat 8.0CPU states: 0.5% user, 1.3% system, 0.0% nice, 98.0% idleMem: 31328K av, 28872K used, 2456K free, 0K shrd, 1032KbuffSwap: 1718912K av, 2608K used, 1716304K free 16528Kcached 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--------------------------------------------------------------------------------
  • 35. 2.12 ntsysv setup :--------------------------------------------------------------------------------setup :: system services server httpd, imap, ipop3, iptables,named, network, sendmail, servers, services, vsftpd, xinetdweb, mail, ftp dnsntsysv :: setup, services( RH--------------------------------------------------------------------------------2.13 route :--------------------------------------------------------------------------------# routeKernel IP routing 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 :--------------------------------------------------------------------------------
  • 36. shutdown -h now halt :: 1reboot 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 / :: harddiskharddisk#fsck /dev/hdc :: harddisk dev/hdc harddisk--------------------------------------------------------------------------------2.17 chown, chgrp :-------------------------------------------------------------------------------- 1.2 chmod 3#chownburin:users x :: x burin users
  • 37. #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 havenetworking)# 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 systemservices#/sbin/chkconfig --list :: level#/sbin/chkconfig --level 3 sendmail on :: sendmaillevel 3 (Text mode)
  • 38. #/sbin/chkconfig --level 5 sendmail on :: sendmaillevel 5 (X Windows)--------------------------------------------------------------------------------2.19 mount, umount : partition Diskette Handy drive-------------------------------------------------------------------------------- mount harddisk server 1harddisk hdc fdisk -l partition 1 hdc x #mkdir /x #mount /dev/hdc1 /x x h

×