【文件目录类】
pwd :显示当前路径的绝对目录,[从最初的根目录开始]
[root@hadoop100 ~]# pwd
/root
cd:切换路径
绝对路径:cd /
[root@hadoop100 sysconfig]# cd /root/桌面/
[root@hadoop100 桌面]# pwd
/root/桌面
相对路径 cd ../
[root@hadoop100 桌面]# cd /root/视频/
[root@hadoop100 视频]# cd ../桌面/
[root@hadoop100 桌面]# cd /root
返回之前的文件 cd - [可以实现两个文件夹中的反复横跳]
[root@hadoop100 桌面]# cd -
/root
ls:列出目录的内容
选项 | 功能 |
-a | 全部的文件, 连同隐藏档( 开头为 . 的文件) 一起列出来(常用) |
-l | 长数据串列出, 包含文件的属性与权限等等数据; (常用)等价于“ll” |
[root@hadoop100 ~]# ls
anaconda-ks.cfg 公共 视频 文档 音乐
initial-setup-ks.cfg 模板 图片 下载 桌面
[root@hadoop100 ~]# ls -a
. .bashrc .ICEauthority .Xauthority 下载
.. .cache initial-setup-ks.cfg 公共 音乐
anaconda-ks.cfg .config .local 模板 桌面
.bash_history .cshrc .mozilla 视频
.bash_logout .dbus .tcshrc 图片
.bash_profile .esd_auth .viminfo 文档
[root@hadoop100 ~]# ls -l
总用量 8
-rw-------. 1 root root 1870 8月 20 16:02 anaconda-ks.cfg
-rw-r--r--. 1 root root 1901 8月 20 16:04 initial-setup-ks.cfg
drwxr-xr-x. 2 root root 6 8月 20 16:06 公共
drwxr-xr-x. 2 root root 6 8月 20 16:06 模板
drwxr-xr-x. 2 root root 6 8月 20 16:06 视频
drwxr-xr-x. 2 root root 6 8月 20 16:06 图片
drwxr-xr-x. 2 root root 6 8月 20 16:06 文档
drwxr-xr-x. 2 root root 6 8月 20 16:06 下载
drwxr-xr-x. 2 root root 6 8月 20 16:06 音乐
drwxr-xr-x. 2 root root 67 8月 20 21:17 桌面
mkdir :创建一个新的目录
[root@hadoop100 ~]# mkdir a
创建多级目录:mkdir -p
[root@hadoop100 ~]# mkdir -p g/h/i
rmdir:删除一个空的目录
[root@hadoop100 ~]# rmdir a
删除多级目录:rmdir -p [先删i,若删完i后的h为空,则自动删h,若删完h后的g为空,则自动删g]
[root@hadoop100 ~]# rmdir -p g/h/i
touch :创建空文件
[root@hadoop100 ~]# touch hello
[root@hadoop100 ~]# touch /home/jiandanchen/hello3
创建空文件也可以使用vim ,但若hello4为空就:q,则会创建失败,可用:wq
[root@hadoop100 ~]# vim hello4
cp: 复制文件或目录
cp [选项] source dest (source 源文件、dest 目标文件) |
[root@hadoop100 ~]# cp initial-setup-ks.cfg ../home/jiandanchen/
[root@hadoop100 ~]# ls /home/jiandanchen/
hello2 hello3 initial-setup-ks.cfg
若向目标文件中写入源文件,或者覆盖掉目标文件,则会出现提示符,若不想要提示符,则可以输入 [\cp]
[root@hadoop100 ~]# cp initial-setup-ks.cfg /home/jiandanchen/hello2
cp:是否覆盖"/home/jiandanchen/hello2"? y
[root@hadoop100 ~]# cp initial-setup-ks.cfg /home/jiandanchen/
cp:是否覆盖"/home/jiandanchen/initial-setup-ks.cfg"? y
cp -r 可递归复制整个文件夹
[root@hadoop100 ~]# cp -r a/ /home/jiandanchen/
rm :删除文件或目录
选项 | 功能 |
-r | 递归删除目录中所有内容 |
-f | 强制执行删除操作, 而不提示用于进行确认。 |
-v | 显示指令的详细执行过程 |
删除文件:
[root@hadoop100 ~]# rm hello
rm:是否删除普通空文件 "hello"?y
强制删除文件:
[root@hadoop100 ~]# rm -f hello4
删除文件夹:
[root@hadoop100 ~]# rm -r a
rm:是否进入目录"a"? y
rm:是否删除普通文件 "a/initial-setup-ks.cfg"?y
rm:是否删除目录 "a"?y
强制删除文件夹:
[root@hadoop100 jiandanchen]# rm -rf a/
强制删除当前目录下的所有文件:
[root@hadoop100 jiandanchen]# rm -f ./*
mv :移动文件与目录或重命名
(1) mv oldNameFile newNameFile | (功能描述: 重命名) |
(2) mv /temp/movefile /targetFolder | (功能描述: 移动文件) |
[root@hadoop100 ~]# mv initial-setup-ks.cfg /home/jiandanchen/
移动并重命名
[root@hadoop100 ~]# mv initial-setup-ks.cfg /home/jiandanchen/1.cfg
不移动只重命名
[root@hadoop100 ~]# mv initial-setup-ks.cfg 2.cfg
cat: 查看文件内容
cat [选项] 要查看的文件
选项 | 功能描述 |
-n | 显示所有行的行号, 包括空行。 |
more: 文件内容分屏查看器
more 要查看的文件
操作 | 功能说明 |
空白键 (space) | 代表向下翻一页; |
Enter | 代表向下翻『一行』; |
q | 代表立刻离开 more , 不再显示该文件内容。 |
Ctrl+F | 向下滚动一屏 |
Ctrl+B | 返回上一屏 |
= | 输出当前行的行号 |
:f | 输出文件名和当前行的行号 |
less: 分屏显示文件内容
less 要查看的文件
操作 | 功能说明 |
空白键 | 向下翻动一页; |
[pagedown] | 向下翻动一页 |
[pageup] | 向上翻动一页; |
/字串 | 向下搜寻『字串』 的功能; n: 向下查找; N: 向上查找; |
?字串 | 向上搜寻『字串』 的功能; n: 向上查找; N: 向下查找; |
q | 离开 less 这个程序; |
echo:输出内容到控制台
echo [选项] [输出内容]
选项:
-e: 支持反斜线控制的字符转换
控制字符 | 作用 |
\\ | 输出\本身 |
\n | 换行符 |
\t | 制表符, 也就是 Tab 键 |
[root@hadoop100 ~]# echo hello,world
hello,world
[root@hadoop100 ~]# echo hello world
hello world
[root@hadoop100 ~]# echo hello word
hello word
[root@hadoop100 ~]# echo "hello word"
hello word
[root@hadoop100 ~]# echo "hello \ world"
hello \ world
[root@hadoop100 ~]# echo "hello \n world"
hello \n world
[root@hadoop100 ~]# echo -e "hello \nworld"
hello
world
echo也可以将信息追加到文件末尾
[root@hadoop100 ~]# echo "hello,linux">>info
head :显示文件头部内容
head 文件 head -n 5 文件 | (功能描述: 查看文件头10行内容) (功能描述: 查看文件头5行内容, 5可以是任意行数) |
选项 | 功能 |
-n <行数> | 指定显示头部内容的行数 |
tail: 输出文件尾部内容
tail 用于输出文件中尾部的内容, 默认情况下 tail 指令显示文件的后 10 行内容。
(1) tail 文件 (功能描述: 查看文件尾部10行内容)
(2) tail -n 5 文件 (功能描述: 查看文件尾部5行内容, 5可以是任意行数)
(3) tail -f 文件 (功能描述: 实时追踪该文档的所有更新)
选项 | 功能 |
-n<行数> | 输出文件尾部 n 行内容 |
-f | 显示文件最新追加的内容, 监视文件变化 |
注意:tail -f 可以监视到echo追加的内容,但是如果用vim追加内容则无法监视到,因为tail -f实质监视的文件的编号,当vim完后,文件的编号会发生改变。
ctrl + s可以暂停 tail -f的监视,但在暂停期间,实际上内部还是会记录变化的。按ctrl+q恢复监视。
In : 软连接
ln -s [原文件或目录] [软链接名] | (功能描述: 给原文件创建一个软链接) |
删除软链接: rm -rf 软链接名, 而不是 rm -rf 软链接名/
如果使用 rm -rf 软链接名/ 删除, 会把软链接对应的真实目录下内容删掉
在创建的软连接中增改,原文件也会直接发生变化。
[root@hadoop100 jiandanchen]# ln -s /root/info myInfo
软连接一个目录
[root@hadoop100 jiandanchen]# ln -s /root/folder/ /home/jiandanchen/myFolder
history : 查看已经执行过历史命令
history
清空历史命令
history -c
查看最近10条历史命令
!数字,表示查看该编号的历史命令
[root@hadoop100 jiandanchen]# history 10
141 rm folder
142 rm -rf folder
143 ls
144 cd -
145 cd /home/jiandanchen/
146 ls
147 rm -rf myFolder
148 ls
149 history
150 history 10
[root@hadoop100 jiandanchen]# !148
ls