Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

Basic Linux Commands Everyone Needs to Know - Operations on Linux

Explore Basic Linux Commands Everyone Needs to Know - Operations on Linux with a useful overview of key features, uses, setup advice, limitations.

Table of Contents

This updated overview organizes the essential information about Basic Linux Commands Everyone Needs to Know - Operations on Linux, including practical uses, key features, setup considerations, and common questions.

What This Guide Covers

  • 1. Some important notes about Linux Terminal
  • [sudo] command [optional switch] [file or directory path]
  • 2. Get familiar with your account

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

1. Some important notes about Linux Terminal - Basic Linux Commands Everyone Needs to Know - Operations on

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.

  • -L will print the path even if it includes symbolic links.
  • -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

6. Read some files - Basic Linux Commands Everyone Needs to Know - Operations on Linux

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.

  • To copy a file, you can use the command: cp.
  • 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:

  • -f: force deletion of files with reminder messages
  • -i: prompt before deletion
  • -r: delete directories recursively
  • -d: delete empty directories
  • -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 :

10. List directory contents - Basic Linux Commands Everyone Needs to Know - Operations on Linux

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".

10. List directory contents - Basic Linux Commands Everyone Needs to Know - Operations on Linux example 2

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

10. List directory contents - Basic Linux Commands Everyone Needs to Know - Operations on Linux example 3

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

ls –al

10. List directory contents - Basic Linux Commands Everyone Needs to Know - Operations on Linux example 4

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

12. Invisible password - Basic Linux Commands Everyone Needs to Know - Operations on Linux

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

13. Copy and paste Linux commands - Basic Linux Commands Everyone Needs to Know - Operations on Linux

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

# ps aux | less

14. Display progress in Linux system - Basic Linux Commands Everyone Needs to Know - Operations on Linux Hình 1: Thông tin ti?n trình ?ang ch?y trong h? th?ng.

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

  • M?i Socket TCP.
  • M?i Socket UDP.
  • M?i k?t n?i ssh/ftp/http/https.
  • M?i Socket TCP trong tr?ng thái FIN-WAIT-1.
  • # ss –s : Hi?n th? t?ng s? Socket.

15. Ki?m tra thông tin Socket và thông tin m?ng TCP/UDP - Basic Linux Commands Everyone Needs to Know Hình 2: Thông tin k?t xu?t khi ch?y l?nh # ss –s.

  • # ss -1 : Hi?n th? m?i c?ng m?.

15. Ki?m tra thông tin Socket và thông tin m?ng TCP/UDP - Basic Linux Commands Everyone Needs to Know example 2 Hình 3: Thông tin k?t xu?t khi ch?y l?nh # ss -1.

  • # ss -lp | grep : Ki?m tra ng??i dùng ?ang làm vi?c v?i Socket m?.
  • # ss -t –a : Hi?n th? m?i Socket TCP.
  • # ss -u –a : Hi?n th? m?i Socket UDP.

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

Khi ch?y l?nh isostat thông tin k?t xu?t có d?ng:

16. Theo dõi Average CPU Load và Disk Activity - Basic Linux Commands Everyone Needs to Know - Operations on Hình 4: Thông tin hi?n th? khi ch?y l?nh isostat.

# iostat –n

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

17. Ki?m tra Memory Map c?a các ti?n trình trong Linux - Basic Linux Commands Everyone Needs to Know 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

18. Ki?m tra th?i gian v?n hành c?a h? th?ng - Basic Linux Commands Everyone Needs to Know - Operations on Hình 6: K?t qu? l?nh uptime.

19. Ki?m tra ng??i dùng ??ng nh?p

# w username

19. Ki?m tra ng??i dùng ??ng nh?p - Basic Linux Commands Everyone Needs to Know - Operations on Linux 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

B?n ch? c?n nh?p l?nh sau vào c?a s? terminal:

# vmstat 3

20. Ki?m soát hành vi h? th?ng, ph?n c?ng và thông tin h? th?ng trong Linux - Basic Linux Commands Everyone Hình 8: Thông tin k?t xu?t c?a l?nh # vmstat 3.

20. Ki?m soát hành vi h? th?ng, ph?n c?ng và thông tin h? th?ng trong Linux - Basic Linux Commands example 2 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

# 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?. 21. Ki?m tra thông tin ph?n c?ng c?a h? th?ng Linux - Basic Linux Commands Everyone Needs to Know 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

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

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

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

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

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

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

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

Final Thoughts

Use the instructions and checks above in order, verify the result after each major step, and keep a backup whenever the process changes important files or system settings.

FAQ

What is Linux, Linux commands used for?

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

Who should consider Linux, Linux commands?

It is most useful for readers who need the features, workflow, or problem-solving approach described in this guide.

What should I check before using it?

Review compatibility, current software requirements, privacy or security settings, costs, and any limitations that could affect your workflow.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.