Configuraton IP Address
Type following:
sudo nano /etc/network/interfaces
it will appear page for config ip address
Restart Stop and Start Network
Type following:
/etc/init.d/networking restart
**start or stop
วันพฤหัสบดีที่ 7 มิถุนายน พ.ศ. 2555
Secure Shell on Linux (SSH)
Ubuntu Linux: Start OpenSSH Server
Type the following command:$ sudo /etc/init.d/ssh start
OR
$ sudo service ssh start
Ubuntu Linux: Stop OpenSSH server
Type the following command:$ sudo /etc/init.d/ssh stop
OR
$ sudo service ssh stop
Ubuntu Linux: Restart OpenSSH server
Type the following command:$ sudo /etc/init.d/ssh restart
OR
$ sudo service ssh restart
Change Password on MySQL 5
วิธีตั้งรหัสผ่านของ root ใหม่ใน MySQL 5
# service mysqld stop
# mysqld_safe --skip-grant-tables &
# mysql
> UPDATE mysql.user SET Password=PASSWORD('newpassword') WHERE User='root';
> FLUSH PRIVILEGES;
> quit
# killall mysqld
# service mysqld restart
ทดลอง login ด้วยรหัสผ่านใหม่
# mysql -u root -pnewpassword
Linux Shell: using grep
วิธีการทำงานของคำสั่ง grep คือจะอ่านไฟล์ที่เราต้องการค้นหาทีละบรรทัด แล้วดูว่าตรง (match) กับคำหรือรูปแบบที่เราต้องการค้นหาหรือไม่ ซึ่งผลลัพธ์โดยดีฟอลต์ที่ได้จากการรันคำสั่ง จะแสดงผลลัพธ์เป็นบรรทัดต่างๆ ที่ตรงกับคำหรือรูปแบบนั้นๆ
วิธีการใช้คำสั่ง
$ grep [OPTION] [FILE]
เราจะทดลองใช้คำสั่ง grep กับไฟล์ /etc/passwd เพื่อหาข้อมูลที่ต้องการ โดยไฟล์ /etc/passwd นี้จะมีรูปแบบการเก็บแยกเป็นบรรทัดอยู่แล้ว
ตัวอย่างไฟล์ /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
...
เริ่มต้นการใช้คำสั่ง grep
เริ่มต้นสมมติว่าเราต้องการหาคำว่า root ในไฟล์ /etc/passwd ว่ามีอยู่ในบรรทัดใดบ้าง สามารถทำได้ดังนี้
$ grep root /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
ผลลัพธ์ที่ได้จะแสดงบรรทัดที่มีคำว่า root อยู่ด้วย
แสดงเลขบรรทัด (-n)
สามารถแสดงเลขบรรทัดในผลลัพธ์โดยการใส่ option -n ในคำสั่ง grep
$ grep -n root /etc/passwd
1:root:x:0:0:root:/root:/bin/bash
12:operator:x:11:0:operator:/root:/sbin/nologin
ผลลัพธ์จะมีเลขที่บรรทัดกำกับมาด้วย ในที่นี้ คือ 1 และ 12 ก็คือบรรทัดที่ 1 และ 12 นั่นเอง
ไม่แสดงบรรทัดที่มีคำที่ต้องการ (-v)
เช่นเราไม่ต้องการบรรทัดที่มีคำว่า root ก็สามารถทำได้โดยเพิ่ม option -v ลงไป
$ grep -v root /etc/passwd
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
...
ผลลัพธ์ที่ได้จะแสดงบรรทัดอื่นๆ ที่ไม่มีคำว่า root
ระบุรูปแบบในการค้นหา (-E)
ในคำสั่ง grep เราสามารถระบุรูปแบบ (pattern) ในการค้นหาได้หลายแบบ แบบที่นิยมกันอย่างหนึ่งคือใช้ REGULAR EXPRESSION ในที่นี้ต้องใส่ option -E โดยสามารถใช้ REGULAR EXPRESSION เช่นเดียวกับเวลาเราใช้ในการเขียนโปรแกรมภาษาต่างๆ
ตัวอย่างเช่นหาบรรทัดที่ขึ้นต้นด้วยตัวอักษร s
$ grep -E ^s /etc/passwd
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
smmsp:x:51:51::/var/spool/mqueue:/sbin/nologin
smolt:x:497:493:Smolt:/usr/share/smolt:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
squid:x:23:23::/var/spool/squid:/sbin/nologin
จากตัวอย่างเราใช้เคื่องหมาย ^ เพื่อระบุว่าตัวอักษรที่ตามมานั้นเป็นตัวอักษรเริ่มต้นของบรรทัด
ค้นหาจากหลายๆ ไฟล์
บางครั้งมีหลายไฟล์ที่เราต้องการค้นหานั้น ก็สามารถทำได้โดยระบุชื่อไฟล์เป็น * ได้
เช่นค้นหาคำว่า root จากทุกไฟล์ใน /etc/
$ grep root /etc/*
/etc/aliases:postmaster: root
/etc/aliases:bin: root
...
/etc/group:root:x:0:root
/etc/group:bin:x:1:root,bin,daemon
/etc/group:daemon:x:2:root,bin,daemon
...
/etc/passwd:root:x:0:0:root:/root:/bin/bash
/etc/passwd:operator:x:11:0:operator:/root:/sbin/nologin
/etc/passwd-:root:x:0:0:root:/root:/bin/bash
...
/etc/rc.sysinit: if [ "$owner" != root ]; then
/etc/rc.sysinit:if [ -f /etc/sysconfig/readonly-root ]; then
/etc/rc.sysinit: . /etc/sysconfig/readonly-root
..
ผลลัพธ์ที่ได้จะแสดงชื่อไฟล์นำหน้าบรรทัดที่มีคำว่า root
ถ้าต้องการค้นหาภายใต้ sub-directory ย่อยๆ ลงไปด้วย ให้เพิ่ม option -r หลังคำสั่ง grep
Directory on Linux
เป็น Directory หลักๆสำหรับการใช้งานบน ระบบปฏิบัติการ Linux
- bin เก็บคำสั่งต่างๆของระบบ เช่น ls,cp,mv,rmdir,pwd,mail,cat
- boot เก็บไฟล์ต่างๆที่ใช้ในการ boot เช่น boot , map , vmlinuz
- dev เก็บไฟล์ดีไวซ์ของอุปกรณ์ต่าง เช่น Hard Disk , CDROM , Modem
- etc เก็บไฟล์ Configuration,ค่าต่างๆของ LILO, Password
- home เมื่อมี User ใหม่ Account จะถูกสร้างในไดเร็กทอรี่ Home นี้
- lib เก็บไลบราลี่ต่างๆ เช่น ภาษา C เพราะ Linux พัฒนามาจากภาษา C
- mnt เป็นไดเร็กทอรี่ปลายทางในการ Mount อุปกรณ์คือ floppy,CDROM
- root เป็นไดเร็กทอรี่ของผู้ดูแลระบบ
- sbin คล้ายๆกับ bin แต่สำคัญรองลงมา
- tmp ไม่ต้องบอกก็รู้ว่าเก็บอะไร
- usr เป็นไดเร็กทอรี่ที่เก็บโปรแกรมต่างๆ ซี่ง X Windows ก็ถูกเก็บไว้ที่นี่
- var เป็นไดเร็กทอรี่ที่เก็บโปรแกรมต่างๆ,ข้อมูลที่ถูกเรียกใช้โดยระบบ เช่น Cache ของ Web Server หรือ Spool ของเครื่องพิมพ์
Linux Command Line
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 สำรองข้อมูลระหว่างโฮสต์
Printing
- lpr Print files ส่งไฟล์ไปพิมพ์ที่เครื่องพิมพ์
- lpq View print queue เปิดดูลำดับงานพิมพ์ที่ค้างอยู่
- lprm Remove print jobs ยกเลิกงานพิมพ์ที่ค้างอยู่
- Spelling Operations
- look Look up spelling เปิดสารบัญคำศัพท์
- aspell Check spelling interactively ตรวจคำสะกดว่าถูกต้องหรือไม่
- spell Check spelling in batch ตรวจคำถูกผิดในไฟล์จำนวนมาก
Processes
- ps List all processes แสดงโปรเซสทั้งหมด
- w 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 ปรับระดับความสำคัญของโปรเซส
Scheduling Jobs
- sleep Wait for some time หน่วงเวลา
- watch Run programs at set intervals รันโปรแกรมซ้ำในระยะเวลาที่กำหนด
- at Schedule a job ตั้งเวลารันกลุ่มคำสั่ง
- crontab Schedule repeated jobs ตั้งเวลารันคำสั่งเป็นรอบเวลาที่กำหนด
- Hosts
- 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 ตรวจสอบเส้นทางไปสู่โฮสต์ปลายทาง
- 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 บันทึกข้อมูล/แทร็กเสียงลงแผ่นซีดี
วันพุธที่ 6 มิถุนายน พ.ศ. 2555
Ubuntu file system layout?
In Windows there’re perhaps only a couple of important folders (by important I mean important in my logical picture of the Windows file system) in the installation drive (in my case C:\). Namely Program Files and Windows. I simply stay away from Windows folder and the “add remove program files” is good enough to handle the program files folder of Windows. Of course there’s a folder named Users where the users (who are not admins) can access only their folders.
Thus there’s a clear picture at some level in my mind of the Windows file system.
In Ubuntu, when I reach the location / , there’s a huge list of folders, most of which I have no clue as to what they contain.
The /bin folder seems to be the equivalent of the Windows folder in windows.
The /usr folder seems like it’s the equivalent of the Users folder in Windows.
But even the /home folder looks like it can fit the bill.
Please understand that I do understand, that Ubuntu (Linux) has a different character than that of Windows, i.e., there need not be exact equivalent of Windows functions, in Ubuntu. All I am looking for is a bit more clearer picture of the Ubuntu file system.
Underneath the root (/) directory, there is a set of important system directories that are common across most Linux distributions that are used. The following is a listing of common directories that are directly under the root (/) directory:
/bin - important binary applications
/boot - boot configuration files
/dev - the device files
/etc - configuration files, startup scripts, etc...
/home - local users' home directories
/lib - system libraries
/lost+found - provides a lost+found system for files that exist under the root (/) directory
/media - mounted (loaded) removable media such as CDs, digital cameras, etc...
/mnt - mounted filesystems
/opt - provides a location for optional applications to be installed
/proc - special dynamic directory that maintains information about the state of the system, including currently running processes
/root - root user home directory, pronounced 'slash-root'
/sbin - important system binaries
/sys - system files
/tmp - temporary files
Remove Apache on Linux
type on command line
sudo dpkg --get-selections | grep apache
it will display below
apache2 install
apache2-doc install
apache2-mpm-prefork install
apache2-utils install
apache2.2-common install
libapache2-mod-auth-mysql install
libapache2-mod-php5 install
after that type this command to remove packet
sudo apt-get remove apache2 apache2-doc apache2-mpm-prefork apache2-utils apache2.2-common libapache2-mod-auth-mysql libapache2-mod-php5
if have more packet you can add more command with sudo apt-get remove "packet "
when you ENTER you will get warning following this
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
ttf-wqy-zenhei ttf-kannada-fonts libaccess-bridge-java libmcrypt4 libt1-5 ttf-telugu-fonts rhino ttf-oriya-fonts dbconfig-common ttf-bengali-fonts
php5-common
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
apache2 apache2-doc apache2-mpm-prefork apache2-utils apache2.2-common jetty libapache2-mod-auth-mysql libapache2-mod-php5 php5 php5-curl php5-gd
php5-mcrypt php5-mysql phpmyadmin
0 upgraded, 0 newly installed, 14 to remove and 1 not upgraded.
After this operation, 39.1MB disk space will be freed.
Do you want to continue [Y/n]? y
it will ask you, do you want to remove? you can type y and ENTER
sudo dpkg --get-selections | grep apache
it will display below
apache2 install
apache2-doc install
apache2-mpm-prefork install
apache2-utils install
apache2.2-common install
libapache2-mod-auth-mysql install
libapache2-mod-php5 install
after that type this command to remove packet
sudo apt-get remove apache2 apache2-doc apache2-mpm-prefork apache2-utils apache2.2-common libapache2-mod-auth-mysql libapache2-mod-php5
if have more packet you can add more command with sudo apt-get remove "packet "
when you ENTER you will get warning following this
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
ttf-wqy-zenhei ttf-kannada-fonts libaccess-bridge-java libmcrypt4 libt1-5 ttf-telugu-fonts rhino ttf-oriya-fonts dbconfig-common ttf-bengali-fonts
php5-common
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
apache2 apache2-doc apache2-mpm-prefork apache2-utils apache2.2-common jetty libapache2-mod-auth-mysql libapache2-mod-php5 php5 php5-curl php5-gd
php5-mcrypt php5-mysql phpmyadmin
0 upgraded, 0 newly installed, 14 to remove and 1 not upgraded.
After this operation, 39.1MB disk space will be freed.
Do you want to continue [Y/n]? y
it will ask you, do you want to remove? you can type y and ENTER
Install Apache on Linux
Download apache from http://httpd.apache.org/download.cgi
- copy "httpd-2.4.2.tar.gz" to /tmp
- and into /tmp with cd /tmp
- extract file "httpd-2.4.2.tar.gz " with tar -zxvf httpd-2.4.2.tar.gz
- cd httpd-2.4.2/ *open httpd-2.4.2 folder
- ./configure --prefix=/usr/local/apache2
- make
- make install
- restart apache -> /usr/local/apache2/bin/apachectl start
- check apache version ->/usr/local/apache/bin/httpd -v
สมัครสมาชิก:
บทความ (Atom)