Keep walking

Whatever you need to grow, just do it faster…

Posts Tagged ‘Unix’

Unix, Linux, and variants

Posted by ZyK on 11/22/2011

Quick links

Unix ABCs
Linux ABCs
MS-DOS vs. Linux / Unix
Unix and Linux commands
Unix Top 10 commands
Unix Shortcuts
Linux variants
Unix variants
Unix and Linux history
Unix and Linux tips
Unix and Linux links
Linux and Unix news
Linux Q&A

Unix ABCs

Unix, which is not an acronym, was developed by some of the members of the Multics team at the bell labs starting in the late 1960‘s by many of the same people who helped create the C programming language. The Unix today, however, is not just the work of a couple of programmers. Many other organizations, institutes and various other individuals contributed significant additions to the system we now know today.

See additional Unix information and variants and information on the Unix variants page.

Linux ABCs

Developed by Linus Torvalds and further elaborated by a number of developers throughout the world, Linux (lee’nuhks/ or /li’nuks/,_not_/li:’nuhks) is a freely available multitasking and multiuser operating system. From the outset, Linux was placed under General Public License (GPL). The system can be distributed, used and expanded free of charge. In this way, developers have access to all the source codes, thus being able to integrate new functions easily or to find and eliminate programming bugs quickly. Thereby drivers for new adapters (SCSI controller, graphics cards, etc.) can be integrated very rapidly.

See additional Linux information and variants and information on the Linux variants page.

MS-DOS vs. Linux / Unix

If you are able to navigate using MS-DOS, you should be able to quickly pick up on the navigation of Linux and Unix. In the below chart is a listing of common MS-DOS commands with their Linux / Unix counterpart.

MS-DOS Linux / Unix
attrib chmod
backup tar
dir ls
cls clear
copy cp
del rm
deltree rm -R
rmdir
edit vi
pico
format fdformat / mount / umount
move / rename mv
type less <file>
cd cd
chdir
more < file more file
md mkdir
win startx

Linux / Unix Commands

  * See the Linux and Unix overview page for a brief description on all commands on one page.
A a2p | ac | alias | ar | arch | arp | as | at | awk
B basename | bash | bc | bdiff | bfs | bg | biff | break | bs | bye
C cal | calendar | cancel | cat | cc | cd | chdir | checkeq | checknr | chfn | chgrp | chkey | chmod | chown | chsh | cksum | clear | cls | cmp | col | comm | compress | continue | copy | cp | cpio | crontab | csh | csplit | ctags | cu | curl | cut
D date | dc | dd | df | deroff | dhclient | diff | dig | dircmp | dirname | dmesg | dos2unix | dpost | du
E echo | ed | edit | egrepelm | emacs | enable | env | eqn | ex | exit | expand | expr
F fc | fdisk | fg | fgrep | file | find | findsmb | finger | fmt | fold | for | foreach | fromdos | fsck | ftp
G getfacl | gprof | grep | groupadd | groupdel | groupmod | gunzip | gview | gvim | gzip
H halt | hash | hashstat | head | help | history | host | hostid | hostname
I id | ifconfig | ifdown | ifup | ip | init | isalist
J jobs | join
K keylogin | kill | ksh
L last | ld | ldd | less | lex | link | ln | lo | locate | login | logname | logout | lp | lpadmin | lpc | lpq | lpr | lprm | lpstat | ls
M mach | mail | mailcompat | mailx | make | man | merge | mesg | mii-tool | mkdir | mkfs | more | mount | mt | mv | myisamchk | mysql
N nc | neqn | netstat | newalias | newform | newgrp | nice | niscat | nischmod | nischown | nischttl | nisdefaults | nisgrep | nismatch | nispasswd | nistbladm | nmap | nohup | nroff | nslookup
O on | onintr | optisa
P pack | pagesize | passwd | paste | pax | pcat | perl | pg | pgrep | pico | pine | ping | pkill | poweroff | pr | priocntl | printf | ps | pvs | pwd
Q quit
R rcp | reboot | red | rehash | remsh | repeat | replace | rgview | rgvim | rlogin | rm | rmail | rmdir | rn | route | rpcinfo | rsh | rsync | rview | rvim
S s2p | sag | sar | scp | screen | script | sdiff | sed | sendmail | set | setenv | setfacl | settime | sftp | sh | shred | shutdown | sleep | slogin | smbclient | sort | spell | split | stat | stop | strip | stty | su | sudo | sysinfo | sysklogd
T tabs | tac | tail | talk | tar | tbl | tcopy | tcpdump | tee | telinit | telnet | test | time | timex | todos | top | touch | tput | tr | traceroute | tree | troff | tty
U ulumask | unalias | uname | uncompress | unhash | uniq | unmount | unpack | untar | until | unzip | uptime | useradd | userdel | usermod
V vacation | veditvgrind | vi | view | vim | vipw | vmstat
W w | wait | wc | wget | whereis | which  | while| who | whoami | whois | write
X X | xargs | xfd | xlsfonts | xset | xterm | xrdb
Y yacc | yes | yppasswd
Z zcat, zip, zipcloak, zipinfo, zipnote, zipsplit

* In addition to each of the above explanations, additional information about a specified command for your Unix or Linux variant can be found by using the man command.

Posted in UNIX-LINUX | Tagged: , | 1 Comment »

Compare UNIX vs LINUX command

Posted by ZyK on 09/17/2011

UNIX (Linux) command

MS-DOS command

Describe

../ ..\ Thư mục mẹ (ví dụ kết hợp với lệnh cd).
./ .\ Thư mục hiện hành (ví dụ kết hợp với lệnh cd).
/ \ Dấu định giới thư mục.
awk, sed   Khởi động trình soạn thảo theo dòng (Unix).
bash   Viết tắt cho (Bourne Again Shell) – Hệ vỏ ngầm định, cấp thấp.
bc   Khởi động trình tính toán nhị phân.
cancel   Hủy bỏ một đơn vị công việc (job) khỏi  chuỗi in.
cat TYPE Xem nội dung của một file.
cd CD Chuyển đổi thư mục.
clear CLS Xóa màn hình.
cmp COMP So sánh hai file.
compress   Nén file.
cp -p COPY Sao chép file.
cp -R XCOPY Sao chép tất các file trong thư mục.
cron, crond   Đặt lịch biểu để khởi động một chương trình.
csh   Hệ vỏ C.
chgrp   Thay đổi định danh (ID) của file.
chmod   Thay đổi quyền bảo vệ file.
date DATE hoặc TIME Hiển thị ngày tháng.
dc   Khởi động trình tính toán Desktop
dd   Sao chép và chuyển đổi một file đầu vào thành một file đầu ra..
df   Hiển thị dung lượng đĩa còn trống.
diff FC So sánh 2 file và chỉ ra các khác biệt. (Xem thêm mgdiff và tkdiff).
du   Thông báo dung lượng đĩa mà một thư mục chiếm dụng.
echo $PATH PATH Đặt hoặc hiển thị đường dẫn cho file chạy.
echo text ECHO (dòng văn bản) Báo hiệu, hiển thị dòng văn bản lên màn hình.
ed EDLIN Khởi động trình soạn thảo theo dòng.
ex   Khởi động trình soạn thảo theo dòng (có khả năng làm việc cùng lúc với vài file).
exit EXIT Thoát khỏi một chương trình.
fdisk FDISK Tiện ích phân hoạch đĩa cứng.
file   Kiểm tra để xác nhận loại file.
free MEM Hiển thị dung lượng bộ nhớ còn trống trên hệ thống.
fsck SCANDISK Kiểm tra và sửa hệ thống file trên đĩa cứng.
ftp   Truyền file qua mạng từ xa sử dụng giao thức File Transfer Protocol.
grep FIND Tìm một từ hoặc chuỗi từ trong một file văn bản.
gunzip   Giải nén file.
gzip   Nén file.
ifconfig IPCONFIG (NT)
WINIPCFG (Win 9x…)
Hiển thị hoặc cấu hình giao diện mạng.
info   Tương tự lệnh man nhưng chi tiết hơn
kill   Kết thúc một tiến trình.
ksh   Hệ vỏ Korn.
less MORE Hiển thị file văn bản mỗi lần trên một trang.
lpr

PRINT

In một file.
lpstat   Cho biết thông tin về trạng thái hoạt động của máy in hoặc chuỗi in (hàng in).
ls -l (hoặc ls -lF)(-a xem tất cả)
(df -k để xem phân vùng đĩa còn trống bao nhiêu)
DIR Xem nội dung thư mục.
ls -R TREE Xem nội dung thư mục theo nhánh (đệ quy).
lsdev MSD Hiển thị thông tin hệ thống.
man HELP hoặc COMMAND /? Mở trình trợ giúp.
man -k HELP Tìm các lệnh bằng cách tra từ khóa.
mkdir MKDIR Tạo thư mục mới.
mke2fs
Xem: fdformat mformat cho đĩa mềm

FORMAT

Định dạng hệ thống file trên đĩa cứng.
more MORE Hiển thị file văn bản mỗi lần trên một trang.
mv RENAME hoặc MOVE Đổi tên hoặc di chuyển file.
mv tên file .tên file ATTRIB +h hoặc -h Thay đổi thuộc tính của file sang chế độ ẩn. Đổi tên file sang dạng bắt đầu bằng dấu “.” .
nslookup tên máy chủ
host tên máy chủ
NBTSTAT (Netbios info: -n, -c)
NBTSTAT -a tên máy chủ
NBTSTAT -A địa chỉ IP
Hiển thị số liệu thóng kê giao thức và các kết nối TCP/IP hiện hành.
passwd   Thay đổi password đăng nhập.
pico, gnp, vi, xedit, xemacs, dtpad EDIT (tên file.txt) Hiệu chỉnh một file.
pine   Gửi và nhận thư điện tử.
ping PING Kiểm tra đường truyền giữa máy khách và máy chủ.
ps   Cho biết thông tin đầy đủ về một tiến trình.
pwd CHDIR Chỉ ra vị trí thư mục.
quota -v   Cho biết thông tin về giới hạn và năng lực sử dụng đĩa hiện hành.
rlogin   Đăng nhập vào một máy tính ở xa.
rm DEL Xóa file.
rm -R DELTREE Xóa thư mục và các file trong thư mục đó.
rmdir RMDIR Xóa thư mục.
route -n ROUTE PRINT Hiển thị bảng định tuyến.
rsh   Hệ vỏ từ xa dùng để kết nối với máy chủ và thực thi một lệnh nào đó.
set và env SET Đặt các biến môi trường
setenv (cho lớp vỏ C) hoặc export (cho lớp vỏ Korn) SET (tên biến) Đặt các biến môi trường.
sh   Hệ vỏ Bourne.
sleep thời gian   Đưa máy tính vào trạng thái “ngủ”
sort SORT Phân loại dữ liệu theo thứ tự số học hoặc chữ cái.
stty   Thay đổi lựa chọn cho trình Terminal.
stty -a   Thông tin về tình trạng của trình Terminal.
talk NET SEND <tên nút mạng> <tin nhắn> (NT) Gửi tin nhắn tới một người dùng. Giao tiếp với người dùng khác thông qua trình “Terminal”.
tar   Tạo (hoặc trích xuất) các file thành (hoặc từ) một file “tar”.
tar -cvf /dev/fd0 tên file
mdir, mcopy
doswrite -a tên file (chỉ dành cho AIX -  AIX là hệ điều hành UNIX của IBM)
BACKUP tên file A:\ Lưu file tới đĩa mềm.
tar và zip pkzip Nén và giải nén file hoặc thư mục. Dùng lệnh tar để biên dịch thư mục trước khi nén. Linux cũng có lệnh nén compress, gzip.
tar -xvf /dev/fd0 tên file
mdir, mcopy
dosread -a tên file ( chỉ dành cho AIX)
RESTORE A:\ files Đọc file trên đĩa mềm.
tcsh   Hệ vỏ C tăng cường.
telnet   Dùng giao thức “telnet” để giao tiếp với các máy chủ khác.
Tên file Tên file Chạy một chương trình hoặc một tập lệnh.
traceroute TRACERT  Định hướng các tuyết và các bước truyền của bộ định tuyến tới một mạng đích.
umask   Thay đổi bảng hình mẫu (mặt nạ) tạo file ngầm định.
uname -a VER Xem phiên bản hệ điều hành.
uncompress   Giải nén file.
vi, emacs EDIT Khởi động trình soạn thảo đồ họa.
w   Cho biết ai đang đăng nhập và thông tin về hoạt động của người dùng này.
whatis   Mô tả các lệnh.
whereis   Chỉ ra vị trí nguồn, mã nhị phân và các thông tin trợ giúp cho một chường trình.
zsh COMMAND Hệ vỏ Z.

 

Posted in UNIX-LINUX | Tagged: | Leave a Comment »

Useful AIX commands

Posted by ZyK on 08/30/2011

Some Common AIX-Unix Commands – Tech-Recipes.com

  • lsps –a list paging space
  • lsattr –El mem0 list current physical memory
  • extendlv hd6 16 doubled paging space from 512MB to 1024MB
    (only use with IBM direction)
  • smit lsmksysb (list files on a tape from a mksysb)
  • lsdev –Cc disk (shows all disk drives)
  • lscfg –vl hdisk1 (shows info on individual disk drives, s/n, p/n, etc…)
  • lspv shows disks installed on system
  • df –k (shows file system size information)
  • lp filename (prints file to network printer)
  • lpstat (shows print jobs)
  • cancel # (cancels print job by #, found with lpstat)
  • enq –U (restarts print que if status shows it is down–must be root)
  • enq –Q prtx -#xxx (redirects a print job to another print que)
  • ps –ef (shows current system processes)
  • errpt –a (shows system error report including power outages)
  • errclear 0 (completely clears the system errlog viewed with errpt –a)
  • errclear –N sysplanar0 0
    (clears only select items specified by the resource name, ex: sysplanar0)
  • diag (system diagnostics, use the advanced diagnostics section, this helps determine the exact cause of a problem like sysplana0, queries system errlog for info)
  • sort –o list list (stores the sorted output of list back into list)
  • sort –u list (sorts and eliminates duplicate lines)
  • grep –vxf combinedlist masterlist (lists of #’s in masterlist not found in combinedlist)
    ex: combinedlist=mulitple distribution lists containing SAs already downloaded to masterlist=list of all SA salons
    this grep will list out the salons in the masterlist that haven’t been downloaded to.
  • tail –f filename shows last ten lines of a file and monitors for any updates
  • lsattr –El sys0 | grep maxuproc shows maximum number of processes allowed for any one users (this can be increased by going into “smit system”)
  • lsvg –l rootvg (displays disk info including number of logical and physical partitions for each file system. PPs should be double that of LPs if disk is mirrored)
  • comm -12 file1 file2 shows only what lines are in both file1 and file2. (sort both files before running the command) (the -12 suppress columns 1 and 2, what is only in file1 and only in file2)
  • wc filename (lists number of lines, number of words, number of characters in file, useful for distribution lists, can use –c for characters, -w for words, or –l for lines [eg. wc –l filename, etc] )
  • df –Ik shows filesystem disk space; total, used and free (no Inodes).
  • (in vi) :r filename reads in the contents of a file.
  • (in vi) :r !command reads in the output of a command.
  • (in vi) yy p (copy and paste) – yy = yank, p = paste below line, P = paste above line.
  • (in vi) dd p (cut and paste) – dd = cut, p = paste below line, P = paste above line.
  • Ksh –n filename checks for syntax errors in korn shell programs
  • cfgmgr command to get system to recognize new hardware (can be run while system is running – a system boot runs it 3 times)
  • cfgmgr –i /dev/cd0 installs drivers from cd for new hardware (best method)
  • lscfg –vp|grep CL shows current firmware version
  • instfix –i | grep –i aix shows maintenance level for AIX
  • oslevel –r shows operating system level with maintenance level
  • nslookup server name shows the ip address of the server name as it is on the network’s DNS server via the RS6000’s /etc/resolv.conf file. If it can’t resolve the server name, either the “name server” is stopped on the RS6000 (no resolv.conf file present) or there is something wrong with the DNS.
  • /etc/netsvc.conf file containing hosts=local,bind4 this will force the RS6000 to first use the /etc/hosts file and then the DNS if it can’t find it in /etc/hosts. Other wise it will check in the DNS only (if name server is started on the RS6000) and never the hosts file. ???
  • lssrc –g nfs use to check if nfs service is currently running.
  • stopsrc –g nfs use to stop nfs service – (change rcnfs from wait to off in /etc/inittab to prevent it from starting during boo

AIX Commands

compiled by: John Flecther

COMMAND PARAMETER DESCRIPTION
bootlist -m normal <dev1> <dev2> Alters the list of boot devices (or the ordering of these devices in the list available to the system)
bosboot -a-ad /dev/rnt<x>

-b <loc of bootimage>

Create a boot image on the default boot deviceCreate a boot image at location and send to tape
cfgmgr Configures devices by running the programs in /etc/methods directory.
chcons Redirects the system console to device or file, effective next startup
chdev -l <device> -a<params> Changes a device’s characteristics.
chdisp Changes the display used by the low-function terminal (LFT subsystem.
chfont Changes the default font selected at boot time.
chfs -a size=+<blocks> /<FS> Changes attributes of a file system. This one will increase the Filesystem .
chgroup Users=x,y,z <grp name> Changes attributes for groups.
chlv -n <nlvname> <olvname> Rename logical volume from olvname to nlvname
chps -s<no. pps> <ps name> Changes attributes of a paging space.
chpv Changes the characteristics of a physical volume in a volume group.
chque -q<q name> -a’host = x’ Changes the queue name.
chssys Changes a subsystem definition in the subsystem object class.
chtcb Changes or queries the trusted computing base attribute of a file.
chtz. Changes the system time zone information
chuser rlogin=true <username> Changes attributes for the specified user.
chvfs Changes entries in the /etc/vfs file.
chvg Sets the characteristics of a volume group.
crfs -v <fstype> (jfs)-d <lvname>

-m <mount point>

-Ayes

Create a Filesystem on a pre-defined logical volume( which will automount at boot!)
crfs -v <fstype> (jfs)-g <vgname>

-a size=’<no blocks>’

-m <mount point>

-Ayes

Create a Filesystem and its logical volume (uses default lvname)
crvfs Creates entries in the /etc/vfs file.
exportvg None Export a volume group
grpck -n ALL Verifies the correctness of a group definition.
hvirprt Changes the attribute values of a virtual printer.
importvg -y <vgname><hdisk x> Import a Volume Group onto hdisk x
lpstat List print queues
lsallq Lists the names of all configured queues.
lsallqdev Lists all configured printer and plotter queue device names within a specified queue.
lsattr -El <devname> List detailed configuration for a device
lscfg List all configured devices
-v List in detail
-l scsi* List all scsi IO devices
lsdev -Cc tape List configured tape devices
-Cc disk List configured disks on devices
-C -s scsi -H List all defined scsi devices
lsdisp Lists the displays currently available on the system.
lsfont Lists the fonts available for use by the display.
lsfs -l List all filesystems in /etc/filesystems quering the LVM descriptor area and superblocks
lsfs Displays the characteristics of file systems.
lsgroup ALL Displays the attributes of groups.(checks NIS aswell!)
lsitab -a Lists the records in the /etc/inittab file.
lskbd Lists the keyboard maps currently available to the low-function terminal (LFT subsystem.
lslicense Displays the number of fixed licenses and the status of floating licensing.
lslpp -l List all installed software
lslv <lvname> List configuration details of a given Logical Volume
-l <lvname> List further configuration details of a given disk
lsprtsv -ch Shows print service information stored in the database.
lsps -a List pagaing space
lspv None List configured disks
<hdisk> List configuration details of a given disk
-l <hdisk> List Logical Volumes/Filesystems on a given disk
lsque Displays the queue stanza name.
lsquedev Displays the device stanza name.
lssrc -a List all subsystems
lsuser Displays attributes of user accounts.
lsvfs Lists entries in the /etc/vfs file.
lsvg None List configured Volume groups
<vgname> List configuration details of a given Volume group
-l <vgname> List Logical Volumes/Filesystems on a given Volume Group
mkcatdefs Preprocesses a message source file.
mkdev Adds a device to the system.
mkfont Adds the font code associated with a display to the system.
mkfontdir Creates a fonts.dir file from a directory of font files.
mkgroup Creates a new group.
mkitab Makes records in the /etc/inittab file.
mklv -y <lvname><vgname>

<no of pps>

Create a Logical Volume
mklv Creates a logical volume.
mklvcopy Adds copies to a logical volume.
mknamsv Configures TCP/IP-based name service on a host for a client.
mknotify Adds a notify method definition to the notify object class.
mkprtsv Configures TCP/IP-based print service on a host.
mkps Add an additional paging space to the system.
mkque Adds a printer queue to the system.
mkquedev Adds a printer queue device to the system.
mkserver Adds a subserver definition to the subserver object class.
mkssys Adds a subsystem definition to the subsystem object class.
mksysb. Backs up mounted file systems in the rootvg volume group for subsequent reinstallation
mkszfile. Records size of mounted file systems in the rootvg volume group for reinstallation
mktcpip Sets the required values for starting TCP/IP on a host.
mkuser Creates a new user account.
mkuser.sys Customizes a new user account.
Mkvg -y <vgname>-s <ppsize>

<hdisk x>

Create a Volume Group on hdisk x
mkvg Creates a volume group.
mkvirprt Makes a virtual printer.
odmadd Adds objects to created object classes.
odmchange Changes the contents of a selected object in the specified object class.
odmcreate Produces the .c (source and .h (include files necessary for ODM application development and creates empty objectclasses.
odmdelete Deletes selected objects from a specified object class.
odmdrop Removes an object class.
odmget Retrieves objects from the specified object classes and places them into an odmadd input file.
odmshow Displays an object class definition on the screen.
pwdck Verifies the correctness of local authentication information.
redefinevg Redefines the set of physical volumes of the given volume group in the device configuration database.
reducevg Removes physical volumes from a volume group. When all physical volumes are removed from the volume group, the volume group is deleted.
reorgvg Reorganizes the physical partition allocation for a volume group.
restbase Restores customized information from the boot image.
rmdel Removes a delta from a Source Code Control System (SCCS file.
rmdev Removes a device from the system.
rmf Removes folders and the messages they contain.
rmfs Removes a file system.
rmgroup Removes a group.
rmitab Removes records in the /etc/inittab file.
rmlv Removes logical volumes from a volume group.
rmlvcopy Removes copies from a logical volume.
rmm Removes messages.
rmnamsv Unconfigures TCP/IP-based name service on a host.
rmnotify Removes a notify method definition from the notify object class.
rmprtsv Unconfigures a print service on a client or server machine.
rmps Removes a paging space from the system.
rmque Removes a printer queue from the system.
rmquedev Removes a printer or plotter queue device from the system.
rmserver Removes a subserver definition from the subserver object class.
rmssys Removes a subsystem definition from the subsystem object class.
rmuser Removes a user account.
rmvfs Removes entries in the /etc/vfs file.
rmvirprt Removes a virtual printer.
runcat Pipes the output data from the mkcatdefs command to the gencat command.
savebase Saves base customized device data in the ODM onto the boot device.
startsrc -s <subsystem> Start a subsystem
stopsrc -s <subsystem> Stop a subsystem
syncvg Synchronizes logical volume copies that are not current.
usrck Verifies the correctness of a user definition.
varyoffvg <vgname> Takes a Volume Group offline
varyoffvg Deactivates a volume group.
varyonvg <vgname> Puts a Volume Group online
varyonvg Activates a volume group.

(http://www.softpanorama.org/Commercial_unixes/AIX/Reference/useful_aix_commands.shtml)

Posted in UNIX-LINUX | Tagged: , | 2 Comments »

20 Linux System Monitoring Tools Every SysAdmin Should Know

Posted by ZyK on 08/08/2011

Need to monitor Linux server performance? Try these built-in command and a few add-on tools. Most Linux distributions are equipped with tons of monitoring. These tools provide metrics which can be used to get information about system activities. You can use these tools to find the possible causes of a performance problem. The commands discussed below are some of the most basic commands when it comes to system analysis and debugging server issues such as:

  1. Finding out bottlenecks.
  2. Disk (storage) bottlenecks.
  3. CPU and memory bottlenecks.
  4. Network bottlenecks.

#1: top – Process Activity Command

The top program provides a dynamic real-time view of a running system i.e. actual process activity. By default, it displays the most CPU-intensive tasks running on the server and updates the list every five seconds.

Fig.01: Linux top commandFig.01: Linux top command

Commonly Used Hot Keys

The top command provides several useful hot keys:

Hot Key Usage
t Displays summary information off and on.
m Displays memory information off and on.
A Sorts the display by top consumers of various system resources. Useful for quick identification of performance-hungry tasks on a system.
f Enters an interactive configuration screen for top. Helpful for setting up top for a specific task.
o Enables you to interactively select the ordering within top.
r Issues renice command.
k Issues kill command.
z Turn on or off color/mono

=> Related: How do I Find Out Linux CPU Utilization?

#2: vmstat – System Activity, Hardware and System Information

The command vmstat reports information about processes, memory, paging, block IO, traps, and cpu activity.
# vmstat 3
Sample Outputs:

procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0      0 2540988 522188 5130400    0    0     2    32    4    2  4  1 96  0  0
 1  0      0 2540988 522188 5130400    0    0     0   720 1199  665  1  0 99  0  0
 0  0      0 2540956 522188 5130400    0    0     0     0 1151 1569  4  1 95  0  0
 0  0      0 2540956 522188 5130500    0    0     0     6 1117  439  1  0 99  0  0
 0  0      0 2540940 522188 5130512    0    0     0   536 1189  932  1  0 98  0  0
 0  0      0 2538444 522188 5130588    0    0     0     0 1187 1417  4  1 96  0  0
 0  0      0 2490060 522188 5130640    0    0     0    18 1253 1123  5  1 94  0  0

Display Memory Utilization Slabinfo

# vmstat -m

Get Information About Active / Inactive Memory Pages

# vmstat -a
=> Related: How do I find out Linux Resource utilization to detect system bottlenecks?

#3: w – Find Out Who Is Logged on And What They Are Doing

w command displays information about the users currently on the machine, and their processes.
# w username
# w vivek

Sample Outputs:

 17:58:47 up 5 days, 20:28,  2 users,  load average: 0.36, 0.26, 0.24
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    10.1.3.145       14:55    5.00s  0.04s  0.02s vim /etc/resolv.conf
root     pts/1    10.1.3.145       17:43    0.00s  0.03s  0.00s w

#4: uptime – Tell How Long The System Has Been Running

The uptime command can be used to see how long the server has been running. The current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes.
# uptime
Output:

 18:02:41 up 41 days, 23:42,  1 user,  load average: 0.00, 0.00, 0.00

1 can be considered as optimal load value. The load can change from system to system. For a single CPU system 1 – 3 and SMP systems 6-10 load value might be acceptable.

#5: ps – Displays The Processes

ps command will report a snapshot of the current processes. To select all processes use the -A or -e option:
# ps -A
Sample Outputs:

  PID TTY          TIME CMD
    1 ?        00:00:02 init
    2 ?        00:00:02 migration/0
    3 ?        00:00:01 ksoftirqd/0
    4 ?        00:00:00 watchdog/0
    5 ?        00:00:00 migration/1
    6 ?        00:00:15 ksoftirqd/1
....
.....
 4881 ?        00:53:28 java
 4885 tty1     00:00:00 mingetty
 4886 tty2     00:00:00 mingetty
 4887 tty3     00:00:00 mingetty
 4888 tty4     00:00:00 mingetty
 4891 tty5     00:00:00 mingetty
 4892 tty6     00:00:00 mingetty
 4893 ttyS1    00:00:00 agetty
12853 ?        00:00:00 cifsoplockd
12854 ?        00:00:00 cifsdnotifyd
14231 ?        00:10:34 lighttpd
14232 ?        00:00:00 php-cgi
54981 pts/0    00:00:00 vim
55465 ?        00:00:00 php-cgi
55546 ?        00:00:00 bind9-snmp-stat
55704 pts/1    00:00:00 ps

ps is just like top but provides more information.

Show Long Format Output

# ps -Al
To turn on extra full mode (it will show command line arguments passed to process):
# ps -AlF

To See Threads ( LWP and NLWP)

# ps -AlFH

To See Threads After Processes

# ps -AlLm

Print All Process On The Server

# ps ax
# ps axu

Print A Process Tree

# ps -ejH
# ps axjf
# pstree

Print Security Information

# ps -eo euser,ruser,suser,fuser,f,comm,label
# ps axZ
# ps -eM

See Every Process Running As User Vivek

# ps -U vivek -u vivek u

Set Output In a User-Defined Format

# ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm
# ps axo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm
# ps -eopid,tt,user,fname,tmout,f,wchan

Display Only The Process IDs of Lighttpd

# ps -C lighttpd -o pid=
OR
# pgrep lighttpd
OR
# pgrep -u vivek php-cgi

Display The Name of PID 55977

# ps -p 55977 -o comm=

Find Out The Top 10 Memory Consuming Process

# ps -auxf | sort -nr -k 4 | head -10

Find Out top 10 CPU Consuming Process

# ps -auxf | sort -nr -k 3 | head -10

#6: free – Memory Usage

The command free displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel.
# free
Sample Output:

            total       used       free     shared    buffers     cached
Mem:      12302896    9739664    2563232          0     523124    5154740
-/+ buffers/cache:    4061800    8241096
Swap:      1052248          0    1052248

=> Related: :

  1. Linux Find Out Virtual Memory PAGESIZE
  2. Linux Limit CPU Usage Per Process
  3. How much RAM does my Ubuntu / Fedora Linux desktop PC have?

#7: iostat – Average CPU Load, Disk Activity

The command iostat report Central Processing Unit (CPU) statistics and input/output statistics for devices, partitions and network filesystems (NFS).
# iostat
Sample Outputs:

Linux 2.6.18-128.1.14.el5 (www03.nixcraft.in) 	06/26/2009

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           3.50    0.09    0.51    0.03    0.00   95.86

Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
sda              22.04        31.88       512.03   16193351  260102868
sda1              0.00         0.00         0.00       2166        180
sda2             22.04        31.87       512.03   16189010  260102688
sda3              0.00         0.00         0.00       1615          0

=> Related: : Linux Track NFS Directory / Disk I/O Stats

#8: sar – Collect and Report System Activity

The sar command is used to collect, report, and save system activity information. To see network counter, enter:
# sar -n DEV | more
To display the network counters from the 24th:
# sar -n DEV -f /var/log/sa/sa24 | more
You can also display real time usage using sar:
# sar 4 5
Sample Outputs:

Linux 2.6.18-128.1.14.el5 (www03.nixcraft.in) 		06/26/2009

06:45:12 PM       CPU     %user     %nice   %system   %iowait    %steal     %idle
06:45:16 PM       all      2.00      0.00      0.22      0.00      0.00     97.78
06:45:20 PM       all      2.07      0.00      0.38      0.03      0.00     97.52
06:45:24 PM       all      0.94      0.00      0.28      0.00      0.00     98.78
06:45:28 PM       all      1.56      0.00      0.22      0.00      0.00     98.22
06:45:32 PM       all      3.53      0.00      0.25      0.03      0.00     96.19
Average:          all      2.02      0.00      0.27      0.01      0.00     97.70

=> Related: : How to collect Linux system utilization data into a file

#9: mpstat – Multiprocessor Usage

The mpstat command displays activities for each available processor, processor 0 being the first one. mpstat -P ALL to display average CPU utilization per processor:
# mpstat -P ALL
Sample Output:

Linux 2.6.18-128.1.14.el5 (www03.nixcraft.in)	 	06/26/2009

06:48:11 PM  CPU   %user   %nice    %sys %iowait    %irq   %soft  %steal   %idle    intr/s
06:48:11 PM  all    3.50    0.09    0.34    0.03    0.01    0.17    0.00   95.86   1218.04
06:48:11 PM    0    3.44    0.08    0.31    0.02    0.00    0.12    0.00   96.04   1000.31
06:48:11 PM    1    3.10    0.08    0.32    0.09    0.02    0.11    0.00   96.28     34.93
06:48:11 PM    2    4.16    0.11    0.36    0.02    0.00    0.11    0.00   95.25      0.00
06:48:11 PM    3    3.77    0.11    0.38    0.03    0.01    0.24    0.00   95.46     44.80
06:48:11 PM    4    2.96    0.07    0.29    0.04    0.02    0.10    0.00   96.52     25.91
06:48:11 PM    5    3.26    0.08    0.28    0.03    0.01    0.10    0.00   96.23     14.98
06:48:11 PM    6    4.00    0.10    0.34    0.01    0.00    0.13    0.00   95.42      3.75
06:48:11 PM    7    3.30    0.11    0.39    0.03    0.01    0.46    0.00   95.69     76.89

=> Related: : Linux display each multiple SMP CPU processors utilization individually.

#10: pmap – Process Memory Usage

The command pmap report memory map of a process. Use this command to find out causes of memory bottlenecks.
# pmap -d PID
To display process memory information for pid # 47394, enter:
# pmap -d 47394
Sample Outputs:

47394:   /usr/bin/php-cgi
Address           Kbytes Mode  Offset           Device    Mapping
0000000000400000    2584 r-x-- 0000000000000000 008:00002 php-cgi
0000000000886000     140 rw--- 0000000000286000 008:00002 php-cgi
00000000008a9000      52 rw--- 00000000008a9000 000:00000   [ anon ]
0000000000aa8000      76 rw--- 00000000002a8000 008:00002 php-cgi
000000000f678000    1980 rw--- 000000000f678000 000:00000   [ anon ]
000000314a600000     112 r-x-- 0000000000000000 008:00002 ld-2.5.so
000000314a81b000       4 r---- 000000000001b000 008:00002 ld-2.5.so
000000314a81c000       4 rw--- 000000000001c000 008:00002 ld-2.5.so
000000314aa00000    1328 r-x-- 0000000000000000 008:00002 libc-2.5.so
000000314ab4c000    2048 ----- 000000000014c000 008:00002 libc-2.5.so
.....
......
..
00002af8d48fd000       4 rw--- 0000000000006000 008:00002 xsl.so
00002af8d490c000      40 r-x-- 0000000000000000 008:00002 libnss_files-2.5.so
00002af8d4916000    2044 ----- 000000000000a000 008:00002 libnss_files-2.5.so
00002af8d4b15000       4 r---- 0000000000009000 008:00002 libnss_files-2.5.so
00002af8d4b16000       4 rw--- 000000000000a000 008:00002 libnss_files-2.5.so
00002af8d4b17000  768000 rw-s- 0000000000000000 000:00009 zero (deleted)
00007fffc95fe000      84 rw--- 00007ffffffea000 000:00000   [ stack ]
ffffffffff600000    8192 ----- 0000000000000000 000:00000   [ anon ]
mapped: 933712K    writeable/private: 4304K    shared: 768000K

The last line is very important:

  • mapped: 933712K total amount of memory mapped to files
  • writeable/private: 4304K the amount of private address space
  • shared: 768000K the amount of address space this process is sharing with others

=> Related: : Linux find the memory used by a program / process using pmap command

#11 and #12: netstat and ss – Network Statistics

The command netstat displays network connections, routing tables, interface statistics, masquerade connections, and multicast memberships. ss command is used to dump socket statistics. It allows showing information similar to netstat. See the following resources about ss and netstat commands:

#13: iptraf – Real-time Network Statistics

The iptraf command is interactive colorful IP LAN monitor. It is an ncurses-based IP LAN monitor that generates various network statistics including TCP info, UDP counts, ICMP and OSPF information, Ethernet load info, node stats, IP checksum errors, and others. It can provide the following info in easy to read format:

  • Network traffic statistics by TCP connection
  • IP traffic statistics by network interface
  • Network traffic statistics by protocol
  • Network traffic statistics by TCP/UDP port and by packet size
  • Network traffic statistics by Layer2 address
Fig.02: General interface statistics: IP traffic statistics by network interface Fig.02: General interface statistics: IP traffic statistics by network interface

Fig.03 Network traffic statistics by TCP connectionFig.03 Network traffic statistics by TCP connection

#14: tcpdump – Detailed Network Traffic Analysis

The tcpdump is simple command that dump traffic on a network. However, you need good understanding of TCP/IP protocol to utilize this tool. For.e.g to display traffic info about DNS, enter:
# tcpdump -i eth1 'udp port 53'
To display all IPv4 HTTP packets to and from port 80, i.e. print only packets that contain data, not, for example, SYN and FIN packets and ACK-only packets, enter:
# tcpdump 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'
To display all FTP session to 202.54.1.5, enter:
# tcpdump -i eth1 'dst 202.54.1.5 and (port 21 or 20'
To display all HTTP session to 192.168.1.5:
# tcpdump -ni eth0 'dst 192.168.1.5 and tcp and port http'
Use wireshark to view detailed information about files, enter:
# tcpdump -n -i eth1 -s 0 -w output.txt src or dst port 80

#15: strace – System Calls

Trace system calls and signals. This is useful for debugging webserver and other server problems. See how to use to trace the process and see What it is doing.

#16: /Proc file system – Various Kernel Statistics

/proc file system provides detailed information about various hardware devices and other Linux kernel information. See Linux kernel /proc documentations for further details. Common /proc examples:
# cat /proc/cpuinfo
# cat /proc/meminfo
# cat /proc/zoneinfo
# cat /proc/mounts

17#: Nagios – Server And Network Monitoring

Nagios is a popular open source computer system and network monitoring application software. You can easily monitor all your hosts, network equipment and services. It can send alert when things go wrong and again when they get better. FAN is “Fully Automated Nagios”. FAN goals are to provide a Nagios installation including most tools provided by the Nagios Community. FAN provides a CDRom image in the standard ISO format, making it easy to easilly install a Nagios server. Added to this, a wide bunch of tools are including to the distribution, in order to improve the user experience around Nagios.

18#: Cacti – Web-based Monitoring Tool

Cacti is a complete network graphing solution designed to harness the power of RRDTool’s data storage and graphing functionality. Cacti provides a fast poller, advanced graph templating, multiple data acquisition methods, and user management features out of the box. All of this is wrapped in an intuitive, easy to use interface that makes sense for LAN-sized installations up to complex networks with hundreds of devices. It can provide data about network, CPU, memory, logged in users, Apache, DNS servers and much more. See how to install and configure Cacti network graphing tool under CentOS / RHEL.

#19: KDE System Guard – Real-time Systems Reporting and Graphing

KSysguard is a network enabled task and system monitor application for KDE desktop. This tool can be run over ssh session. It provides lots of features such as a client/server architecture that enables monitoring of local and remote hosts. The graphical front end uses so-called sensors to retrieve the information it displays. A sensor can return simple values or more complex information like tables. For each type of information, one or more displays are provided. Displays are organized in worksheets that can be saved and loaded independently from each other. So, KSysguard is not only a simple task manager but also a very powerful tool to control large server farms.

Fig.05 KDE System GuardFig.05 KDE System Guard {Image credit: Wikipedia}

See the KSysguard handbook for detailed usage.

#20: Gnome System Monitor – Real-time Systems Reporting and Graphing

The System Monitor application enables you to display basic system information and monitor system processes, usage of system resources, and file systems. You can also use System Monitor to modify the behavior of your system. Although not as powerful as the KDE System Guard, it provides the basic information which may be useful for new users:

  • Displays various basic information about the computer’s hardware and software.
  • Linux Kernel version
  • GNOME version
  • Hardware
  • Installed memory
  • Processors and speeds
  • System Status
  • Currently available disk space
  • Processes
  • Memory and swap space
  • Network usage
  • File Systems
  • Lists all mounted filesystems along with basic information about each.
Fig.06 The Gnome System Monitor applicationFig.06 The Gnome System Monitor application

Bonus: Additional Tools

A few more tools:

  • nmap – scan your server for open ports.
  • lsof – list open files, network connections and much more.
  • ntop web based tool – ntop is the best tool to see network usage in a way similar to what top command does for processes i.e. it is network traffic monitoring software. You can see network status, protocol wise distribution of traffic for UDP, TCP, DNS, HTTP and other protocols.
  • Conky – Another good monitoring tool for the X Window System. It is highly configurable and is able to monitor many system variables including the status of the CPU, memory, swap space, disk storage, temperatures, processes, network interfaces, battery power, system messages, e-mail inboxes etc.
  • GKrellM – It can be used to monitor the status of CPUs, main memory, hard disks, network interfaces, local and remote mailboxes, and many other things.
  • vnstat – vnStat is a console-based network traffic monitor. It keeps a log of hourly, daily and monthly network traffic for the selected interface(s).
  • htop – htop is an enhanced version of top, the interactive process viewer, which can display the list of processes in a tree form.
  • mtr – mtr combines the functionality of the traceroute and ping programs in a single network diagnostic tool.

By cyberciti

Posted in UNIX-LINUX | Tagged: , | 3 Comments »

Unix command to find CPU Utilization

Posted by ZyK on 08/08/2011

Under Sun Solaris UNIX (and other UNIX oses like HP-UX and *BSD oses) you can use following commands to gather CPU information:

=> sar : System activity reporter

=> mpstat : Report per-processor or per-processor-set statistics

=> ps / top commands

Note: Linux specific CPU utilization information is here. Following information applies to UNIX only.

UNIX sar command examples

General syntax is as follows:
sar t [n]
In the first instance, sar samples cumulative activity counters in the operating system at n intervals of t seconds, where t should be 5 or greater. If t is specified with more than one option, all headers are printed together and the output may be difficult to read.

Task: Display today’s CPU activity, use

# sar

Task:Watching system activity evolve i.e. reports CPU Utilization

# sar -u 12 5

Where,

  • -u 12 5: Comparison of CPU utilization; 12 seconds apart; 5 times.

Output includes:

  1. %usr: User time (% of CPU)
  2. %sys: System time (% of CPU)
  3. %wio: Percent of CPU running idle with a process waiting for block I/O
  4. %idle: Percent of CPU that is idle

Task: You can watch CPU activity evolve for 10 minutes and save data

# sar -o file-name 60 10

Task: You can just sar and logout and let the report store in files

# nohup sar -A -o output-file 60 10 1>/dev/null 2>&1 &
Note to display data stored in output-file pass -f option to sar command:
# sar -f output-file

UNIX mpstat example

Type the following command to display per-processor statistics; 12 seconds apart; 5 times
# mpstat 12 5

You can also use traditional ps and top command:
# top
# ps -e -o pcpu -o pid -o user -o args

In Unix, you can see CPU usage on a job that is running in a number of ways, as described below:

The time command

If you want to see a grand total of CPU time for a program when it finishes running, you can use the time command. At the Unix prompt, enter:

time myprog

Replace myprog with the name of the program you are running. The following is an output example for users in the csh or tcsh shells:

1.406u 0.042s 0:04.96 29.0% 2+5k 0+1io 0pf+0w

The program myprog used 1.406 seconds of user time, 0.042 seconds of system time, and 4.96 seconds of real time. The sum of the user and system times is the total CPU time of the process. The percentage (29.0%) indicates the percentage of the CPU’s time that the process used while it ran. The output will appear in a slightly different format when using sh, ksh, or bash, since the time command is not built into those shells.

The ps command

You can also use the Unix command ps. At the Unix prompt, enter:

ps -u username

Replace username with your username. You will see something like the following:

PID TTY TIME COMMAND 10005 ? 3:03 a.out 15852 rb 0:01 -tcsh (tcsh) 24980 rb 0:00 sh -c /usr/local/bin/emacs /usr1/mmouse/snd.18106 24981 rb 0:02 /usr/local/bin/emacs /usr1/mmouse/snd.18106 22311 rf 0:22 elm

In this example, the “TIME” column shows that the process running Elm has used 22 CPU seconds.

 

Posted in UNIX-LINUX | Tagged: , | 1 Comment »

Adding a Hard Drive in Linux

Posted by ZyK on 07/28/2011

Adding New Drives

There are many reasons why you would need to add a new drive to your Linux box. You might have out-grown your current space limitations, or you may want to add a separate drive for a specific project or service. In any case, if you follow this guide, you should have no problems. First, you must be familiar with the naming scheme Linux uses for your drives. For purposes if this article, everything highlighted in blue is the command you must type at the terminal prompt. Anything hightlighted in red indicates changes made by a previous command or something you should pay special attention to. Anything highlighted in green is simply the standard output from a terminal or issued command. The machine used for this guide is running Red Hat Entperise Linux

Conventional Naming

This article assumes you know the difference between primary, extended and logical partitions. In the following example, I added a SCSI hard drive with one primary partition. With that being said, I’ll continue explaining the naming scheme. Linux gives each drive a 3 letter name followed by a partition number. If you are using IDE drives, these will all be named hd**. Where hd denotes the drive and the next two variables are aassociated with IDE order (primary master, primary slave, etc) and partition number. So, your primary master drive will always be named hda. If you are using SCSI drives, everything remains the same except instead of using hd, drives are named sd**. Your SCSI primary master drive will always be named sda. All of these devices reside under the /dev portion of your Linux file system. For instance, as root, you can issue the following command to view the naming combinations possible for your system. Remember, in this example, I am using SCSI hardware. If you are using IDE, simply use hd is place of sd here.
[root@roswell root]# ls /dev/sda*
/dev/sda     /dev/sdab10  /dev/sdad12  /dev/sdaf14  /dev/sdah2   /dev/sdaj4   /dev/sdal6
/dev/sda1    /dev/sdab11  /dev/sdad13  /dev/sdaf15  /dev/sdah3   /dev/sdaj5   /dev/sdal7
/dev/sda10   /dev/sdab12  /dev/sdad14  /dev/sdaf2   /dev/sdah4   /dev/sdaj6   /dev/sdal8
/dev/sda11   /dev/sdab13  /dev/sdad15  /dev/sdaf3   /dev/sdah5   /dev/sdaj7   /dev/sdal9
/dev/sda12   /dev/sdab14  /dev/sdad2   /dev/sdaf4   /dev/sdah6   /dev/sdaj8   /dev/sdam
/dev/sda13   /dev/sdab15  /dev/sdad3   /dev/sdaf5   /dev/sdah7   /dev/sdaj9   /dev/sdam1
/dev/sda14   /dev/sdab2   /dev/sdad4   /dev/sdaf6   /dev/sdah8   /dev/sdak    /dev/sdam10
----
Some results omitted**
----
[root@roswell root]#
Note that I omitted a large portion of the results because they were huge! Remember that this list is not dependent on the current number of hard drives in the system, but the maximum naming possibilities for any number of drives and partitions. Do not be surprised if your results are rather lengthy as well.

Creating, Mounting, and Configuration New Partitions

Before adding an extra drive, this machine had 2 physical drives. Both of them were named accordingly (sda and sdb) before the new drive was added. The second drive containing the swap partitions was automatically renamed when the new drive was added. Notice the command and output below:
[root@roswell root]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             8.3G  2.4G  5.5G  30% /
/dev/sda2              99M   26M   69M  27% /boot
/dev/sdc1              16G   13G  2.3G  85% /export  <-- old sdb renamed to sdc by the Linux
none                  250M     0  250M   0% /dev/shm
[root@roswell root]#
This command simply lists all currently mounted drives, their names, and space usage. Notice that sdb is not presently mounted. However, we know that it exists otherwise, there would not be an sdc present. I could not add my new drive as sdc because my SCSI hotswap drive cage reserves the first two slots for 1.5″ drives. So I was forced to make the new drive sdb because it is a 1.5″ drive.

Setting Partitions

You should be fairly familiar with fdisk. The commands are somewhat different than it’s DOS equivalent. See the following commands and output:
[root@roswell root]# fdisk /dev/sdb
Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)
Command (m for help):
If there is a problem, and there is no drive associated with /dev/sdb, you will get an error message. Remember, that nothing will actually be executed until you issue a w command. It’s always a good idea to read through the variables of your commands. Doing so will ensure that you aren’t forgetting anything. Let’s get started!
Command (m for help): p
Disk /dev/sdb: 50.0 GB, 50019202560 bytes
255 heads, 63 sectors/track, 6081 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot    Start       End    Blocks   Id  System

Command (m for help):
If you issue a p command, you will see any partitions that currently exist on the drive. You can see by the output above there are no existing partitions. This drive is un-partitionedd and unformatted. To create a new partition, is the n command.
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-6081, default 1): 1
Last cylinder or +size or +sizeM or +sizeK (1-6081, default 6081): 6081
Command (m for help):
In the output above notice that interval I selected for the cylinders. Using the entire range allows you create one partition across the entire drive. So, in order to create a primary partition on /dev/sdb/ we issued the following commands:
  • n (creates a new partition)
  • p (creates a primary partition)
  • 1 (the number 1 denotes the partition will be /dev/sdb1)
We can check the partition specifications we just entered by using the p command again.
 
Command (m for help): p
Disk /dev/sdb: 50.0 GB, 50019202560 bytes
255 heads, 63 sectors/track, 6081 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/sdb1             1      6081  48845601   83  Linux
Command (m for help):
Notice the new partition (highlighted in red). However, we must issue a w command to finalize it. If you messed anything up, you can use the d command and specify which partition you want to delete.
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@roswell root]#

Formatting

Now that the partition has been created, you need to format the drive. You can format it with almost any file system you wish. However, the most common Linux formats are ext2 and ext3. Ext3 is simply a candy coated version of ext2 that adds a logging feature. You must specify which partition to format by calling the device and partition number like this:
 
[root@roswell root]# mkfs -t ext3 /dev/sdb1
mke2fs 1.32 (09-Nov-2002)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
6111232 inodes, 12211400 blocks
610570 blocks (5.00%) reserved for the super user
First data block=0
373 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000, 7962624, 11239424

Writing inode tables: done                            
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@roswell root]#
What did we do there? Using the mkfs (make file system) command, we specified the type (using the -t) ext3 using the device and partition name (/dev/sdb1). You have successfull partitioned and formatted your new drive. Wait, you’re not done yet. You will want to mount this partition to make it usable. You will also want this partition to mount automatically when you reboot the machine.

Mounting

In order to automatically mount a partition, you must edit the /etc/fstab file. The fstab file tells Linux where to mount all partitions located within the system. The output below shows the current fstab file before including the newly added drive:
[root@roswell root]# vi /etc/fstab
LABEL=/                 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
none                    /dev/pts                devpts  gid=5,mode=620  0 0
LABEL=/export           /export                 ext3    defaults        1 2
none                    /proc                   proc    defaults        0 0
none                    /dev/shm                tmpfs   defaults        0 0
/dev/sdb2               swap                    swap    defaults        0 0
/dev/cdrom              /mnt/cdrom              udf,iso9660 noauto,owner,kudzu,ro 0 0
/dev/fd0                /mnt/floppy             auto    noauto,owner,kudzu 0 0
You may notice I viewed this file using vi. Vi is a simple text editor that may or may not be loaded on your Linux system. It is somewhat similar to emacs. In any case, both programs can perform the same task. We will mount the new partition as /media. Remember to create a directory named media, otherwise fstab won’t be able to mount the partition. It is shown high-lighted red in the output below:
LABEL=/                 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
none                    /dev/pts                devpts  gid=5,mode=620  0 0
LABEL=/export           /export                 ext3    defaults        1 2
none                    /proc                   proc    defaults        0 0
none                    /dev/shm                tmpfs   defaults        0 0
/dev/sdb1               /media                  ext3    defaults        1 2
/dev/sdb2               swap                    swap    defaults        0 0
/dev/cdrom              /mnt/cdrom              udf,iso9660 noauto,owner,kudzu,ro 0 0
/dev/fd0                /mnt/floppy             auto    noauto,owner,kudzu 0 0
Next, issue a simple mount command providing the partition name:
[root@roswell export]# mount /dev/sdb1
[root@roswell export]#
You’re all done! You will be able to access the /media folder immediately and after the machine reboots as fstab will automatically re-mount it for you. If you want to verify the partition is successfully present and mounted, use the following commands:
[root@roswell media]# mount
/dev/sda1 on / type ext3 (rw)
none on /proc type proc (rw)
none on /dev/pts type devpts (rw,gid=5,mode=620)
usbdevfs on /proc/bus/usb type usbdevfs (rw)
/dev/sda2 on /boot type ext3 (rw)
/dev/sdc1 on /export type ext3 (rw)
none on /dev/shm type tmpfs (rw)
/dev/sdb1 on /media type ext3 (rw)
[root@roswell media]#
The red line shows our new drive freshly mounted. You can check the space usage if you issue the following command.
[root@roswell media]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             8.3G  2.4G  5.5G  30% /
/dev/sda2              99M   26M   69M  27% /boot
/dev/sdc1              16G   13G  2.3G  85% /export
none                  250M     0  250M   0% /dev/shm
/dev/sdb1              46G   33M   44G   1% /media
[root@roswell media]# 

By http://www.skullbox.net/erikrodriguez.php

Posted in UNIX-LINUX | Tagged: | Leave a Comment »

Sử dụng bộ soạn thảo vi trong UNIX và Linux

Posted by ZyK on 07/28/2011

Sử dụng bộ soạn thảo vi trong UNIX và Linux

Phần I: Giới thiệu vi:

Có rất nhiều trình soạn thảo trong UNIX cũng như Linux. Nhưng tình soạn thảo vi là trình soạn thảo được nhiều chuyên gia UNIX và Linux sử dụng. Có lẽ một phần là nó chiếm ít tài nguyên, nhưng cũng có thể là nó tồn tại trong UNIX và Linux từ ngày bắt đầu và không có một hệ UNIX hay Linux nào mà không chứa nó như một trình soạn thảo mặc định.

Ngồi vào máy bạn tạo, bạn tạo ra dữ liệu, thư điện tử, danh sách, bản ghi nhớ, ghi chú, báo cáo…vv. Bạn sẽ dùng một bộ soạn thảo(còn gọi là bộ chỉnh sửa, hoặc hiệu chỉnh) văn bản nào đó để làm công việc vừa kể. Linux có sẵn nhiều chương trình xử lý hoặc hiệu chỉnh văn bản để giúp bạn như: nano, cat, touch… Tuy nhiên để đưa các câu lệnh và trình shell vào một tập tin, bạn cần có một bộ soạn thảo (editor) có khả năng lưu trữ công việc của mình vào một tập tin văn bản dưới dạng mã ASCII. Linux giới thiệu bộ soạn thảo văn bản mang tên vi , mà bạn có thể dùng để hiệu chỉnh hầu như tất cả mọi thứ. vi rất hữu ích cho quản trị hệ thống vì chương trình này có sẵn trên mọi nền UNIX. Do đó khi đã quen tay với vi rồi, bạn tha hồ thao tác mọi hệ thống chạy UNIX. Ngoài ra vi cũng có lợi vì chiếm rất ít tài nguyên khi thi hành lệnh. Trong khi một số chương trình khác không thể chạy được vì xung đột phần cứng hoặc là vì hệ thống, vi vẫn hoạt động bình thường.

Hai bộ vi và ex đi kèm với bản phát hành Red Hat thực ra là danh xưng khác nhau của bộ soạn thảo vim (VI iMproved). Hai tên vi và ex gắn liền với vim, do đó khi chạy vi , thực ra bạn đang chạy vim. Mời bạn xem tập tin /usr/share/vim/vim61/doc/vi_diff.txt hay /usr/share/doc/vim-common-6.1/doc/vi_diff.txt để biết tóm tắt những điểm khác nhau giữa vi và vim.

Hình 1.1 Soạn thảo với vi

Linux có những bộ soạn thảo văn bản khác: một chương trình dạng đồ họa để dùng với XFree86 và hai bộ chuẩn không đồ họa mang tên ed và ex. Cả hai đều mang tính line-oriented, nghĩa là bạn chỉ có thể làm việc từng hàng một. Một chương trình khác mang tên emacs cũng có mặt trong các bản phát hành Linux. vi và emacs là những bộ soạn thảo toàn màn hình. Thông tin xuất hiện theo từng màn hình một để bạn có thể chỉnh sửa, thêm theo ngữ cảnh.

Trong bài này không bàn nhiều về ed hay ex, bởi vì bạn sẽ thấy vi rất dễ dùng và có sẵn trên mọi máy chạy UNIX, bao gồm cả Linux.

Muốn hiểu vi, bạn cần tìm hiểu vài nét về vi trong thế giới UNIX. Cho dù nhiều hệ điều hành ngày nay đã có những bộ soạn thảo mạnh mẽ và thân thiện với người sử dụng ví dụ như: Open Offices…, nhưng bạn vẫn nên tìm hiểu về vi bởi vì bất kỳ bản UNIX nào cũng có sẵn bộ vi. Đôi lúc vi là bộ soạn thảo duy nhất sẵn có vào lúc cần thiết, vì vậy bạn cần biết vài thao tác căn bản. Hơn nữa giờ đây với những phiên bản mới (v.6.x) vi đã trở nên thân thiện hơn và đã có nhiều phiên bản chạy trên Windows.

Trước đây UNIX được triển khai trong hoàn cảnh terminal của người sử dụng là máy teletype hoặc một dạng máy in kết quả ra giấy chạy chậm rì. Vào thời đó màn hình chưa được dùng nhiều. Bộ soạn thảo văn bản dùng cho môi trường như thế thường là line-oriented, mà người sử dụng chỉ thấy và chỉ làm việc trên một dòng lệnh duy nhất mà thôi.

Hiện nay các hệ UNIX còn dùng hai bộ soạn thảo line-oriented: ed và ex.

Khi UNIX bắt đầu ra đời, sinh viên đại học được dùng UNIX không mất tiền và cùng góp sức triển khai hệ điều hành này. Đại học California và Berkeley có nhiều đóng góp, trong đó có bộ soạn thảo toàn màn hình, thay thế việc xử lý từng dòng lệnh một. Bộ soạn thảo toàn màn hình này được gọi là vi, viết tắt của chữ “Visual”.

Đã đến lúc chuyển sang loại hình công việc screen-oriented, nhìn cả màn hình thay vì từng dòng một. Người sử dụng làm việc với các terminal nhìn trực tiếp vào màn hình, thay vì làm việc với các thiết bị in ra giấy.

Trong phần này chỉ giới thiệu đôi chút về vi, muốn biết vi hoạt động và sử dụng như thế nào mời các bạn đón đọc tiếp phần II – vi là gì?

II – Vi là gì ?:

Trong phần trước chúng ta đã được giới thiệu về VI và biết được sự ra đời cũng như tầm quan trọng và sự hữu ích của VI. Phần này các bạn sẽ hiểu được sự hoạt động của VI.

Cũng như hàng triệu người khác đang sử dụng vi, bạn sẽ thấy ứng dụng này khởi động nhanh và có thể dùng cho việc đơn giản cũng như phức tạp. Bạn dùng vi để nhập văn bản, chỉnh sửa hoặc xóa bỏ văn bản. Ngoài ra bạn còn tìm kiếm và thay thế, cắt, chép, và dán từng khối văn bản.

Vi cũng giúp bạn cắt xén tỉa gọt văn bản cho đúng ý mình. Bạn tùy nghi di chuyển con trỏ đến bất kỳ chỗ nào trên màn hình cũng như trên phạm vi văn bản đang được xử lý. Bộ soạn thảo vi không phải là phần mềm xử lý văn bản, cũng không là ứng dụng chế bản văn phòng, do đó sẽ không có trình đơn (menu) và cũng không có các tiện ích trợ giúp.

Các ứng dụng xử lý văn bản thường có hai định dạng, một loại trên màn hình và một dùng khi in ra, chẳng hạn như trình bày văn bản dạng in đậm, in nghiêng, hoặc gạch dưới. Vi lại không như thế. Các lệnh khác của Linux có thể thực thi vài điều vừa kể, chẳng hạn như lệnh lp thực hành in và lệnh nroff có khả năng định dạng văn bản. Một vài chương trình xử lý văn bản như TeX và LaTeX, có thể xử lý các câu lệnh nhúng trong văn bản, chẳng hạn như in đậm hoặc gạch dưới.

Bộ soạn thảo vi chạy ở hai chế độ khác nhau:

- Ở chế độ câu lệnh, những gì bạn gõ vào sẽ được hiểu như là câu lệnh ra lệnh cho vi. Lệnh sẽ bảo vi lưu tập tin, thoát khỏi vi, chuyển con trỏ đến các vị trí khác nhau trong tập tin, chỉnh sửa, sắp xếp, xóa bỏ, thay thế và tìm kiếm đoạn văn bản.

– Ở chế độ nhập liệu hoặc còn gọi là nhập văn bản (chế độ INSERT), những gì bạn gõ vào được máy hiểu là nội dung của tập tin mà bạn đang chỉnh sửa. Theo chế độ này, vi hành động như là chiếc máy đánh chữ đơn thuần.

Trong một phiên chỉnh sửa văn bản, bạn có thể chuyển từ chế độ này sang chế độ khác. Bạn phải nhớ mình đang ở chế độ nào và biết cách chuyển đổi. Chương này sẽ giới thiệu tùy chọn showmode giúp bạn biết xem vi đang thuộc chế độ nào. Chỉ cần tập luyện ít lâu là bạn sẽ thấy vi rất tiện lợi để xử lý các tập tin ASCII Linux, đặc biệt là các tập tin cấu hình và shell script.

Để biết được trình soạn thảo vi làm việc như nào và bạn có thể gỡ lỗi (debug error) xảy ra trong quá trình dùng vi thì mời các bạn đón đọc phần tiếp theo: Tìm hiểu tiến trình soạn thảo Vi – Phần III.

III – Tìm hiểu tiến trình soạn thảo và cách sử dụng Vi:

Bạn soạn thảo bằng cách tạo ra văn bản mới hoặc chỉnh sửa văn bản đã có sẵn. Tạo ra văn bản mới tức là viết chữ vào một tập tin được đặt tên theo dạng Linux. Khi chỉnh sửa, bạn dùng tên tập tin có sẵn để gọi bản sao của tập tin ấy ra trình diện tại phiên soạn thảo. Trong cả hai trường hợp, khi sử dụng bộ soạn thảo tức là bạn đã lưu giữ văn bản tại bộ nhớ của máy ở một vùng được gọi là vùng đệm.

Vùng đệm sẽ không thay đổi gì ở nội dung của tập tin cho đến khi bạn ra lệnh lưu nội dung vùng đệm. Chỉ khi nào bạn ra lệnh này xong, máy sẽ ghi những điều chỉnh sửa vào đĩa cứng. Lúc ấy những gì bạn vừa thay đổi mới có hiệu lực thường trực. Do đó nếu sau khi thao tác một lúc, bạn quyết định là không nên thay đổi gì ở nội dung cũ thì cứ để y nguyên như thế. Trong một phiên làm việc, bạn muốn lưu những thay đổi ấy bao nhiêu lần cũng được, và bạn nên ra lệnh lưu một cách đều đặn, phòng khi mất nguồn đột xuất hoặc treo máy. Khi ra lệnh lưu, bạn không phải thoát khỏi bộ soạn thảo. Chương này sẽ chỉ bạn nhiều cách thoát ra khỏi bộ soạn thảo.

Bộ soạn thảo vi được coi là có tính tương tác bởi vì chương trình sẽ giao lưu qua lại với bạn trong phiên làm việc. Vi liên lạc với bạn bằng cách hiển thị tình trạng phiên làm viêc, hoặc giả hiển thị những thông báo lỗi, hoặc đôi lúc trên màn hình không xuất hiện điều gì cả (đúng theo kiểu của Linux). Dòng cuối cùng trên màn hình, gọi là dòng trạng thái, mang những lời nhắn của Linux.

Bạn sử dụng bộ soạn thảo để chỉnh sửa, sắp xếp lại, xóa bỏ, tìm kiếm và thay thế đoạn văn bản. Các thao tác chỉnh sửa như thế được tiến hành ở chế độ soạn thảo. Trong nhiều trường hợp, lệnh chỉ là một ký tự tương ứng với chữ đầu tiên của tên một hành động. Ví dụ chữ I tương ứng với hành động Insert, và r được dùng để replace( thay thế) một ký tự.

Hầu hết các câu lệnh đều diễn ra trên một dòng hoặc nhiều dòng ký tự. Dòng được đánh số từ 1(dòng đầu tiên) cho đến dòng cuối cùng của vùng đệm. Khi bạn thêm hoặc bớt dòng, số hiệu của dòng sẽ tự động chỉnh lý. Số hiệu của dòng tức là địa chỉ của dòng đó trong vùng đệm. Vùng địa chỉ là hai địa chỉ hoặc hai số hiệu của dòng được cách bởi dấu phẩy. Nếu muốn xác định vùng địa chỉ từ dòng thứ ba đến dòng thứ tám vủa vùng đệm, bạn viết 3, 8.

Vị trí con trỏ luôn chỉ bạn biết vị trí hiện hàn của vùng đệm soạn thảo. Một vài lệnh mà bạn gõ ở chế độ ra lệnh sẽ tác động đến ký tự ngay chỗ con trỏ đang nhấp nháy. Nếu bạn không di chuyển con trỏ, những thay đổi sẽ diễn ra tại vị trí ấy. Bộ soạn thảo vi có nhiều lệnh để di chuyển con trỏ tới lui trong vùng đệm soạn thảo. Vi là bộ soạn thảo toàn màn hình. Bạn ra lệnh cho Vi để di chuyển con trỏ đến nhiều nơi trong tập tin, và bạn trực tiếp nhìn thấy những thay đổi diễn ra khi bạn thao tác. Vì thế Vi phải có khả năng di chuyển và chỉnh sửa văn bản trên terminal của chính bạn cũng như ở các loại terminal khác. Vi biết bạn đang dùng terminal nào, và khả năng màn hình của terminal ấy ra sao bằng cách xem xét biến shell mang tên TERM. Linux dùng biến TERM để xác định xem terminal làm được gì, chẳng hạn như gạch dưới, đảo màn hình, xóa màn hình, gán phím chức năng, và khả năng về màu sắc của terminal.

Bạn chỉ cần gõ Vi tại dấu nhắc shell tại dòng lệnh để kích hoạt Vi. Muốn tạo ra hoặc chỉnh sửa một tập tin nào đó, bạn gõ lệnh Vi chung với tên tập tin. Chẳng hạn muốn tạo tập tin abc với Vi, bạn gõ: Vi abc.

Khi Vi được kích hoạt, màn hình terminal sẽ tự động xóa trống, đồng thời một dấu sóng (~) xuất hiện ở phía bên trái mỗi đầu dòng, trừ dòng đầu tiên hay những dòng đã soạn thảo. Dấu sóng báo hiệu dòng trống của vùng đệm. Con trỏ nằm phía ngoài cùng bên trái của dòng đầu tiên. Bạn sẽ trông thấy từ 20 đến 22 dấu sóng ở phía trái màn hình. Nếu màn hình không đúng như thế, bạn nên kiểm tra lại vị trí của TERM. Còn nếu mọi sự diễn ra như mô tả, bạn đã khởi động được Vi, và Vi đang ở chế độ chờ lệnh.Để có thể thao tác hoặc sử dụng Vi một cách hiệu quả nhất, mời các bạn đón đọc phần tiếp theo: IV – Tìm hiểu hai chế độ của Vi và tạo ra tập tin Vi đầu tiên.

IV – Tìm hiểu hai chế độ của Vi và tạo ra tập tin Vi đầu tiên

Vi ( vim ) – the powerful & simple editor for linux

Linux là một hệ điều hành được điều khiển đa phần qua môi trường dòng lệnh ( console ), thêm vào đó, các file cấu hình dịch vụ trên Linux thường được chỉnh sửa bởi trình editor là vi ( hay vim, bản cải thiện của vi ). Nếu bạn là người thường xuyên quản trị server linux qua console, thì vi là trình tiện ích hay sử dụng nhất. Do vậy, học cách sử dụng vi là một yêu cầu tối thiểu và cần thiết cho một người sử dụng linux.

1. Cơ bản

- Sử dụng vi kèm theo tên file(s) muốn edit: vi one.txt two.txt etc.txt

– Có 2 mode: command mode và insert mode. Khi bắt đầu sử dụng lệnh vi, vi mặc định ở command mode. Hoặc ấn Esc để chuyển sang command mode khi người dùng đang ở insert mode.

2. Các lệnh edit cơ bản

- Ấn phím lệnh i hoặc a từ chế độ command mode để chuyển sang insert mode. i để thêm ký tự trước con trỏ, a để thêm ký tự sau con trỏ.

– Sử dụng lệnh h j k l hoặc các phím mũi tên tương ứng để di chuyển con trỏ sang trái, xuống, lên, sang phải.

– Sử dụng x xóa 1 ký tự, dw xóa 1 từ, dd xóa cả 1 dòng.

– Sử dụng số N đi trước phím lệnh để lặp lại N lần tác dụng của lệnh. Ví dụ, 3dw sẽ xóa 3 từ tính từ vị trí con trỏ.

– Sử dụng u ( = undo )để khôi phục lại những thay đổi trước đó.

– Sử dụng ZZ hay hay :wq lưu lại tất cả thay đổi và thoát.

– Sử dụng :q! thoát ra không lưu lại bất kỳ thay đổi nào.

3. Cắt và dán

- yy sao chép dòng hiện tại vào buffer, Nyy sao chép N dòng.

– p ( P ) dán nội dung từ buffer vào dưới ( trên ) dòng hiện tại

4. Nhảy đến hàng hay cột

- Gõ một số N trước ký tự G để đi đến dòng thứ N, vd 23G sẽ nhảy đến dòng 23.

– Gõ một số N trước ký tự | (pipe) để nhảy đến cột thứ N.

5.

Sử dụng . để lặp lại action gần nhất. Ví dụ người dùng gõ i để insert dòng chữ “hello world”, sau đó chuyển sang chế độ command mode bằng phím Esc, nhảy xuống dòng và gõ . , dòng chữ “hello world” sẽ hiện ra.

6. Tìm kiếm

- Sử dụng / (?) đi theo sau là từ muốn tìm để tìm kiếm từ trong phần văn bản sau ( trước ) con trỏ. ví dụ /foobar hay ?foobar.

– Sau khi kết quả tìm kiếm đầu tiên hiện ra, sử dụng n để tìm kiếm tiếp trong phần văn bản còn lại sau con trỏ, N để tìm kiếm ngược trở lại đầu văn bản trước con trỏ.

7. Các lệnh colon ( đi sau dấu : )

- :%s/foo/bar/g tìm sự xuất hiện của “foo” trong toàn bộ file và thay thế bằng “bar”, /foo/bar/g chỉ thay thế ở dòng hiện tại.

– et nu hiển thị số dòng trước mỗi dòng, et nonu để bỏ hiển thị số dòng.

– :1,8d xóa từ dòng 1 cho đến dòng 8 trong file.

– Sử dụng ma để đánh dấu dòng hiện tại là a ( có thể là bất cứ ký tự nào từ a-z ). Sau đó dùng ‘a để nhảy đến dòng đã được dánh dấu là a từ bất cứ đâu. Có thể sử dụng với colon, :’a,’b d xóa tất cả các dòng bắt đầu từ dòng được đánh dấu là a cho đến dòng được đánh dấu là b, hoặc ngược lại.

– :w newfile.txt để save nội dung của file hiện tại vào một file mới là newfile.txt ( tựa “save as” bên Win Word ).

– :8,16 co 32 để copy dòng 8 đến 16 đến điểm sau dòng 32.

– :3,16 m 32 để chuyển rời dòng 8 đến 16 đến điểm sau dòng 32.

– Nếu dùng vi để mở nhiều file ( vi file1 file2 file3 ), có thể sử dụng :n để nhảy đến file tiếp theo và :rew để nhảy quay ngược lại đến file đầu tiên, :args để hiện thị tất cả các file đang được mở.

8. Vi for Smarties

- Sử dụng G để nhảy đến dòng cuối cùng của file.

– Khi xóa nhiều dòng, di chuyển con chuột đến dòng đầu tiên, gõ ma để đánh dấu, sau di đến dòng cuối cùng và gõ d’a để xóa những dòng đó.

– $ để nhảy xuống cuối dòng, :$ để nhảy đến dòng cuối của file.

- 0 để nhảy đến đầu dòng, :0 để nhảy tới dòng đầu tiên của file.

– d$ xóa từ vị trí con trỏ hiện tại đến cuối dòng.

– :10,$ d xóa từ dòng 10 cho đến dòng cuối cùng của file, hoặc ngược lại.

– :10,20 m 0 chuyển rời dòng 10 đến 20 lên trên dòng đầu tiên của file.

9. Shell

- Sử dụng :!command để thi hành lệnh command trong môi trường vi.

Trên đây là giới thiệu cách sử dụng vi một cách cơ bản và đủ dùng cho mọi đối tượng người sử dụng linux. Người dùng muốn tham khảo thêm có thể lên website của vim tại http://vim.wikia.com/wiki/Best_Vim_Tips.

Trích từ Internet

Posted in UNIX-LINUX | Tagged: , | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.