路径/文件操作
移动/拷贝文件/文件夹
移动某个文件到指定路径:
1
mv path/to/file destDir
移动某路径下的所有文件(不包括隐藏文件)到指定路径:
1
mv path/* destDir
如果要移动包括隐藏文件在内的所有文件到指定路径,要使用正则表达式:
1
mv path/.[^.]* destDir
含义为匹配以
.
开头,第二个字符不是.
的所有文件,避免匹配到上级目录../
。拷贝整个文件夹
1
cp -r folder/path destDir
-r
的含义是递归地复制到目标路径;
修改权限
修改文件夹即所有子文件、文件夹权限
1
chmod -R 755 folder/path
修改单个文件权限
1
chmod 755 path/to/file
修改文件夹下所有子文件夹拥有者
1
chown -R user_name folder/path
查看用户组
1
cat /etc/group
cat
命令用于用于一次显示整个文件
查找文件
列出所有后缀为
pth
的文件1
ll *.pth
删除文件/文件夹
删除文件
1
rm path/to/file
删除文件夹(空)
1
rmdir path/to/folder
解压文件
解压
zip
文件:1
unzip -d destDir file.zip
解压
tar
文件:1
tar -xvf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz
磁盘管理
磁盘状态
查看磁盘空间
1
df 以磁盘分区为单位查看文件系统,可以获取硬盘被占用了多少空间,目前还剩下多少空间等信息。例如,我们使用df -h命令来查看磁盘信息,-h选项为根据大小适当显示。
相关命令:
1
2
3
4
5df -hl:查看磁盘剩余空间
df -h:查看每个根路径的分区大小
du -sh [目录名]:返回该目录的大小
du -sm [文件夹]:返回该文件夹总M数
du -h [目录名]:查看指定文件夹下的所有文件大小(包含子文件夹)1
du 英文原义为 disk usage,含义为显示磁盘空间的使用情况,用于查看当前目录的总大小。
1
2
3
4
5
6
7
8
9
10du 命令用于查看当前目录的总大小:
-s:对每个Names参数只给出占用的数据块总数。
-a:递归地显示指定目录中各文件及子目录中各文件占用的数据块数。若既不指定-s,也不指定-a,则只显示Names中的每一个目录及其中的各子目录所占的磁盘块数。
-b:以字节为单位列出磁盘空间使用情况(系统默认以k字节为单位)。
-k:以1024字节为单位列出磁盘空间使用情况。
-c:最后再加上一个总计(系统默认设置)。
-l:计算所有的文件大小,对硬链接文件,则计算多次。
-x:跳过在不同文件系统上的目录不予统计。
-h:以K,M,G为单位,提高信息的可读性。
进程
查询端口占用
1
lsof -i:6006
结束进程
1
kill -9 PID