Tổng quan về lệnh trên LinuxCác lệnh thao tác với ổ đĩa Các lệnh thao tác với thư mục Các lệnh thao tác với tập tin Các lệnh quản lý tài khoản người dùng trên hệ thống tập tin Các lệnh t
Trang 1Updated 25.08.2008 Computer Sciences Div @ 2008 1
2nd Chapter
THE BASIC COMMANDS ON
LINUX
Trang 2Tổng quan về lệnh trên Linux
Các lệnh thao tác với ổ đĩa
Các lệnh thao tác với thư mục
Các lệnh thao tác với tập tin
Các lệnh quản lý tài khoản người dùng trên hệ thống tập tin
Các lệnh thao tác với hệ thống
Trang 3Overview of commands on Linux
Command Line Interface in Linux called CLI (Command Line Interface).
Trang 4Overview of commands on Linux
Some errors often appear when you type commands
on Linux:
Command does not exist or can not be found:
Trang 5Overview of commands on Linux
Some errors often appear when you type commands
on Linux:
Type the command syntax incorrectly:
Trang 6List and partition drives
Check capacity of drives
Attached partitions
Cancel attach partitions
Trang 7List and partition drives
Command name: fdisk
Function: Liệt kê các phân vùng ổ đĩa trên Linux
Syntax : fdisk [-l]
Example:
Trang 8Check capacity of drives
Command name: df (disk free)
Function: Check capacity of drives.
Syntax: df [-a]
Example:
Trang 9Command name: mount
Function: Thực hiện gắn kết phân vùng vào FileSystem.
Syntax: mount -t type dev dir
Type: Loại phân vùng mà ta muốn gắn kết vào hệ thống
Dev: Tên phân vùng hiện có trên hệ thống Dùng lệnh fdisk để xem
hệ thống máy tính đang dùng có những phân vùng nào
Dir: Thư mục được chỉ định để gắn kết vào
Example:
Trang 10Cancel attached partitions
Command name: umount (unmount)
Function: Hủy bỏ gắn kết phân vùng.
Syntax: Umount dir
Dir: Thư mục được chỉ định để gắn kết vào.
Example:
Trang 11Command operation with folder
Change the current folder
View/ check the current working folder Create new folder
Display the structure of folder tree
List folder contents
Delete folder
Rename folder
Trang 12Function: Chuyển đổi thư mục hiện hành.
Syntax: cd <Đường dẫn thư mục mới>
Example:
Trang 13Change the current folder
Note: If cd command does not contain <folder
path> , the program will move to a separate folder from any folder.
Trang 14Change the current folder
Note: String " " and "." represent for Parent folder and current one.
Trang 16Create new folder
Command name: mkdir
Function: Tạo mới thư mục.
Syntax: mkdir <Tên thư mục mới cần tạo>
Example:
Tạo thư mục viethan trong thư mục home.
Chuyển đến thư mục hiện hành viethan.
Tạo trong thư mục viethan các thư mục con: khmt, laptrinh và
hethongtt.
Trang 17Display the structure of folder tree
Command name: tree
Funstion: Hiển thị cấu trúc cây thư mục.
Syntax: tree <tham số>
Tham số -d: Chỉ hiển thị thư mục.
Tham số -f: Hiển thị đầy đủ đường dẫn các tập tin.
Trang 18Funtion: Hiển thị nội dung trong thư mục.
Syntax: ls [- Tùy chọn] [Thư mục]
Trang 19Command name: rmdir
Function: Delete folder.
Syntax: rmdir <Tên thư mục>
Example:
Trang 20Delete only empty folders
Not delete the current folders
Many empty folders can be deleted at the same time by showing the paths to those folders are separated by spaces
Trang 21Function: Đổi tên thư mục.
Syntax: mv <Tên thư mục cũ> <Tên thư mục mới>
Example:
Trang 22Function: Sao chép thư mục.
Syntax: cp <Thư mục nguồn> <Thư mục đích>
Example:
Trang 23Xuất nội dung thông báo
Xem loại tập tin
Đếm số dòng, số từ và ký tự
Chia một tập tin lớn thành nhiều tập tin nhỏ
Trang 24Command name: vi hoặc gedit (graphic edit)
Function: Tạo mới tập tin.
Syntax: vi <Tên tập tin> hoặc gedit <Tên tập tin>
Trang 25Create a file with vi command
Vi là trình soạn thảo cơ bản của các hệ thống Linux
Cú pháp để soạn thảo một tập tin như sau:
#vi <Tên tập tin>
Ví dụ: vi test
Khi sử dụng vi, ta có thể chọn một trong hai chế độ thao
tác: chế độ câu lệnh (command mode) và chế độ soạn
thảo (editor mode)
Nếu ta đang ở chế độ soạn thảo, nhấn phím ESC + lệnh
sẽ chuyển sang chế độ lệnh Ngược lại, nếu ta đang ở chế
độ lệnh thì nhấn phím lệnh để chuyển sang chế độ soạn thảo
Trang 27Create a file with gedit command
Sử dụng lệnh gedit để tạo tập tin dạng text trong chế độ
đồ họa
Sau khi soạn thảo xong nội dung tập tin, vào menu
File/Save để lưu nội dung tập tin trước khi vào menu File/Close để đóng tập tin.
Trang 28Command name: cp (copy)
Function: Sao chép tập tin từ thư mục này đến thư mục
khác.
Syntax: cp [- tùy chọn] <Thư mục nguồn>/<Tập tin
nguồn> <Thư mục đích> Tùy chọn:
-i: Hỏi lại người dùng nếu tập tin đích đã tồn tại.
-r: Sao chép cả cây thư mục.
-f: Sao chép đè.
-v: Hiển thị quá trình sao chép tập tin
Trang 30Command name: mv (move)
Meaning: Di chuyển tập tin từ nơi này đến nơi khác
Syntax: mv [-tùy chọn] <thư mục nguồn>/<tên tập tin> <thư mục
đích> Trong đó tùy chọn:
-i: Reask the user if the target file exists or not.
-u: Moving only source file that is newer old file or false old files.
-f: Moving overwrite.
-v: Display process to remove file.
Example:
Trang 31Creating links to files
Command name: ln (link)
Meaning: Tạo liên kết giữa các tập tin
Syntax: ln <tên tập tin nguồn> <đường dẫn>/<tên
tập tin đích>
Example:
Trang 32Searching/ Finding files
Command name: find (find)
Meaning: Tìm kiếm tập tin trong thư mục
Syntax: find <tên thư mục nguồn> -name <tên tập
tin cần tìm>
Examlpe:
Trang 33Command name: rm (remove)
Meaning: Xóa tập tin
Syntax: rm [- Tùy chọn] <tên tập tin cần xóa>
Trong đó, [- Tùy chọn] là các giá trị sau:
-i: Nhắc nhở xác nhận trước khi xóa tập tin.
-r: Xóa tất cả các tập tin trong thư mục được chọn xóa -v: Hiển thị quá trình xóa tập tin
Example:
Trang 34Display file contents
Command name: Cat, more, less, head, tail
Meaning: Xem nội dung bên trong tập tin.
Syntax:
cat <tên tập tin>: Hiển thị hết nội dung tập tin.
more <tên tập tin> hoặc less <tên tập tin>: Hiển thị nội dung tập tin trên từng trang màn hình.
head [-n] <tên tập tin>: Hiển thị n dòng đầu của tập tin tail [-n] <tên tập tin>: Hiển thị n dòng cuối của tập tin
Trang 35Display file contents
cat :<file name>: Displays all contents of file
Trang 36Display file contents
more <file name> or less < file name >: Displays contents of file on each page.
Trang 37Display file contents
head [-n] <file name>: Display n first lines in the file.
Trang 38Display file contents
tail [-n] <file name>: Display n last lines of the
file
Trang 39Command name : cat.
Meaning: Dùng để nối nội dung nhiều tập tin vào một tập
tin.
Syntax: cat <tên tập tin 1> <tên tập tin 2>…<tên tập tin n>
> <tên tập tin k>
Example:
Trang 40Compress and decompress files
Command name: gzip và gunzip.
Meaning: Dùng để nén (gzip) hoặc gỡ nén (gunzip) cho tập
tin.
Syntax: gzip <tên tập tin> hoặc gunzip <tên tập tin>
Example:
Trang 41Instructions use the command
View instructions to use command
Command name: man.
Meaning: Xem hướng dẫn sử dụng lệnh.
Syntax: man <command> với <command> là tên
của một lệnh cần xem hướng dẫn.
Example:
Trang 42Output report contents
Command name: echo.
Meaning: Xuất nội dung thông báo.
Syntax: echo <arg1><arg2> <argN> với
<arg1><arg2> <argN> là các đối số của dòng lệnh.
Example:
Trang 43Output report contents
Notes: In addition showing report on screen, echo command is also used to display folder contents with the command syntax: echo *
Trang 44View file types
Command name: file.
Meaning: Xem loại tập tin.
Syntax: file <Tên tập tin>
Example:
Trang 45Counting lines, words and characters of file
Command name: wc (word count).
Meaning: Đếm số dòng, số từ và số ký tự có trong
tập tin.
Syntax: wc <Tên tập tin>
Example:
Trang 46Split a large file into smaller files
Command name: split.
Meaning: Dùng để chia một tập tin có kích cỡ lớn thành
nhiều tập tin có kích thước nhỏ
Syntax: split -b <dung lượng> < tên tập tin nguồn> <tên
tập tin đích>
Example:
Trang 48Account of system includes two types:
Tài khoản người dùng (User)
Tài khoản nhóm người dùng (Group)
Tài khoản người dùng trên
Windows
Tài khoản người dùng trên
Linux
Trang 49Information above is stored
in the file / etc / passwd
Hộp thoại tạo mới user
Trang 50User groups account
groupname: Tên của nhóm.
gid: Số hiệu nhóm (group identify number).
Danh sách các tài khoản thuộc nhóm.
Các thông tin trên lưu trong tập tin /etc/group
Cửa sổ quản trị tài khoản người dùng
Trang 51Rights to access on file
When a file is created, the
following information
established:
uid của người dùng tạo tập tin.
gid của nhóm người dùng tạo
tập tin.
Các quyền truy cập trên tập
tin.
Owner: rwx Group: rwx Other: rwx
Hộp thoại các quyền trên tập tin chotay
Trang 52Only the users owning this file have the right to
change permissions on files.
Performing above command in two ways:
Dùng các ký hiệu tượng trưng
Dùng thông số tuyệt đối
Trang 53{r,w,x}: r (read only), w (write)
và x (excusive)
Ví dụ: #chmod g+x chotay Hộp thoại phân quyền tập tin chotay
Trang 54Using absolute parameters
Cú pháp: chmod <mode> <Tên tập tin> Trong đó:
<mode>: Là một số cơ số 8 dùng để gán và hủy quyền trên tập tin
Ví dụ: [root@pc02 root]#chmod 7 5 5 viethan.txt
Owner ( 7(10) = 111(2)): u+rwx Group ( 5(10) = 101(2)): g+rx, g-w Other ( 5(10) = 101(2)): o+rx, o-w
Trang 55Command changes the user owns the file
Chown command allows changing the owner of the
file Example: chown root chotay.
Chgrp command allows changing owner group on
on file Eg chgrp root chotay.
Trang 57Command name: at.
Meaning: Executing command at a specified time.
Thực thi lệnh tại một thời điểm được chỉ định trước.
Syntax: at <Tham số> [Thời gian] Trong đó:
<Parameter >:
-f file: Executing a file -l: Displaying a list of commands.
-d job [job…]: Delete command
[Thời gian]: Time to execute command.
Trang 58Command name: hostname.
Meaning: Hiển thị tên máy tính hoặc đặt lại tên máy tính
Hệ thống lưu tên máy tính trong /etc/hosts.
Syntax: hostname
Display computer name
Rename computer name
Trang 59Command name: ps (report a snapshot).
Meaning: Xem danh sách các tiến trình đang hoạt
động trên hệ thống.
Syntax: ps
Trang 61Command name: date.
Meaning: Hiển thị ngày giờ hiện hành của hệ thống
máy tính.
Syntax: date
Trang 62Command name: cal.
Meaning: Xem lịch với tháng và năm chỉ định.
Syntax: cal <month><year>
Trang 63Command name: who
Meaning: To view user accounts using the system
Syntax: who
Trang 66To logout bc, using the keyboard: Ctrl + D.
Using man bc command to view the instructions of this command
Trang 67Overview of commands on Linux
Command operation with drives
Command operation with folders
Command operation with files
User accounts management commands on file
system
Commands operation with system
Trang 69Question 1 Which of the following basic syntax
of a command on Linux is right :
a <Command name > [option] [parameter ]
b < option > [Command name ] [parameter]
c < parameter > [Command name ] [option]
d All of a, b and c are wrong
Question 2 Which of the following command used to list the partitions of disk :
a df
b fdisk
c mount
d umount
Trang 72c View file types
d Outputting report contents
Trang 73Câu hỏi lý thuyết
Câu 9 Lệnh hostname dùng để thực hiện nhiệm vụ nào sau đây
a Tạo tập tin
b Xóa thư mục
c Xem danh sách các tiến trình đang hoạt động trên hệ thống
d Hiển thị tên máy tính đang làm việc
Câu 10 Lệnh clear dùng để thực hiện nhiệm vụ nào sau đây
a Xóa tập tin
b Xóa màn hình
c Xem loại tập tin
d Xuất nội dung thông báo
Trang 75Creating a new disk partition to store data with
capacity is 5GB to meet the following requirements:
Đảm bảo an toàn dữ liệu trong trường hợp hợp hệ thống