- top 查看进程信息
输入top,可查看系统所有进程信息,包括CPU使用率、内存占用率等,类似Windows系统的任务管理器。
输入Shift+P可按CPU使用率排序,输入Shift+M可按内存占用率排序,输入q可退出该界面。 - df 查看磁盘空间
输入df,可查看文件系统的磁盘空间占用情况,常见命令参数如下:
-a, --all include dummy file systems
-B, --block-size=SIZE use SIZE-byte blocks
–direct show statistics for a file instead of mount point
–total produce a grand total
-h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)
-H, --si likewise, but use powers of 1000 not 1024
-i, --inodes list inode information instead of block usage
-k like --block-size=1K
-l, --local limit listing to local file systems
–no-sync do not invoke sync before getting usage info (default)
-P, --portability use the POSIX output format
–sync invoke sync before getting usage info
-t, --type=TYPE limit listing to file systems of type TYPE
-T, --print-type print file system type
-x, --exclude-type=TYPE limit listing to file systems not of type TYPE
-v (ignored)
常用命令如下:
df -ha 显示所有磁盘空间占用情况;
df -i 以inode模式显示磁盘使用情况;
df -ht ext4 显示指定类型磁盘;
df -h 列出文件系统的类型。 - du 查看文件大小
输入du -sh,可以查看文件及文件夹的大小, -h输出文件系统分区使用的情况,例如10KB,10MB,10GB等,-s显示文件或整个目录的大小,默认单位是KB。
du -sh /xxx/xxx 显示文件夹大小,但不会列出路径下每一个文件的大小;
du -sh /xxx/* 列出xxx下每个文件夹和文件的大小;
du -h --max-depth=1 /xxx/xxx 查找占用空间最大的文件与目录,-depth=1代表展示选择路径的目录级别。 - rm 删除文件
输入rm -rf /xxx/xxx,可删除选择目录以及其下所有文件和文件夹。
-r 向下递归,不管有多少级目录,一并删除;
-f 直接强行删除,不作任何提示;
-i 交互模式,在删除前询问用户是否操作。
rm -rf /xxx/xxx/*,可删除选择目录下的所有文件和文件夹。 - cp 复制文件
输入cp [option] source target,可进行文件复制。
选项参数:
-a 是指archive的意思,也说是指复制所有的目录;
-d 若源文件为连接文件(link file),则复制连接文件属性而非文件本身;
-f 强制(force),若有重复或其它疑问时,不会询问用户,而强制复制;
-i 若目标文件(destination)已存在,在覆盖时会先询问是否真的操作;
-l 建立硬连接(hard link)的连接文件,而非复制文件本身;
-p 与文件的属性一起复制,而非使用默认属性;
-r 递归复制,用于目录的复制操作;
-s 复制成符号连接文件(symbolic link),即“快捷方式”文件;
-u 若目标文件比源文件旧,更新目标文件。
示例:
cp -rf /home/user1/* /root/temp/ 将/home/user1目录下的所有东西拷到/root/temp/下而不拷贝user1目录本身。
cp /test1/file1 /test3/file2 将/test1目录下的file1复制到/test3目录,并将文件名改为file2。 - mv 移动文件
输入mv [option] source target,可进行文件移动(剪切)。
参数说明:
-f force,强制直接移动而不询问;
-i 若目标文件(destination)已经存在,就会询问是否覆盖;
-u 若目标文件已经存在,且源文件比较新,才会更新。
mv ./WorkReport/web.xml ./WorkReport/WEB-INF/ 移动/WorkReport/web.xml文件到/WorkReport/WEB-INF/;
mv /data/new /data/old/ 移动/data/new 到/data/old/文件夹下,源文件路径末尾就不加 / 了;
mv /data/new/* /data/old/ 如果是移动文件夹下的所有文件,源路径后面跟上 /*。 - 开启端口
输入iptables -I INPUT -p tcp --dport 8080 -j ACCEPT,开启防火墙8080端口之后,可通过网络远程连接该机的8080端口。
Linux常用指令(完善中)
最新推荐文章于 2024-07-06 23:03:02 发布