常用命令
OnethingAI
发布于:2025-06-12
常用命令
Linux 更多常用命令:45 个常用 Linux 命令,让你轻松玩转 Linux! - 掘金 (juejin.cn)
查看当前目录下的文件/文件夹
命令: ls
(base) root@instance:~/onethingai-tmp# ls test.tar.gz test.txt test1.txt test_dir
查看当前目录路径
命令: pwd
(base) root@instance:~/onethingai-tmp# pwd /root/onethingai-tmp
切换目录
命令: cd
(base) root@instance:~/onethingai-tmp# cd test_dir/ (base) root@instance:~/onethingai-tmp/test_dir# pwd /root/onethingai-tmp/test_dir
切换目录中,有一些特殊的符号定义,~ 表示为 home directory,. 则是表示目前所在的目录,.. 则表示目前目录位置的上一层目录。
(base) root@instance:~/onethingai-tmp/test_dir_1# pwd /root/onethingai-tmp/test_dir_1
(base) root@instance:~/onethingai-tmp/test_dir_1# cd .. #切换到上一层目录
(base) root@instance:~/onethingai-tmp# pwd /root/onethingai-tmp
(base) root@instance:~/onethingai-tmp# cd ~ #切换到home directory
(base) root@instance:~# pwd /root
创建目录
命令: mkdir
plain (base) root@instance:~/onethingai-tmp# mkdir test_dir_1 (base) root@instance:~/onethingai-tmp# ls test.tar.gz test.txt test1.txt test_dir test_dir_1
拷贝文件/目录
命令: cp
plain (base) root@instance:~/onethingai-tmp/test_dir_1# ls test.txt test_dir (base) root@instance:~/onethingai-tmp/test_dir_1# cp test.txt test1.txt #拷贝文件 (base) root@instance:~/onethingai-tmp/test_dir_1# ls test.txt test1.txt test_dir (base) root@instance:~/onethingai-tmp/test_dir_1# cp -r test_dir test_dir_1 #拷贝目录 (base) root@instance:~/onethingai-tmp/test_dir_1# ls test.txt test1.txt test_dir test_dir_1
删除文件/目录
命令: rm
(base) root@instance:~/onethingai-tmp/test_dir_1# ls test.txt test1.txt test_dir test_dir_1
(base) root@instance:~/onethingai-tmp/test_dir_1# rm -f test1.txt #删除test1.txt, -f参数表示强制删除,不需要确认
(base) root@instance:~/onethingai-tmp/test_dir_1# ls test.txt test_dir test_dir_1
(base) root@instance:~/onethingai-tmp/test_dir_1# rm -fr test_dir_1 #删除目录
(base) root@instance:~/onethingai-tmp/test_dir_1# ls test.txt test_dir
重命名文件/目录
命令: mv
(base) root@instance:~/onethingai-tmp/test_dir_1# ls test.txt test_dir
(base) root@instance:~/onethingai-tmp/test_dir_1# mv test.txt test.txt.1 #将test.txt重命名为test.txt.1
(base) root@instance:~/onethingai-tmp/test_dir_1# ls test.txt.1 test_dir
打包/压缩/解压
linux 常用的打包,压缩/解压工具为 tar 和 zip。
tar压缩
tar -jcf <自定义打包的名称>.tar.gz <待打包目录的路径>
(base) root@instance:~/onethingai-tmp# ls test.txt test1.txt
(base) root@instance:~/onethingai-tmp# tar -jcf test.tar.gz test.txt test1.txt #压缩打包
(base) root@instance:~/onethingai-tmp# ls test.tar.gz test.txt test1.txt
tar解压
(base) root@instance:~/onethingai-tmp# ls test.tar.gz
(base) root@instance:~/onethingai-tmp# tar -xf test.tar.gz #解包
(base) root@instance:~/onethingai-tmp# ls test.tar.gz test.txt test1.txt
2,zip/unzip
plain (base) root@instance:~/onethingai-tmp# apt-get install zip
zip压缩
(base) root@instance:~/onethingai-tmp# ls test.txt test1.txt
(base) root@instance:~/onethingai-tmp# zip -r test.zip test.txt test1.txt #打包 adding: test.txt (deflated 18%) adding: test1.txt (deflated 18%)
zip解压
(base) root@instance:~/onethingai-tmp# ls test.zip
(base) root@instance:~/onethingai-tmp# unzip test.zip #解压 Archive: test.zip inflating: test.txt
inflating: test1.txt
查看进程以及内存占用情况
命令: top
(base) root@instance:~/onethingai-tmp# top
20:17:47 up 2:59, 0 users, load average: 0.00, 0.00, 0.00 Tasks: 10 total, 1 running, 9 sleeping, 0 stopped, 0 zombie %Cpu(s): 2.3 us, 1.3 sy, 0.0 ni, 96.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st MiB Mem : 2048.0 total, 1463.7 free, 264.5 used, 319.8 buff/cache MiB Swap: 0.0 total, 0.0 free, 0.0 used. 1783.5 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
9 root 20 0 726472 14848 11904 S 0.3 0.7 0:08.49 pan_client
10 root 20 0 737068 27864 16384 S 0.3 1.3 0:01.36 proxy
24 root 20 0 390108 87140 15488 S 0.3 4.2 0:02.33 python3
1 root 20 0 1136 640 640 S 0.0 0.0 0:00.16 init
7 root 20 0 34260 26276 9600 S 0.0 1.3 0:01.11 supervisord
8 root 20 0 712932 4864 3328 S 0.0 0.2 0:00.00 jupyter_monitor
11 root 20 0 712932 4864 3328 S 0.0 0.2 0:00.00 ssh_monitor
26 root 20 0 15436 8832 7296 S 0.0 0.4 0:00.00 sshd
129 root 20 0 5120 3968 3328 S 0.0 0.2 0:00.26 bash
10479 root 20 0 7712 3584 2944 R 0.0 0.2 0:00.00 top
查看进程情况
命令: ps
(base) root@instance:~/onethingai-tmp/test_dir_1# ps
PID TTY TIME CMD 129 pts/0 00:00:00 bash 10572 pts/0 00:00:00 ps
下载
命令: wget
(base) root@instance:~/onethingai-tmp/test_dir_1# wget http://example.com/file.zip