Basic Linux commands everyone needs to know - Operations on Linux are much faster

When using Linux, you should also learn basic Linux commands to perform operations more quickly and easily. Below are some basic Linux commands you should know.

Just like the Windows operating system, when using Linux you should also learn basic Linux commands to perform operations more quickly and easily. Below are some basic Linux commands you should know.

With some of the commands below, you will see sets of commands with simple explanations, specific illustrative examples to help you or the Linux users you are supporting use this operating system in general, and the command line above. Linux in particular is more efficient.

1. Some important notes about Linux Terminal

Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 1Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 1

To quickly open Terminal from the GUI, press the key combination Ctrl + Alt + T .

Dissecting most Linux commands:

[sudo] command [optional switch] [file or directory path]

Using sudo will run any command under Admin. Most Linux commands are used to install/remove a program's system files, using something that requires sudo.

2. Get familiar with your account

These commands will help new Linux users get acquainted with their Linux account.

Command Function For example
pwd Displays the current location in the file system. pwd
whoami Show username - most useful if switching users with the su command and need to be reminded of which account is in use whoami
ls Provides a file list. With the -a parameter , the command displays files whose names begin with a period (for example, .bashrc). With the -l parameter , the command displays permissions, file size and last updated date/time. ls
ls -a
ls -l
env Shows user environment settings (e.g. search path, saved history size, home directory, etc.) env
echo. echo Echoes user-supplied text or displays the value of some variable. echo hello
echo $PATH
history. history Lists previously issued commands. history
history | tail -5
passwd Change the password. Note that complex requirements may be enforced. passwd
history | tail -5

3. Create a new folder

mkdir is a basic directory manipulation command on Linux, helping you create a new directory quickly. Command syntax:

mkdir folder

Note:

Folder is the name of the folder you want to create. For example, if you want to create a folder named backup, the syntax is:

mkdir /home/marin/backup

In case if you want to create a folder containing many subfolders, you can use the "-p" option . Suppose, you have the directory foo and have access to it:

mkdir -p /foo/bar/baz

The above command will create the bar directory, the baz directory is located in bar; bar and baz are in /foo already.

4. Search the current directory

If you want to search your current directory, you can use the pwd command.

The pwd command in Linux stands for present working directory. When it comes to Linux commands, this is one of the simplest. Its only function is to export the current working directory in the terminal. It comes in handy when you're not sure exactly what directory you're in, or when you need to move the current working directory inside a Bash script, for example.

Eg:

marin@[LinuxVeda]:[~/work]$ pwd /home/marin/work

You can change directories using the cd command or list the contents of the current directory using the ls command.

You can use this command to help determine your current location in the directory structure. It is also a very useful command to use in scripts where you may not know the exact directory structure of where the script is running.

This command is usually built-in as a shell builtin in most modern shells such as bash, zsh, and ksh. System administrators mainly use the command because regular users don't need it.

The pwd command itself is extremely simple and does not require any additional flags or parameters. The standard syntax of the command is as follows.

pwd [option]…

To display the current working directory using pwd's default behavior, simply enter the following line in the command prompt.

pwd

The pwd command accepts two different flags.

  1. -L will print the path even if it includes symbolic links.
  2. -P Will print the physical path, avoiding symbolic links.

It is important to note that the behavior of pwd is slightly different from the /bin/pwd command.

5. Create and edit files

Linux systems provide commands to create files. The user can select the desired text editor. Some commands require users to be proficient before using them, while others are quite simple.

Command Function For example
nano An easy-to-use text editor that requires the user to move around in the file using arrow keys and provides control sequences to position text, save changes, etc. nano myfile
Because A more sophisticated editor, allowing users to enter commands to find and change text, make global changes, etc. vi myfile
ex A text editor designed for programmers and has both visual and command-line modes. ex myfile
touch Create a file if it does not exist yet or update the timestamp if it has been created. touch newfile
touch updatedfile
> Create files by directing output to them. > creates a file while >> attaching to an existing file. cal > calendar
ps > myprocs
date >> date.log

6. Read some files

Usually you have to review the contents of many different files. Regularly reviewing different files is often quite complicated and time-consuming. Therefore the simplest way to read their contents is to use the cat command. The command syntax is quite simple:

cat FILE

Just change FILE with the file name you want to read. As a result, you will see the content of the file appear at the bottom of Terminal.

Eg:

cat script.sh

Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 2Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 2

Additionally, you can use the cat command for multiple files at once:

cat FILE-1 FILE-2

The output of the command will display the contents of the files in the order of the contents of FILE - 1 and then the contents of FILE -2.

Additionally, Linux provides a number of commands to review the content and nature of files. Here are some of the most useful commands.

Command Function For example
cat Displays the entire content of a text file. cat .bashrc
more Displays the content of the text file. Press the spacebar to move to each additional paragraph. more .bash_history
less. less Displays the contents of the text file, but allows you to return using the up arrow key. less .bash_history
file Identify files by type (e.g. ASCII text, executable files, images, folders) file myfile
file ~/.bashrc
file /bin/echo

7. Copy or move files

Copying or moving files in the Linux terminal is quite simple and easy.

  1. To copy a file, you can use the command: cp.
  2. To move a file, use the command: mvoflder.

Both commands are quite simple to use. With the cp command . To copy a file, enter a file name and enter a new copy file name. For example:

cp file1 file2

The above command copies file1 and creates file2 containing the contents of file1. You can use cp to copy directories. It is important to note that when you want to copy a directory you should use the -r option .

In other words, cp -r will copy the contents of a given directory (and subdirectories) to the directory of your choice. Also you can use cp with full path:

cp -r /home/marin/work/ /home/marin/backup

The above command will copy the contents of the "work" folder to a new folder named "backup".

If you want to copy all files and folders of one folder to another folder, you can use the "*" character . The character is used to find suitable ports (in this case, files and directories). For example:

cp /home/marin/work/* /home/marin/backup/

Next is the mv command. Command syntax:

mv file1 file2

The above command changes file1 to file2. The same goes for folders. However, if you specify 1 file and 1 folder, the file will be moved into the folder. Such as:

mv /home/marin/file1 /home/marin/work/

The above command will move file1 from '/home/marin/' to '/home/marin/work/'. If you want to move all files in one folder to another folder, you can use the "*" character :

mv /home/marin/work/* /home/marin/backup/

8. Delete files and folders

If you want to delete a folder or a file, you can use the rm command . It is important to note that when using this command to delete a file or folder, these files cannot be restored. To delete a file, do:

rm /home/marin/useless-file.txt

You can use rm with many different options. Some important options include:

  1. -f: force deletion of files with reminder messages
  2. -i: prompt before deletion
  3. -r: delete directories recursively
  4. -d: delete empty directories
  5. -v: explains what task is being performed

9. Find files

There are two commands that can help users find files on Linux, but they work very differently. One command searches the file system, while the other looks at a previously built database.

Command

Function

For example
find.find Locate files based on provided criteria (name, type, owner, permissions, file size, etc.). Unless a location is given to start the search, this command searches only in the current directory. find . -name myfile
find /tmp -type d
locate. locate Locate files using the contents of /var/lib/mlocate/mlocate.db updated by the updateb command run via cron. No starting position required. locate somefile
locate "*.html" -n 20

Note: Details about the find command are in the section below.

10. List directory contents

To list directories, you can use the ls command :

Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 3Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 3

The "ls" command can take different parameters that help you change the output of the command. For example, the "-a" parameter will display all files and folders, including hidden folders containing "-a".

Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 4Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 4

If you want the command output to display a detailed list of information for each file and directory, you can use the '-l' (L) option :

ls -l You can try different

Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 5Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 5

Additionally, you can combine parameters to display detailed information for all files:

ls –al

Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 6Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 6

11. Search for the previous Linux command

Pressing the Up key will display the last Linux command you used successfully. There are no error statements displayed here.

Additionally, you can use the history command to view all Linux commands ever used on Terminal.

12. Invisible password

Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 7Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 7

When asked to enter a password, let's say in the case of using sudo , when you type the password on the screen nothing will be displayed, no stars or dots. After entering the password, you Press Enter and you're done.

13. Copy and paste Linux commands

Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 8Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 8

To copy or paste Terminal commands, you cannot use the familiar key combinations Ctrl + C and Ctrl + V.

Instead you can use Ctrl + Shift + C and Ctrl + Shift + V or right-click and select Copy or Paste from the Context Menu.

14. Display progress in Linux system

Một trong những công việc cần thiết khi quản trị hệ thống Linux đó là kiểm soát các tiến trình hiện đang chạy. Khi đã biết được những tiến trình nào đang chạy bạn có thể tắt những tiến trình gây giảm tốc độ của hệ thống. Ngoài ra, thông tin về những tiến trình hệ thống cho chúng ta biết nên tắt nhưng tiến trình làm cho hệ thống vận hành không ổn định. Do đó việc biết được những tiến trình nào đang chạy trên hệ thống rất quan trọng. Linux hỗ trợ nhiều phương pháp kiểm tra tiến trình, một trong số đó là sử dụng lệnh ps. Khi sử dụng lệnh này mọi thông tin về những tiến trình đang chạy sẽ được hiển thị. Bạn chỉ cần nhập cú pháp lệnh sau vào cửa sổ terminal:

# ps aux | less

Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 9Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 9
Hình 1: Thông tin tiến trình đang chạy trong hệ thống.

Ngoài ra lệnh này có thể sử dụng kết hợp với một số tham số khác như:

# ps –A: Kiểm tra mọi tiến trình trong hệ thống.
# ps -U root -u root –N: Kiểm tra mọi tiến trình ngoại trừ những tiến trình hệ thống.
# ps -u username: Kiểm tra những tiến trình được thực hiện bởi một người dùng nhất định.

Hoặc bạn có thể sử dụng lệnh # top để xem những tiến trình đang chạy trên hệ thống trong thời gian thực.

15. Kiểm tra thông tin Socket và thông tin mạng TCP/UDP

Sau khi cấu hình những dịch vụ mạng của hệ thống Linux, bạn cần phải giữ lại tab của các cổng đang thực sự nhận tín hiệu trên giao diện mạng của hệ thống. Điều này rất quan trọng vì hệ thống có thể bị xâm nhập qua các cổng mở. Có một số công cụ quản lý Linux thông báo cho bạn biết thông tin của những cổng mởvà truy cập vào những cổng đang mở trên mạng. Một trong những phương pháp đơn giản và tin cậy nhất đó là sử dụng lệnh ss để kiểm tra thông tin Socket, ngoài ra lệnh này còn có thể hiển thị nhiều thông tin TCP và thông tin trạng thái hơn các công cụ khác. Lệnh ss này cung cấp thông tin về:

  1. Mọi Socket TCP.
  2. Mọi Socket UDP.
  3. Mọi kết nối ssh/ftp/http/https.
  4. Mọi tiến trình cục bộ được kết nối tới máy chủ X.
  5. Mọi Socket TCP trong trạng thái FIN-WAIT-1.

Dưới đây là một số lệnh ss:

  1. # ss –s: Hiển thị tổng số Socket.

Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 10Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 10 Hình 2: Thông tin kết xuất khi chạy lệnh # ss –s.

  1. # ss -1: Hiển thị mọi cổng mở.

Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 11Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 11
Hình 3: Thông tin kết xuất khi chạy lệnh # ss -1.

  1. # ss –pl: Kiểm tra tên tiến trình sử dụng Socket mở sử dụng lệnh sau:
  2. # ss -lp | grep: Kiểm tra người dùng đang làm việc với Socket mở.
  3. # ss -t –a: Hiển thị mọi Socket TCP.
  4. # ss -u –a: Hiển thị mọi Socket UDP.

16. Theo dõi Average CPU Load và Disk Activity

Nếu là một quản trị viên hệ thống Linux, bạn cần phải biết phương pháp duy trì một sự cân bằng hợp lý trong quá trình tải đầu vào và đầu ra giữa các ổ đĩa vật lý. Bạn có thể thay đổi cấu hình hệ thống để thực hiện tác vụ này. Tuy nhiên có một phương pháp đơn giản hơn rất nhiều đó là sử dụng lệnh isostat để quản lý hệ thống thiết bị tải đầu vào và đầu ra trong Linux bằng cách theo dõi thời gian hoạt động và tốc độ truyền trung bình của những thiết bị này. Lệnh này sẽ thông báo thông tin của CPU (Central Processing Unit), thông tin đầu vào và đầu ra cho những thiết bị, phân vùng và hệ thống file mạng (NFS).

Khi chạy lệnh isostat thông tin kết xuất có dạng:

Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 12Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 12 Hình 4: Thông tin hiển thị khi chạy lệnh isostat.

Để lấy thông tin thư mục NFS bạn hãy sử dụng lệnh sau:

# iostat –n

17. Kiểm tra Memory Map của các tiến trình trong Linux

Khi làm việc trong hệ thống Linux có thể bạn cần kiểm tra dung lượng bộ nhớ sử dụng trong hệ thống. Linux tích hợp nhiều lệnh cho phép kiểm tra dung lượng bộ nhớ chiếm dụng. Trong đó có một lệnh đơn giản giúp hiển thị thông tin tổng dung lượng đã chiếm dụng và chưa chiếm dụng của bộ nhớ vật lý và tổng dung lượng bộ nhớ đó là lệnh free.

Sau khi chạy lệnh này bạn sẽ thấy tổng dung lượng đã chiếm dụng và chưa chiếm dụng của bộ nhớ vật lý và tổng dung lượng bộ nhớ trong hệ thống. Ngoài ra nó còn hiển thị thông tin bộ nhớ đệm mà các nhân sử dụng.

Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 13Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 13
Hình 5: Thông tin hiển thị sau khi chạy lệnh free

18. Kiểm tra thời gian vận hành của hệ thống

Bạn có muốn biết máy chủ đã vận hành bao lâu? Nếu muốn bạn chỉ cần sử dụng lênh uptime để kiểm tra thời gian mà hệ thống đã vận hành. Lệnh đơn giản này không chỉ cho bạn biết thời gian hệ thống vận hành mà còn cho biết lượng người dùng đã đăng nhập vào hệ thống trong một khoảng thời gian trước đó.

Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 14Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 14 Hình 6: Kết quả lệnh uptime.

19. Kiểm tra người dùng đăng nhập

Ngoài những công cụ quản lý Linux, bạn có thể sử dụng một lệnh để kiểm tra những người dùng nào đã thực hiên đăng nhập vào hệ thống và những gì họ đã thực hiện. Lệnh này sẽ hiển thị thời gian hiện tại, thời gian hệ thống đã vận hành, lượng người dùng đã đăng nhập.

Ngoài ra lệnh này cũng hiển thị lượng tải trung bình trong mỗi 1, 5 và 15 phút. Lệnh này rất hữu dụng với những Admin hệ thống muốn sử dụng thông tin tải trung bình để hoạch định dung lượng.

Để kiểm tra ai đã đăng nhập vào hệ thống và những tác vụ họ đã thực hiện bạn chỉ cần chạy lệnh sau:

# w username

Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 15Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 15
Hình 7: Thông tin hiển thị sau khi chạy lệnh # w username.

20. Kiểm soát hành vi hệ thống, phần cứng và thông tin hệ thống trong Linux

Với nhiều người dùng Linux, kiểm soát hệ thống là một tác vụ phức tạp. Hầu hết các bản phân phối Linux tích hợp khá nhiều công cụ kiểm soát. Những công cụ kiểm soát này cung cấp các phương pháp có thể được áp dụng để kiểm tra thông tin hành vi hệ thống. Việc kiểm soát hệ thống cho phép người dùng theo dõi nguyên nhân khả năng thực thi của hệ thống bị cản trở. Một trong những tác vụ cần thiết của quá trình kiểm soát hệ thống là tra cứu thông tin về hành vi hệ thống, phần cứng và thông tin bộ nhớ. Có một lệnh đơn giản giúp hiển thị thông tin về tiến trình, bộ nhớ, trang ghi, nhóm IO, lỗi và hành vi CPU đó là lệnh vmstat.

Bạn chỉ cần nhập lệnh sau vào cửa sổ terminal:

# vmstat 3

Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 16Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 16
Hình 8: Thông tin kết xuất của lệnh # vmstat 3.

Ngoài ra bạn có thể sử dụng lệnh # vmstat –m để kiểm tra thông tin bộ nhớ, và lệnh # vmstat –a để hiển thị thông tin trang nhớ đang hoạt động và không hoạt động.

Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 17Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 17
Hình 9: Thông tin hiển thị sau khi chạy lệnh # vmstat –a.

21. Kiểm tra thông tin phần cứng của hệ thống Linux

Với một số người dùng Linux thì việc kiểm tra thông tin phần cứng thật không dễ dàng. Linux là một hệ thống phức tạp nhưng nó lại tích hợp một số công cụ giúp lấy thông tin chi tiết của phần cứng, chẳng hạn chúng ta có thể sử dụng một lệnh khá đơn giản để kiểm tra thông tin đĩa cứng trên hệ thống đó là lệnh hdparm. Lệnh này cung cấp một giao diện dòng lệnh để thực hiện quản lý nhiều loại đĩa cứng được hệ thống phụ điều khiển thiết bị ATA/IDE của Linux hỗ trợ. Nó cung cấp một lệnh giúp hiển thị thông tin xác minh như dung lượng, thông tin chi tiết, … trực tiếp từ ổ đĩa. Thông tin này được lưu dưới một định dạng mở rộng mới. Bạn chỉ cần đăng nhập dưới quyền root user và sử dụng lệnh sau:

# hdparm -I /dev/sda

Hoặc dùng lệnh:

$ sudo hdparm -I /dev/sda

Khi đó thông tin về đĩa cứng của hệ thống sẽ lập tức hiển thị.

Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 18Basic Linux commands everyone needs to know - Operations on Linux are much faster Picture 18
Hình 10: Thông tin chi tiết của đĩa cứng.

22. Các lệnh xử lý tập tin trên Linux

Lệnh để di chuyển xung quanh hệ thống file Linux là ls, nhưng có nhiều biến thể.

Lệnh Linux Nhiệm vụ lệnh sẽ làm
ls Liệt kê nội dung thư mục hiện tại
ls -al Liệt kê nội dung thư mục bao gồm cả file ẩn
cd dir Di chuyển từ thư mục hiện tại sang thư mục dir
cd Chuyển từ thư mục hiện tại về thư mục riêng (thường là [Tên User] ở Home)
cd . Di chuyển lên (về /) một thư mục từ vị trí hiện tại.
cd

Đưa người dùng đến vị trí được chỉ định. Nếu vị trí bắt đầu bằng /, nó được coi là tương đối với thư mục gốc và vị trí hiện tại. Ký tự ~ đại diện cho thư mục Home. Ví dụ:

cd /tmp
cd Documents
cd ~/Documents

pwd Hiện thư mục hiện tại
mkdir TipsMake Tạo thư mục mới có tên là TipsMake
rm filemuonxoa Xóa file có tên là filemuonxoa
rm -r thumuccanxoa Xóa thư mục có tên là TipsMake
rm -f filecanxoa Bắt xóa file có tên là filecanxoa
rm -rf thumuccanxoa Bắt xóa thư mục có tên là thumuccanxoa
cp file1 file2 Sao chép file1 sang file2
cp -r dir1 dir2 Sao chép thư mục dir1 sang dir2 và tạo dir2 nếu chưa có dir2
mv file1 file2 Di chuyển file1 đến chỗ file2 hoặc đổi tên file1 thành file2. Nếu file2 có sẵn thì di chuyển file1 vào file2
ln -s tenfile link Tạo liên kết biểu tượng có tên là link đến file có tên là tenfile
touch filecantao Tạo hoặc cập nhật tập tin filecantao
cat > tenfile Nhập từ bàn phím (đầu vào chuẩn - standard input) vào tập tin tenfile mới
more tenfile Hiện nội dung file có tên là tenfile
head tenfile Hiện 10 dòng đầu của tập tin tenfile
tail tenfile Hiện 10 dòng cuối của tập tin tenfile
tail -f tenfile Hiện nội dung của tập tin tenfile và cập nhật liên tục trong thời gian thực
tail -f -n N tenfile Hiện nội dung của tập tin tenfile và cập nhật liên tục, giới hạn N dòng

23. Các lệnh mạng trên Linux

TipsMake đã có một bài hướng dẫn khá chi tiết về các lệnh làm việc với mạng trên Linux, bạn quan tâm có thể tham khảo nha.

24. Bắt đầu, dừng và liệt kê các service

Các lệnh này cho phép người dùng hiển thị các service cũng như bắt đầu và dừng chúng.

Lệnh Chức năng Ví dụ
systemctl Lệnh systemctl có thể bắt đầu, dừng, khởi động lại và load lại các service, cần có quyền admin. sudo systemctl stop apache2.service
sudo systemctl restart apache2.service
sudo systemctl reload apache2.service
service Liệt kê các service và cho biết liệu chúng có đang chạy không. service --status-all

25. Xác định phiên bản hệ điều hành

Bảng bên dưới liệt kê các lệnh sẽ hiển thị chi tiết về hệ điều hành Linux đang chạy trên hệ thống.

Lệnh Chức năng Ví dụ
uname Hiển thị thông tin về phiên bản hệ điều hành trong một dòng văn bản. uname -a
uname -r
lsb_release Trên các hệ thống dựa trên Debian, lệnh này hiển thị thông tin về hệ điều hành bao gồm codename và ID nhà phân phối. lsb_release -a
hostnamectl Hiển thị thông tin trên hệ thống bao gồm tên máy chủ, loại chassis (thùng máy), hệ điều hành, kernel và cấu trúc. hostnamectl

26. Đo hiệu suất hệ thống

Sau đây là một số công cụ hữu ích để kiểm tra hiệu năng hệ thống.

Lệnh Chức năng Ví dụ
top Hiển thị các tiến trình đang chạy cùng với việc sử dụng tài nguyên và dữ liệu hiệu suất hệ thống. Có thể hiển thị các tiến trình cho một người dùng đã chọn hoặc tất cả người dùng. Các tiến trình có thể được sắp xếp theo các tiêu chí khác nhau (theo mặc định là mức độ sử dụng CPU). top
top jdoe
atop Tương tự như lệnh trên nhưng hướng nhiều đến hiệu năng hệ thống hơn so với các tiến trình riêng lẻ. atop
free Hiển thị bộ nhớ và trao đổi tổng bộ nhớ, phần đã sử dụng và còn trống. free
df Hiển thị việc sử dụng không gian ổ đĩa hệ thống của file. df
df -h

27. Quản lý người dùng và nhóm

Các lệnh để tạo và xóa tài khoản người dùng và các nhóm khá đơn giản.

Lệnh Chức năng Ví dụ
useradd Thêm tài khoản người dùng mới vào hệ thống. Tên người dùng là bắt buộc. Các trường khác (mô tả người dùng, shell, mật khẩu ban đầu, v.v.) có thể được chỉ định. Thư mục chính sẽ mặc định là /home/username. useradd -c "John Doe" jdoe
useradd -c "Jane Doe" -g admin -s /bin/bash jbdoe
userdel Xóa tài khoản người dùng khỏi hệ thống. Tùy chọn -f mạnh mẽ hơn, xóa các file chính và file người dùng khác ngay cả khi người dùng vẫn đăng nhập. userdel jbdoe
userdel -f jbdoe
groupadd Thêm một nhóm người dùng mới vào hệ thống, cập nhật /etc/group. groupadd developers
groupdel Xóa nhóm người dùng khỏi hệ thống. groupdel developers

28. Thiết lập và chạy các tiến trình theo lịch

Các tác vụ có thể được lên lịch để chạy định kỳ bằng cách sử dụng lệnh được liệt kê dưới đây.

Lệnh Chức năng Ví dụ
crontab Thiết lập và quản lý các tiến trình theo lịch. Với tùy chọn -l, các công việc định kỳ được liệt kê. Với tùy chọn -e, các công việc định kỳ có thể được thiết lập để chạy ở các khoảng thời gian đã chọn. crontab -l
crontab -l -u username
crontab -e
anacron Cho phép người dùng chỉ chạy các công việc theo lịch trình hàng ngày. Nếu hệ thống bị tắt khi một công việc được đặt lịch chạy, nó sẽ chạy khi hệ thống khởi động. sudo vi /etc/anacrontab

29. Cập nhật, cài đặt và liệt kê các ứng dụng

Các lệnh để cài đặt và cập nhật ứng dụng tùy thuộc vào phiên bản Linux đang sử dụng, cụ thể là dựa trên nền tảng Debian hay RPM.

Lệnh Chức năng Ví dụ
apt update Trên các hệ thống dựa trên Debian, lệnh này cập nhật danh sách các gói có sẵn và các phiên bản của chúng, nhưng không cài đặt hoặc nâng cấp bất kỳ gói nào sudo apt update
apt upgrade Trên các hệ thống dựa trên Debian, lệnh này cài đặt các phiên bản mới hơn của các gói đã có. sudo apt upgrade
apt list Liệt kê tất cả các gói được cài đặt trên hệ thống dựa trên Debian. Với tùy chọn --upgradable, nó chỉ hiển thị các gói có bản nâng cấp. apt list
apt list --installed
apt list --upgradable
apt install Trên các hệ thống dựa trên Debian, lệnh này cài đặt gói được yêu cầu. sudo apt install apache2
yum update Trên các hệ thống dựa trên RPM, lệnh này cập nhật tất cả hoặc các gói được chỉ định. sudo yum update
yum update mysql
yum list Trên các hệ thống dựa trên RPM, lệnh này liệt kê các gói. sudo yum update mysql
yum install Trên các hệ thống dựa trên RPM, lệnh này cài đặt gói được yêu cầu. sudo yum -y install firefox
yum list Trên các hệ thống dựa trên RPM, lệnh này liệt kê các gói đã biết và đã cài đặt. sudo yum list
sudo yum list --installed

30. Tắt và khởi động lại

Các lệnh tắt và khởi động lại hệ thống Linux yêu cầu quyền admin. Các tùy chọn như +15 là số phút mà lệnh sẽ đợi trước khi yêu cầu tắt máy được thực hiện.

Lệnh Chức năng Ví dụ
shutdown Tắt hệ thống tại thời điểm yêu cầu. Tùy chọn -H tạm dừng hệ thống, còn tùy chọn -P sẽ tắt nguồn. sudo shutdown -H now
shutdown -H +15
shutdown -P +5
halt Tắt hệ thống tại thời điểm yêu cầu. sudo halt
sudo halt -p
sudo halt --reboot
poweroff Ngắt nguồn khỏi hệ thống tại thời điểm yêu cầu. sudo shutdown -H now
sudo shutdown -H +15
sudo shutdown -P +5

31. Lệnh bảo mật Linux

Mình đã tổng hợp 20+ lệnh bảo mật Linux thiết yếu, rất cần thiết cho các vấn đề bảo mật trên Linux, bạn cần thì tham khảo nha.

Tham khảo thêm một số bài viết dưới đây:

Chúc các bạn thành công!

4.5 ★ | 2 Vote