The Basic Commands On Linux

76 1.1K 0
The Basic Commands On Linux

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

2nd Chapter THE BASIC COMMANDS ON LINUX Updated 25.08.2008 Computer Sciences Div. @ 2008 1 Contents Tổ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 Updated 25.08.20 Computer Sciences Div. 2 Overview of commands on Linux Command Line Interface in Linux called CLI (Command Line Interface). Command syntax: Command names [-option] [argument 1] [argument 2] .... [argument n] Examples: mount -t ntfs /dev/sda1 /mnt/sda1 Với: • • • • Tên lệnh: mount Tuỳ chọn: -t ntfs Đối số 1: /dev/sda1 Đối số 2: /mnt/sda1 Updated 25.08.20 Computer Sciences Div. 3 Overview of commands on Linux Some errors often appear when you type commands on Linux: Command does not exist or can not be found: Updated 25.08.20 Computer Sciences Div. 4 Overview of commands on Linux Some errors often appear when you type commands on Linux: Type the command syntax incorrectly: Updated 25.08.20 Computer Sciences Div. 5 Command operation with drives: : List and partition drives Check capacity of drives Attached partitions Cancel attach partitions Updated 25.08.20 Computer Sciences Div. 6 List and partition drives Command name: fdisk Function: Liệt kê các phân vùng ổ đĩa trên Linux Syntax : fdisk [-l] Example: Updated 25.08.20 Computer Sciences Div. 7 Check capacity of drives Command name: df (disk free) Function: Check capacity of drives. Syntax: df [-a] Example: Updated 25.08.20 Computer Sciences Div. 8 Attached partitions Command 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: Updated 25.08.20 Computer Sciences Div. 9 Cancel 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: Updated 25.08.20 Computer Sciences Div. 10 Command 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 Updated 25.08.20 Computer Sciences Div. 11 Change the current folder Command name: cd Function: Chuyển đổi thư mục hiện hành. Syntax: cd Example: Updated 25.08.20 Computer Sciences Div. 12 Change the current folder Note: If cd command does not contain , the program will move to a separate folder from any folder. Updated 25.08.20 Computer Sciences Div. 13 Change the current folder Note: String ".." and "." represent for Parent folder and current one. Updated 25.08.20 Computer Sciences Div. 14 View/ check the current working folder Command name: pwd Function: Xem thư mục và đường dẫn của thư mục làm việc hiện hành. Syntax: pwd Example: Thư mục hiện hành: khmt Đường dẫn hiện hành: /home/giaovien/khmt Updated 25.08.20 Computer Sciences Div. 15 Create new folder Command name: mkdir Function: Tạo mới thư mục. Syntax: mkdir 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. Updated 25.08.20 Computer Sciences Div. 16 Display 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ố -d: Chỉ hiển thị thư mục. Tham số -f: Hiển thị đầy đủ đường dẫn các tập tin. Updated 25.08.20 Computer Sciences Div. 17 List folder contents Command name: ls Funtion: Hiển thị nội dung trong thư mục. Syntax: ls [- Tùy chọn] [Thư mục] [- Tùy chọn]: -a: Liệt kê tất cả các thư mục và tập tin kể cả các thư mục và tập tin có thuộc tính ẩn. -R: Liệt kê tất cả các thư mục và tập tin trong các thư mục con. -l: Liệt kê thuộc tính các tập tin. [Thư mục]: Là thư mục cần liệt kê nội dung Updated 25.08.20 Computer Sciences Div. 18 Delete folder Command name: rmdir Function: Delete folder. Syntax: rmdir Example: Updated 25.08.20 Computer Sciences Div. 19 Remove folder Notes: Delete 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 Updated 25.08.20 Computer Sciences Div. 20 Rename folder Command name: mv Function: Đổi tên thư mục. Syntax: mv Example: Updated 25.08.20 Computer Sciences Div. 21 Copy folder Command name: cp Function: Sao chép thư mục. Syntax: cp Example: Updated 25.08.20 Computer Sciences Div. 22 Command operation with folders Tạo tập tin Sao chép tập tin Di chuyển tập tin Tạo liên kết với tập tin Tìm kiếm tập tin Xóa tập tin Hiển thị nội dung tập tin Nối các tập tin Nén và giải nén tập tin Xem hướng dẫn sử dụng lệnh Xuấ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ỏ Updated 25.08.20 Computer Sciences Div. 23 Creating files Command name: vi hoặc gedit (graphic edit) Function: Tạo mới tập tin. Syntax: vi hoặc gedit Updated 25.08.20 Computer Sciences Div. 24 Creating files Create 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 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. Updated 25.08.20 Computer Sciences Div. 25 Creating files Create a file with vi command Updated 25.08.20 Computer Sciences Div. 26 Creating file Create 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. Updated 25.08.20 Computer Sciences Div. 27 Copying files Command 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] / . 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. Updated 25.08.20 Computer Sciences Div. 28 Copy files Note: If we want to copy files from a folder to another folder and rename file, we have to specify the file name to change at target folder. Example: copy files “thongbao” from tmdt folder to cntt_ud folder, and rename the file “thongbao” into “baocao”. Updated 25.08.20 Computer Sciences Div. 29 Moving files Command 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] / . 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: Updated 25.08.20 Computer Sciences Div. 30 Creating links to files Command name: ln (link) Meaning: Tạo liên kết giữa các tập tin Syntax: ln / Example: Updated 25.08.20 Computer Sciences Div. 31 Searching/ Finding files Command name: find (find) Meaning: Tìm kiếm tập tin trong thư mục. Syntax: find -name Examlpe: Updated 25.08.20 Computer Sciences Div. 32 Removing files Command name: rm (remove) Meaning: Xóa tập tin Syntax: rm [- Tùy chọn] . 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: Updated 25.08.20 Computer Sciences Div. 33 Display file contents Command name: Cat, more, less, head, tail Meaning: Xem nội dung bên trong tập tin. Syntax: cat : Hiển thị hết nội dung tập tin. more hoặc less : Hiển thị nội dung tập tin trên từng trang màn hình. head [-n] : Hiển thị n dòng đầu của tập tin. tail [-n] : Hiển thị n dòng cuối của tập tin. Updated 25.08.20 Computer Sciences Div. 34 Display file contents cat :: Displays all contents of file Updated 25.08.20 Computer Sciences Div. 35 Display file contents more or less < file name >: Displays contents of file on each page. Updated 25.08.20 Computer Sciences Div. 36 Display file contents head [-n] : Display n first lines in the file. Updated 25.08.20 Computer Sciences Div. 37 Display file contents tail [-n] : Display n last lines of the file. Updated 25.08.20 Computer Sciences Div. 38 Connecting files Command name : cat. Meaning: Dùng để nối nội dung nhiều tập tin vào một tập tin. Syntax: cat … > Example: Updated 25.08.20 Computer Sciences Div. 39 Compress 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 hoặc gunzip Example: Updated 25.08.20 Computer Sciences Div. 40 View instructions to use command Command name: man. Meaning: Xem hướng dẫn sử dụng lệnh. Syntax: man với là tên của một lệnh cần xem hướng dẫn. Example: Updated 25.08.20 Computer Sciences Div. 41 Output report contents Command name: echo. Meaning: Xuất nội dung thông báo. Syntax: echo ... với ... là các đối số của dòng lệnh. Example: Updated 25.08.20 Computer Sciences Div. 42 Output report contents Notes: In addition showing report on screen, echo command is also used to display folder contents with the command syntax: echo * Updated 25.08.20 Computer Sciences Div. 43 View file types Command name: file. Meaning: Xem loại tập tin. Syntax: file . Example: Updated 25.08.20 Computer Sciences Div. 44 Counting 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 Example: Updated 25.08.20 Computer Sciences Div. 45 Split 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 < tên tập tin nguồn> Example: Updated 25.08.20 Computer Sciences Div. 46 User accounts management commands on file system Account of system Rights to access on file Chmod command Command changes user that owns the file Updated 25.08.20 Computer Sciences Div. 47 Account of system Account 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 Updated 25.08.20 Tài khoản người dùng trên Linux Computer Sciences Div. 48 Account of system User account : Hộp thoại tạo mới user username: Tên người sử dụng. password: Mật khẩu. uid: Số nhận dạng (user identify number). gid: Số hiệu nhóm (group identify number). home directory: Thư mục chủ của tài khoản. Shell: Loại Shell mặc định cho tài khoản người dùng. Information above is stored in the file / etc / passwd Updated 25.08.20 Computer Sciences Div. 49 Account of system User 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 Updated 25.08.20 Computer Sciences Div. 50 Rights 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 Updated 25.08.20 Hộp thoại các quyền trên tập tin chotay Computer Sciences Div. 51 Chmod command Chmod command allows changing user’s rights on files. Only 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 Updated 25.08.20 Computer Sciences Div. 52 Chmod command Using symbols Cú pháp: chmod {a,u,g,o} {+,-,=} {r,w,x} {a,u,g,o}: a (all), u (user), g (group), o (other) {+,-,=}: + là thêm quyền, - là bớt quyền, = là gán bằng một giá trị khác {r,w,x}: r (read only), w (write) và x (excusive) Ví dụ: #chmod g+x chotay Updated 25.08.20 Hộp thoại phân quyền tập tin chotay Computer Sciences Div. 53 Chmod command Using absolute parameters Cú pháp: chmod . Trong đó: : 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 755 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 Updated 25.08.20 Computer Sciences Div. 54 Command 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. Trước Updated 25.08.20 Sau Computer Sciences Div. 55 Commands operation with system At command Hostname command Ps command Clear command Date command Cal command Who command Bc utility Updated 25.08.20 Computer Sciences Div. 56 At command Command 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 [Thời gian]. Trong đó: : -f file: Executing a file . -l: Displaying a list of commands. -d job [job…]: Delete command. [Thời gian]: Time to execute command. Updated 25.08.20 Computer Sciences Div. 57 Hostname name Command 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 Updated 25.08.20 Computer Sciences Div. 58 Ps command Command 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 Updated 25.08.20 Computer Sciences Div. 59 Clear command Command name: clear Meaning: Xoá màn hình. Syntax: clear Updated 25.08.20 Computer Sciences Div. 60 Date command Command name: date. Meaning: Hiển thị ngày giờ hiện hành của hệ thống máy tính. Syntax: date Updated 25.08.20 Computer Sciences Div. 61 Cal command Command name: cal. Meaning: Xem lịch với tháng và năm chỉ định. Syntax: cal Updated 25.08.20 Computer Sciences Div. 62 Who command Command name: who Meaning: To view user accounts using the system Syntax: who Updated 25.08.20 Computer Sciences Div. 63 Bc utility Basic calculator utility (basic calculator) provides a calculator set to perform manual calculations expressions, mathematical functions ,.... Updated 25.08.20 Computer Sciences Div. 64 Bc utility To assign the number of digits in the decimal, we use the scale command = n ; n is the number of digits in the decimal Updated 25.08.20 Computer Sciences Div. 65 Bc utility Programming on bc: To logout bc, using the keyboard: Ctrl + D. Using man bc command to view the instructions of this command . Updated 25.08.20 Computer Sciences Div. 66 Summary Overview 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 Updated 25.08.20 Computer Sciences Div. 67 QUESTIONS AND EXERCISES Questions Exercises Updated 25.08.20 Computer Sciences Div. 68 Questions Question 1. Which of the following basic syntax of a command on Linux is right : a. [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 Updated 25.08.20 Computer Sciences Div. 69 Questions Question 3. Which of the following command used to change the current folder? a. mkdir b. pwd c. cd d. tree Question 4. Which of the following command used to change the name of folder? a. mkdir b. rmdir c. tree d. mv Updated 25.08.20 Computer Sciences Div. 70 Questions Question 5. Which of the following command used to copy file? a. mv b. cp c. cat d. ls Question 5. Which of the following command used to delete file? a. mv b. rmdir c. rm d. who Updated 25.08.20 Computer Sciences Div. 71 Questions Question 7. Which of the following command used to view command’s instructions? a. help b. man c. rm d. who Question 8. Which of the following thing is implemented with echo command? a. Creating files b. Deleting folders c. View file types d. Outputting report contents Updated 25.08.20 Computer Sciences Div. 72 Câ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 Updated 25.08.20 Computer Sciences Div. 73 Exercises Bài thực hành số 1 Bài thực hành số 2 Updated 25.08.20 Computer Sciences Div. 74 1st Exercises Creating 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 bị sự cố (ví dụ hệ thống shutdown bất ngờ). Thiết lập chế độ mount tự động cho phân vùng đĩa trên mỗi khi Linux khởi động lại. Tạo đĩa khởi động cho Linux để ứng phó trong trường hợp bị sự cố. Updated 25.08.20 Computer Sciences Div. 75 2nd Exercises Using commands learned to implement the given scheme Updated 25.08.20 Computer Sciences Div. 76 [...]...Command 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 Updated 25.08.20 Computer Sciences Div 11 Change the current folder Command name: cd Function: Chuyển đổi thư mục hiện hành Syntax: cd : Displays contents of file on each page Updated 25.08.20 Computer Sciences Div 36 ... 29 Moving files Command 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] / 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: Updated 25.08.20 Computer Sciences Div... file Create 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 Updated 25.08.20 Computer Sciences Div 27 Copying files Command 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]

Ngày đăng: 22/10/2015, 19:54

Từ khóa liên quan

Mục lục

  • 2nd Chapter

  • Contents

  • Overview of commands on Linux

  • Slide 4

  • Slide 5

  • Command operation with drives: :

  • List and partition drives

  • Check capacity of drives

  • Attached partitions

  • Cancel attached partitions

  • Command operation with folder

  • Change the current folder

  • Slide 13

  • Slide 14

  • View/ check the current working folder

  • Create new folder

  • Display the structure of folder tree

  • List folder contents

  • Delete folder

  • Remove folder

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan