Linux的从零开始(第三天)

移动文件或者重命名

mv move (rename) files     移动/重命名 文件 相当于windows中的ctrl+x ctrl+v

mv b.txt spring //移动b.txt 文件到 目录中

mv a.txt aaa.txt 把a.txt重命名为aaa.txt aaa.txt目录不存在

mv frames/ frameset 把目录frames重命名为frameset

删除空目录

rmdir      remove empty directories 删除空目录
rmdir mybatis/       直接删除空目录mybatis  不能删除非空目录
rmdir bb cc dd 删除多个空目录

删除文件

rm         remove files or directorie 删除文件或目录

选项:
-r recursive 递归的 remove directories and their contents recursively
递归删除目录及目录下所有内容
-f force 强制的 ignore nonexistent files and arguments, never prompt
不带提示信息,直接删除  
rm 中文.txt //删除 中文.txt 有提示信息 需要确认是否删除 y/n
rm -f aaa.txt //直接删除aaa.txt不带提示
rm -rf bb 不带提示递归删除目录bb 及其下的所有内容
文件统计
wc               (word count) print newline, word, and byte counts for each file 打印每个文件行 数,单词数和字节数
选项:
-l print the newline counts 打印行数
-c print the byte counts 打印字节数
-m print the character counts 打印字符数(utf-8时一个中文1个字符 3个字节)
-w print the word counts 打印单词数
查找文件或者目录
find           search for files in a directory hierarchy 按照目录层次查询文件
find /etc -name '*audit*' 查找/etc下 所有名称含有audit的文件或者目录
find /etc -name '*t*' | wc -l         | 管道符 连接多个命令的 通常后一个命令把前一个命令的执行结果作为参数
筛选文件内容
grep            (global regular expression print) print lines matching a pattern全局按照正则表达式查找匹配内容,并把查找结果打印到标准数据
grep 22: tomcat.log 查找含有22:的所有行,并打印
find /etc -name '*t*' | grep pos | wc -l 从find的查找结果查找含有pos的行并打印,并统计行数
创建快捷方式(创建软硬连接)
ln          make links between files 在文件之间创建连接
选项:
-s make symbolic links instead of hard links 为文件或者目录创建象征性的连
接 软连接 (相当于windows下的快捷方式)
-d allow the superuser to attempt to hard link directories
硬接连 给源文件创建一个副本文件,当原文件删除,对副本文件没有任何影响
ln -s /tmp/aaa/ aaa.lnk 为/tmp下aaa目录创建软连接到当前用户主目录下
ln -d a.log a.log.lnk 为a.log创建硬连接a.log.lnk
压缩解压文件
gzip:(不能压缩目录)         compress or expand files
选项:
-d Decompress 解压缩
gzip tomcat.log 压缩tomcat.log文件 产生一个tomcat.log.gz 源文件消失
gzip -d tomcat.log.gz 解压 压缩包消失,源文件出现
bzip2:(不能压缩目录)
最小化安装,只安装了gzip 没有安装bzip2
yum -y install bzip2 自动分析依赖,在线安装软件bzip2
选项:
-d decompress 解压缩
bzip2 tomcat.log 压缩tomcat.log 产生tomcat.log.bz2 源文件消失
bzip2 -d tomcat.log.bz2 解压 压缩包消失 源文件出现
这两个命令都无法直接对目录进行压缩
压缩解压目录/文件 查看压缩包
tar               GNU `tar' saves many files together into a single tape or disk archive, and can restore individual files from the archive
把许多文件保存到一起到一个单独磁带或者磁盘档案上,可以从档案中恢复文件和windows下的压缩解压是一个意思
选项:
-c   create 创建 create a new archive 创建压缩
-t list 列表 list the contents of an archive 查看压缩包
-x extract 提取 extract files from an archive 从压缩包提取文件 解压缩
上面3个选项中 都不可以共同使用
-z    gzip filter the archive through gzip 通过gzip方式进行过滤(压缩,查看压缩包,解压)
-j     bzip2 filter the archive through bzip2 通过bzip2方式进行过滤(压缩,查看压缩包,解压)
上面2个选项不能共同使用(不能压缩,查看或者解压过程中换方式)
-v verbose verbosely list files processed 显示文件详情 可选的,不要也可以
-f file use archive file or device ARCHIVE 文档名称
-C change to directory DIR 改变目录 指定解压文件位置
tar -czvf frameset.tar.gz frameset/ 压缩文件夹frameset,压缩之后的名称为frameset.tar.gz 因为带了v 所以会显示压缩过程
tar -czf frameset.tar.gz frameset 依然压缩,不再显示详细信息
tar -tzvf frameset.tar.gz 查看压缩包(带v显示详情)
tar -xzvf frameset.tar.gz 解压 没有-C 默认解压到当前目录
tar -xzvf frameset.tar.gz -C /tmp/ 解压到指定目录
角色,权限和命令:
第1位:文件类型(d 目录,- 普通文件,l 链接文件)
“-”表示普通文件;
“d”表示目录;
“l”表示链接文件;
“p”表示管理文件;
“b”表示块设备文件;
“c”表示字符设备文件;
“s”表示套接字文件;
第2-4位:所属用户权限,用u(user)表示
第5-7位:所属组权限,用g(group)表示
第8-10位:其他用户权限,用o(other)表示
第2-10位:表示所有的权限,用a( all)表示
三种基本权限:
r 读权限(read)
w 写权限(write)
x 执行权限 (execute)
chmod             修改文件权限命令(change mode)
参数:-R 下面的文件和子目录做相同权限操作(Recursive递归的)
用数字来表示权限(r=4,w=2,x=1,-=0)
例如:chmod 750 b.txt
rwx用二进制表示是111,十进制4+2+1=7
r-x用二进制表示是101,十进制4+0+1=5
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值