1. ls Command
Description
ls Command Function: List directory contents (displays the list of files and subdirectories in the current or specified directory)
In the terminal of Ubuntu (or other Linux distributions), the ls command is used to list files and subdirectories within a directory (folder). If no parameters are provided after the command, it displays non-hidden files and folders in the current directory by default:
lsIn Linux, hidden files (files or directories starting with .) are not displayed by default. If you need to see all files (including hidden files), add the -a parameter:
ls -aIf you need detailed information (including permissions, owner, size, modification time, etc.), add -l:
ls -lA common combination is -a and -l (the order can vary):
ls -al
# or
ls -la2
3
Files starting with
.are hidden files. For example,.cache.
Common ls -l output explanation (columns from left to right):
| File Type and Permissions | Links | Owner | Group | File Size (bytes) | Last Modified Time | File/Directory Name |
|---|---|---|---|---|---|---|
| drwxr-xr-x | 2 | root | root | 4096 | Dec 9 10:41 | file/directory name |
- First column: File type and permissions. The first character represents the type:
d: directory-: regular filel: symbolic linkp: named pipeb: block devicec: character devices: socket
- Next 9 characters: Permission indicators (in order: owner, group, and other users' read r/write w/execute x permissions)
- Second column: Number of hard links
- For regular files, this is the number of hard links to the file
- For directories, this is the number of subdirectories (including itself and parent directory)
- Third/Fourth columns: Owner, Group
- Fifth column: File size (in bytes)
- Sixth column: Last modification time
- Last column: File or directory name
.represents the current directory,..represents the parent directory
Common parameter descriptions:
-aDisplay all files, including hidden files-lUse long format to display detailed information-tSort by modification time-sDisplay file size (in blocks)
2. cd Command
Description
cd Command Function: Change the current working directory
Usage is simple: cd <directory path>, switches the current Shell to the target directory.
- Go to the parent directory:
cd ..- Go into the
TaishanPi-3-Linuxsubdirectory:
cd TaishanPi-3-Linux/Tip: After entering the first few letters of a directory name, press
Tabkey to auto-complete the file or directory name.
3. pwd Command
Description
pwd Command Function: Display the absolute path of the current working directory
Executing pwd displays the full path of the current directory (starting from root /).
4. mkdir Command
Description
mkdir Command Function: Create a new directory (folder)
- Single directory
mkdir test- To create multiple levels of directories (e.g.,
test/test1), it is recommended to use the-pparameter, which creates both parent and child directories at once:
mkdir -p test/test15. rmdir Command
Description
rmdir Command Function: Remove an empty directory
rmdir can only delete empty directories. If the directory is not empty, use rm -r
In practice,
rm -ris generally used to delete non-empty directories.
6. rm Command
Description
rm Command Function: Remove files or directories
- Remove a file:
rm file.txt- To remove a directory (including contents), add
-r(recursive):
rm -r testdir- Force removal without prompt:
rm -rf testdir- Ask for confirmation before each deletion (interactive mode):
rm -ri testdirOnce deleted, recovery is not easy. Be careful with this operation!
7. touch Command
Description
touch Command Function: Create an empty file or modify the timestamp of an existing file
- Create a new empty file:
touch filename.txt- If the file already exists,
touchwill modify its modification time without changing the file content.
8. clear Command
Description
clear Command Function: Clear the terminal display content (but does not delete command history)
After executing clear, the terminal window display is cleared, but the history can still be retrieved using the up arrow.
9. reset Command
Description
reset Command Function: Reinitialize the terminal
reset reinitializes terminal settings, restoring display and input, similar to restarting the terminal. It clears the current screen display and historical content.
10. cp Command
Description
cp Command Function: Copy files or directories
- Copy a file:
cp source_file target_file- When copying a directory, add the
-rparameter:
cp -r source_dir target_dir11. mv Command
Description
mv Command Function: Move (cut) files or directories, or rename files/directories
- Move files/directories:
mv source_file target_directory/- Rename a file or directory:
mv old_name new_name12. ifconfig Command
Description
ifconfig Command Function: Display and configure network interfaces (it is recommended to use ip a on newer systems)
The ifconfig utility is used to display or configure network interfaces. Most modern Linux distributions recommend using the ip command instead:
ifconfig
# or
ip a2
3
If
ifconfigis not installed, you can usesudo apt update && sudo apt install -y net-toolsto install it.
13. cat Command
Description
cat Command Function: Concatenate and display file contents
Commonly used to quickly view the contents of a text file:
cat filenameFor longer files, it is recommended to use
lessormorefor paginated viewing.
14. reboot Command
Description
reboot Command Function: Restart the computer
Executing this will restart immediately. Sometimes superuser permissions are required:
sudo reboot15. poweroff Command
Description
poweroff Command Function: Shut down the computer
Executing this will begin the shutdown process immediately. Superuser permissions are also often required:
sudo poweroff