Table of contents
- The following examples cover common Linux command usage and can be adapted and extended to meet specific needs.
- Enter commands in the terminal
man
to view detailed help documentation for each command to learn more options and usage.
1. File and directory operations
instruction | Example | |
---|---|---|
Increase by .1 | mkdir :Create new directory |
mkdir new_directory |
Add.2 | touch :Create multiple files |
touch file1.txt file2.txt |
Delete.1 | rm : Delete Files |
rm file.txt |
Delete.2 | rm : delete directory |
rm -r directory/ |
Change.1 | cp : Copy files to target directory ( -r copy entire directory) |
cp file.txt /path/to/target |
Change.2 | mv : Move files to target directory |
mv file.txt /path/to/target |
Change.3 | mv : Rename file |
mv old_file.txt new_name.txt |
Change.4 | chmod : Modify file permissions |
chmod 755 file.txt |
Change.5 | cd : Move the user's home directory ( cd .. the command can return to the previous directory) |
cd /root/ |
Check.1 | ls : List the contents of the current directory ( -l display file information in a detailed list; -a display hidden files) |
ls |
Check.2 | pwd : Display the current working directory |
pwd |
Check.3 | cat : Display file content |
cat file.txt |
Check.4 | find : Find files in the specified directory |
find /path/to/search -name “*.txt” |
Check.5 | gerp : Search for the specified text in the file and output the line containing the text ( -i ignore case; -n display line number) |
grep “hello” myfile.txt |
Check.6 | head : Display the specified number of lines at the beginning of the file |
head -n 10 file.txt |
Check.7 | tail : Display the specified number of lines at the end of the file |
tail -n 20 file.txt |
2. Process management and query
instruction | Example | |
---|---|---|
1 | ps : Show running processes |
ps to |
2 | kill : Terminate process |
kill process_id |
3 | killall : Terminate all processes with the specified name |
killall process_name |
4 | top : Real-time display of process information running in the system, including CPU and memory usage (press q the key to exit top ) |
top |
3. Compression and decompression operations
instruction | Example | |
---|---|---|
1 | tar : package file |
tar -cvf archive.tar file1.txt file2.txt |
2 | tar : Unpack files |
tar -xvf archive.tar |
3 | gzip : Compressed file |
gzip file.txt |
4 | gzip : unzip files |
gzip -d file.txt.gz |
4. System information and management
instruction | Example | |
---|---|---|
1 | df : Display disk space usage |
df -h |
2 | du : Show folder size |
du -sh directory/ |
3 | ifconfig : Display network interface configuration |
ifconfig |
4 | ping : Test network connection |
ping google.com |
5 | free : Show detailed memory usage |
free -h |
6 | netstat : Display listening port and network connection |
netstat -tuln |
5. Remote and download operations
instruction | Example | |
---|---|---|
1 | ssh : Remotely log in to other computers ( -p specify port number; -i specify key file) |
ssh username@hostname |
2 | scp : Copy local files to remote computer ( -r copy entire directory; -P specify port number) |
scp file.txt username@hostname:/path/to/destination |
3 | wget : download file |
wget https://example.com/file.txt |
4 | curl :Download files, supports multiple protocols and data exchange formats ( -O automatically uses remote file name; -L follows redirects) |
curl https://example.com/file.txt -o file.txt |
6. User and permission management
instruction | Example | |
---|---|---|
1 | sudo : 以超级用户权限运行命令 |
sudo command |
2 | useradd : 添加新用户 |
sudo useradd newuser |
3 | userdel : 删除用户及其主目录 |
sudo userdel -r username |
4 | chmod : 分配执行权限 |
chmod 777 /root/start.sh |
7. 时间和日期操作
指令 | 示例 | |
---|---|---|
1 | date : 显示当前日期和时间 |
date |
2 | timedatectl : 设置系统时间和日期 |
sudo timedatectl set-time ‘YYYY-MM-DD HH:MM:SS’ |
3 | cal : 显示指定月份的日历 |
cal 5 2023 |
8. 运行和停止程序
指令 | 示例 | |
---|---|---|
1 | ./ : 运行可执行程序 |
./StartTest |
2 | sh : 运行sh文件 |
sh SeriveceStart.sh |
2 | Ctrl : 暂停程序 |
Ctrl + Z (快捷方式) |
2 | Ctrl : 停止程序 |
Ctrl + C (快捷方式) |
9. 其他操作
指令 | 示例 | |
---|---|---|
1 | echo : 打印文本到终端 |
echo “Hello, World!” |
2 | uname : 显示系统信息(内核版本等) |
uname -a |