这是我参与更文挑战的第6天,活动详情查看:更文挑战
1.vi/vim
1.1 是什么
VI是Unix操作系统和类Unix操作系统中最通用的文本编辑器。
VIM编辑器是从VI发展出来的一个性能更强大的文本编辑器。可以主动的以字体颜色辨别语法的正确性,方便程序设计。VIM与VI编辑器完全兼容。
1.2 一般模式
以vi/vim打开一个档案就直接进入一般模式了(这是默认的模式)
常用语法
语法
功能描述
yy
复制光标当前一行
y数字y
复制一段(从第几行到第几行)
p
箭头移动到目的行粘贴
u
撤销上一步
dd
删除光标当前行
d数字d
删除光标(含)后多少行
x
剪切一个字母,相当于del
X
剪切一个字母,相当于Backspace
yw
复制一个词
dw
删除一个词
^
移动到行头
$
移动到行尾
1+shift+g
移动到页头,数字
shift+g
移动到页尾
数字+shift+g
移动到目标行
1.3 编辑模式
常用语法
按键
功能
i
当前光标前
a
当前光标后
o
当前光标行的下一行
I
光标所在行最前
A
光标所在行最后
O
当前光标行的上一行
1.4 指令模式
常用语法
命令
功能
:w
保存
:q
退出
:!
强制执行
/要查找的词
n 查找下一个,N 往上查找
:noh
取消高亮显示
:set nu
显示行号
:set nonu
关闭行号
:%s/old/new/g
替换内容 /g 替换匹配到的所有内容
2.帮助命令
2.1 man
基本语法
man [命令或配置文件] (功能描述:获得帮助信息)
显示说明
信息
功能
NAME
命令的名称和单行描述
SYNOPSIS
怎样使用命令
DESCRIPTION
命令功能的深入讨论
EXAMPLES
怎样使用命令的例子
SEE ALSO
相关主题(通常是手册页)
2.2 help
基本语法
help 命令 (功能描述:获得shell内置命令的帮助信息)
2.3 type
基本语法
type 命令 (功能描述:获得shell命令的类型)
[xxxx@hadoop1 ~]$ type cd
cd 是 shell 内 //说明是内嵌命令
[xxxx@hadoop1 ~]$ type ls
ls 是 `ls --color=auto' 的别
复制代码
3.文件目录类
3.1 pwd
基本语法
pwd (功能描述:显示当前工作目录的绝对路径)
[root@hadoop1 opt]# pwd
/opt
复制代码
3.2 ls
基本语法
ls [选项] [目录或是文件]
选项说明
选项
功能
-a
全部的文件,连同隐藏档( 开头为 . 的文件) 一起列出来(常用)
-l
长数据串列出,包含文件的属性与权限等等数据;(常用)等价于“ll”
[root@hadoop1 ~]# ll
总用量 8
-rw-r--r-- 1 root root 2 11月 25 21:22 swappiness~
-rw-r--r-- 1 root root 2 11月 26 10:28 swappinesz~
[root@hadoop1 ~]# ls
swappiness~ swappinesz~
[root@hadoop1 ~]# ls -a
. .bash_logout .cshrc .mysql_history .ssh .tcshrc
.. .bash_profile .history .oracle_jre_usage swappiness~ .viminfo
.bash_history .bashrc .lesshst .pki swappinesz~
[root@hadoop1 ~]# ls -al
总用量 68
dr-xr-x---. 5 root root 4096 4月 7 18:28 .
dr-xr-xr-x. 20 root root 4096 4月 6 16:03 ..
-rw-r--r-- 1 root root 6775 4月 6 19:16 .bash_history
-rw-r--r--. 1 root root 18 12月 29 2013 .bash_logout
-rw-r--r--. 1 root root 176 12月 29 2013 .bash_profile
-rw-r--r--. 1 root root 176 12月 29 2013 .bashrc
-rw-r--r--. 1 root root 100 1
复制代码
3.3 cd
基本语法
cd [参数]
参数说明
参数
功能
cd 绝对路径
切换路径
cd相对路径
切换路径
cd ~或者cd
回到自己的家目录
cd –
回到上一次所在目录
cd ..
回到当前目录的上一级目录
cd -P
跳转到实际物理路径,而非快捷方式路径
[root@hadoop1 opt]# cd /root/
[root@hadoop1 ~]# cd -
/opt
[root@hadoop1 opt]# cd ../
[root@hadoop1 /]# cd /root/
[root@hadoop1 ~]# cd ~
[root@hadoop1 ~]# cd ../
[root@hadoop1 /]# cd
复制代码
3.4 mkdir
基本语法
mkdir [选项] 要创建的目录
选项说明
选项
功能
-p
创建多层目录
[xxxxx@hadoop1 test]$ mkdir qqq
[xxxxx@hadoop1 test]$ mkdir -p qqq/www/eeee
复制代码
3.5 rmdir
基本语法
rmdir 要删除的空目录
[root@hadoop1 www]$ rmdir eeee
复制代码
3.6 touch
基本语法
touch 文件名称
[root@hadoop1 qqq]$ touch 1.txt
[root@hadoop1 qqq]$ touch ./www/1.txt
复制代码
3.7 cp
基本语法
cp [选项] source dest (功能描述:复制source文件到dest)
选项说明
选项
功能
-r
递归复制整个文件夹
[root@hadoop1 test]# cp a.txt ./aaa
[root@hadoop1 test]# cp -r aaa aaaa
复制代码
3.8 rm
基本语法
rm [选项] deleteFile (功能描述:递归删除目录中所有内容)
选项说明
选项
功能
-r
递归删除目录中所有内容
-f
强制执行删除操作,而不提示用于进行确认。
-v
显示指令的详细执行过程
[root@hadoop1 test]# rm a.txt
rm:是否删除普通文件 "a.txt"?yes
[root@hadoop1 test]# rm -f b.txt
[root@hadoop1 test]# rm -rf aaaa/
复制代码
3.9 mv
基本语法
mv oldFile newFile (功能描述:重命名)
mv ./aaa/ bbb/ (功能描述:移动文件夹)
mv a.txt aaa/a.txt (功能描述:移动文件)
[root@hadoop1 aaa]# mv a.txt b.txt
[root@hadoop1 aaa]# mv ./b/ ../
[root@hadoop1 aaa]# mv b.txt ../
复制代码
3.10 cat
基本语法
cat [选项] 要查看的文件
选项说明
选项
功能描述
-n
显示所有行的行号,包括空行。
[root@hadoop1 test]# cat README.txt
For the latust information about Hadoop, please visit our website at:
http://hadoop.apache.org/core/
[root@hadoop1 test]# cat -n README.txt
1 For the latust information about Hadoop, please visit our website at:
2
3 http://hadoop.apache.org/core/
复制代码
3.11 more
基本语法
more 要查看的文件
操作说明
操作
功能说明
空白键 (space)
代表向下翻一页;
Enter
代表向下翻『一行』;
q
代表立刻离开 more ,不再显示该文件内容。
Ctrl+F
向下滚动一屏
Ctrl+B
返回上一屏
=
输出当前行的行号
:f
输出文件名和当前行的行号
[root@hadoop1 test]# more README.txt
复制代码
3.12 less
基本语法
less 要查看的文件
操作说明
操作
功能说明
空白键
向下翻动一页;
[pagedown]
向下翻动一页
[pageup]
向上翻动一页;
/字串
向下搜寻『字串』的功能;n:向下查找;N:向上查找;
?字串
向上搜寻『字串』的功能;n:向上查找;N:向下查找;
q
离开 less 这个程序;
[root@hadoop1 test]# less README.txt
复制代码
3.13 echo
基本语法
echo [选项] [输出内容]
选项:
-e: 支持反斜线控制的字符转换
控制字符
作用
\\
输出\本身
\n
换行符
\t
制表符,也就是Tab键
[root@hadoop1 test]# echo 666
666
[root@hadoop1 test]# echo "4444"
4444
[root@hadoop1 test]# echo -e "666\t666"
666 666
[root@hadoop1 test]# echo -e "\033[34m 蓝色字 \033[0m"
蓝色字
复制代码
扩展 带颜色输出:
echo -e “\033[字背景颜色;文字颜色m 字符串 \033[0m” 同时添加字背景颜色和文字颜色
echo -e “\033[文字颜色m 字符串 \033[0m” 仅添加文字颜色
字体颜色
echo -e "\033[30m 黑色字 \033[0m"
echo -e "\033[31m 红色字 \033[0m"
echo -e "\033[32m 绿色字 \033[0m"
echo -e "\033[33m 黄色字 \033[0m"
echo -e "\033[34m 蓝色字 \033[0m"
echo -e "\033[35m 紫色字 \033[0m"
echo -e "\033[36m 天蓝字 \033[0m"
echo -e "\033[37m 白色字 \033[0m"
复制代码
字背景颜色
echo -e "\033[40;37m 黑底白字 \033[0m"
echo -e "\033[41;37m 红底白字 \033[0m"
echo -e "\033[42;37m 绿底白字 \033[0m"
echo -e "\033[43;37m 黄底白字 \033[0m"
echo -e "\033[44;37m 蓝底白字 \033[0m"
echo -e "\033[45;37m 紫底白字 \033[0m"
echo -e "\033[46;37m 天蓝底白字 \033[0m"
echo -e "\033[47;30m 白底黑字 \033[0m"
复制代码
最后面控制选项说明
\33[0m 关闭所有属性
\33[1m 设置高亮度
\33[4m 下划线
\33[5m 闪烁
\33[7m 反显
\33[8m 消隐
\33[30m — \33[37m 设置前景色
\33[40m — \33[47m 设置背景色
\33[nA 光标上移n行
\33[nB 光标下移n行
\33[nC 光标右移n行
\33[nD 光标左移n行
\33[y;xH设置光标位置
\33[2J 清屏
\33[K 清除从光标到行尾的内容
\33[s 保存光标位置
\33[u 恢复光标位置
\33[?25l 隐藏光标
\33[?25h 显示光标
复制代码
3.14 head
基本语法
head 文件 (功能描述:查看文件头10行内容)
head -n 5 文件 (功能描述:查看文件头5行内容,5可以是任意行数)
2)选项说明
选项
功能
-n<行数>
指定显示头部内容的行数
[root@hadoop1 test]# head README.txt
For the latust information about Hadoop, please visit our website at:
http://hadoop.apache.org/core/
http://wiki.apache.org/hadoop/
and our wiki, at:
ribution
[root@hadoop1 test]# head -n 1 README.txt
For the latust information about Hadoop, please visit our website at:
复制代码
3.15 tail
基本语法
(1)tail 文件 (功能描述:查看文件尾部10行内容)
(2)tail -n 5 文件 (功能描述:查看文件尾部5行内容,5可以是任意行数)
(3)tail -f 文件 (功能描述:实时追踪该文档的所有更新)
(4)tail -5f 文件 或者 tail -fn 5 文件 (功能描述:查看文件尾部5行内容,5可以是任意行数 并且 实时追踪该文档的所有更新)
2) 选项说明
选项
功能
-n<行数>
输出文件尾部n行内容
-f
显示文件最新追加的内容,监视文件变化
[root@hadoop1 test]# tail README.txt
The following providus more details on the included cryptographic
software:
Hadoop usus usus the SSL librarius from the Jetty project written
by mortbay.org.
[root@hadoop1 test]# tail -n 1 README.txt
by mortbay.org.
[root@hadoop1 test]# tail -fn 2 README.txt
Hadoop usus usus the SSL librarius from the Jetty project written
by mortbay.org.
^C
[root@hadoop1 test]# tail -2f README.txt
Hadoop usus usus the SSL librarius from the Jetty project written
by mortbay.org.
^C
复制代码
3.16 > 和 >>
基本语法
(1)ls -l > 文件 (功能描述:列表的内容写入文件a.txt中(覆盖写))
(2)ls -al >> 文件 (功能描述:列表的内容追加到文件aa.txt的末尾)
(3)cat 文件1 > 文件2 (功能描述:将文件1的内容覆盖到文件2)
(4)echo “内容” >> 文件
[root@hadoop1 test]# ls -l > b.txt
[root@hadoop1 test]# ls -l >> b.txt
[root@hadoop1 test]# cat README.txt >> b.txt
[root@hadoop1 test]# echo "66666" >> b.txt
复制代码
3.17 ln
基本语法
ln -s [原文件或目录] [软链接名] (功能描述:给原文件创建一个软链接)
经验
删除软链接: rm -rf 软链接名,而不是rm -rf 软链接名/
如果使用 rm -rf 软链接名/ 删除,会把软链接对应的真实目录下内容删掉
查询:通过ll就可以查看,列表属性第1位是l,尾部会有位置指向。
[root@hadoop1 test]# rm -rf a.txtln
[root@hadoop1 test]# ln -s aaa aaa.ln
[root@hadoop1 test]# ll
总用量 36
drwxrw-rw- 2 root root 4096 4月 8 09:32 aaa
lrwxrwxrwx 1 root root 3 4月 8 10:13 aaa.ln -> aaa
复制代码
3.18 history
基本语法
history (功能描述:查看已经执行过历史命令)
[root@hadoop1 test]# history
1 2020-11-21 14:20:05 root hostname
复制代码