文件目录类
pwd
-
ls
ls -a :显示所有文件和目录,包括隐藏的
- ls -l :列表方式显示信息
-
cd
cd ~ :回到家目录
- cd .. :回到上一级目录
- cd / :回到根目录
-
mkdir
mkdir /home/zhangsan:只能创建一级目录
mkdir -p /home/person/xiaohong:创建多级目录
rmdir
只能删除一个空目录
-
rm
-r 递归删除
- -f 强制删除不提示
- rm 文件:删除文件
-
touch
touch a.txt:创建一个文件
-
cp
-r递归复制整个文件夹
- cp -r src dest
-
mv
剪切/重命名文件/目录
- 改名:mv a.txt b.txt
-
cat
默认打开所有的内容,只是浏览,不会修改文件
- cat 文件:查看文件
- cat -n 文件:查看文件并显示行号
cat -n a.txt | more:分页显示,空格Enter等控制
more
全屏方式显示文本
more a.txt:分页显示
显示大型文件较好,不是一次性加载整个文件,一页页的加载
less 文件
:输出重定向,覆盖原文件
:追加,原文件尾部追加
- 文件不存在就创建
ls -l > a.txt ls -l >> a.txt cat a.txt > c.txt echo “aaa” > a.txt
echo
echo $PATH:环境变量
[root@hadoop1 zsf]# echo aaaa[root@hadoop1 zsf]# echo "aa"aa[root@hadoop1 zsf]# echo 'aa'aa[root@hadoop1 zsf]# echo $PATH/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
head
显示文件前几行,默认显示前10行
- -n 10:自定义显示几行
head 文件 head -n 10 文件
tail
- 显示文件尾部的内容
tail 文件 tail -n 10 文件 tail -f 文件:实时追踪该文档的更新
ln
- 软连接指令,类似Windows快捷方式
- pwd查看软连接,看到的时软连接的本身目录
- ln -s 要跳转的目录 快捷方式 ``` [root@hadoop1 home]# ls ff.txt zsf zwj [root@hadoop1 home]# ln -s /root linkRoot [root@hadoop1 home]# ls ff.txt linkRoot zsf zwj [root@hadoop1 home]# cd linkRoot/ [root@hadoop1 linkRoot]# pwd /home/linkRoot [root@hadoop1 linkRoot]# cd /home/ [root@hadoop1 home]# ls -l 总用量 12 -rw-r—r—. 1 root root 15 1月 7 13:56 ff.txt lrwxrwxrwx. 1 root root 5 1月 7 14:00 linkRoot -> /root drwx———. 7 506 wudong 4096 1月 7 13:28 zsf drwx———. 4 505 wudong 4096 1月 6 14:00 zwj
- 删除软连接,不能带反斜杠
> rm -rf linkRoot
<a name="foEKn"></a>
#### history
- 查看历史指令
- 查看所有的历史指令:histoty
- 查看指定数目的历史指令:histoty 10
- 执行特定历史指令:!142
> [root@hadoop1 ~]# history 10
> 140 ls -l
> 141 rm -rf linkRoot
> 142 ls
> 143 cd /roo
> 144 cd /root/
> 145 ls
> 146 clear
> 147 history
> 148 histoty 10
> 149 history 10
> [root@hadoop1 ~]# !142
> ls
> anaconda-ks.cfg install.log install.log.syslog temp 公共的 模板 视频 图片 文档 下载 音乐 桌面
> [root@hadoop1 ~]#
<a name="fbOeO"></a>
### 时间日期
<a name="4qNni"></a>
#### date
- 输出日期
[root@hadoop1 ~]# date “+%Y %m %d %H:%M:%S” 2021 01 07 14:56:35 [root@hadoop1 ~]# date 2021年 01月 07日 星期四 14:57:24 CST
- 设置时间
> [root@hadoop1 ~]# date -s "2021-01-07 13:00:00"
> 2021年 01月 07日 星期四 13:00:00 CST
<a name="d1zOX"></a>
#### cal
- 查看当前月的日历:cal
- 查看某年的日历:cal 2020
<a name="BFtnj"></a>
### 搜索查找
<a name="cgbxU"></a>
#### find
- -name
- -user
- -size
> 指定目录查找指定文件名:find /home -name ff.txt
> 指定目录查找s属于指定用户的文件:find /home -user root
> 查找目录下大于20M的文件:find /home -size +20M
> 查找目录下小于20k的文件:find /home -size -20k
> 查找目录下等于20M的文件:find /home -size 20M
> 查找目录下以.txt结尾的文件:find /home -name *.txt
<a name="eSBD8"></a>
#### locate
- 无须遍历整个文件系统,直接从locate数据库查询,但是使用前需要更新locate数据库
> [root@hadoop1 /]# updatedb
> [root@hadoop1 /]# locate ff.txt
> /home/ff.txt
<a name="zQCIY"></a>
#### | grep
- |:管道符号,将前面一个命令的结果传递给后面的命令处理
- grep:过滤查找
- -n 匹配行号
- -i 忽然大小写
> cat a.txt | grep yes
> cat a.txt | grep -n yes
> cat a.txt | grep -ni yes
<a name="U34xK"></a>
### 压缩解压缩
<a name="NeIYM"></a>
#### gzip/gunzip
- 压缩/解压之后,原文件会消失
> gzip a.txt
> gunzip a.txt.gz
<a name="aeVKd"></a>
#### zip/unzip
- zip
- -r 递归压缩
- unzip
- -d指定解压到那个目录
> 压缩整个home目录:zip -r mypackage.zip /home/
> 解压到root目录下:unzip -d /root mypackage.zip
<a name="cEMb0"></a>
#### tar
- -z:打包同时压缩
- -c:产生tar打包文件
- -x:解压tar.gz文件
- -v:显示详细信息
- -f:指定压缩后的文件名
- 压缩
> [root@hadoop1 home]# ls
> a.txt b.txt mypackage.zip zsf zwj
> [root@hadoop1 home]#
> [root@hadoop1 home]# tar -zcvf ab.tar.gz a.txt b.txt
> a.txt
> b.txt
> [root@hadoop1 home]# ls
> ab.tar.gz a.txt b.txt mypackage.zip zsf zwj
- 打包整个目录
> tar -zcvf home.tar.gz /home
- 解压
> 解压到当前目录:tar -zxvf ab.tar.gz
> 解压到指定目录:tar -zxvf ab.tar.gz -C /opt/tmp
<a name="tEaWk"></a>
### ar
- ar主要用来集合多文件,打包成库文件
> ar命令可以用来创建、修改库,也可以从库中提出单个模块。库是一单独的文件,里面包含了按照特定的结构组织起来的其它的一些文件(称做此库文件的member)。原始文件的内容、模式、时间戳、属主、组等属性都保留在库文件中。
> ar可集合许多文件,成为单一的备存文件。在备存文件中,所有成员文件皆保有原来的属性与权限。
- 各参数含义
```java
root@ubuntu:/home/wangchun/demo# ls
hello hello.c makefile world world.c
# 将hello world这两个文件打包成hw.a
root@ubuntu:/home/wangchun/demo# ar rcs hw.a hello world
root@ubuntu:/home/wangchun/demo# ls
hello hello.c hw.a makefile world world.c
# 查询这个库文件中有哪些文件
root@ubuntu:/home/wangchun/demo# ar tv hw.a
rwxr-xr-x 0/0 8519 Feb 20 09:31 2021 hello
rwxr-xr-x 0/0 8519 Feb 20 09:31 2021 world
root@ubuntu:/home/wangchun/demo#
