一、环境变量

1.环境变量PATH的作用:将一些常用目录放入PATH中,我们使用时就不用输入绝对路径,方便使用。

[root@localhost ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin

2.例如 ls,是在bin目录下,而bin目录又在PATH中,所以我们可以在任何地方使用ls.

[root@localhost ~]# which ls
alias ls='ls --color=auto'
/usr/bin/ls

[root@localhost ~]# cd /opt/
[root@localhost opt]# ls
rh

3.也可以手动添加目录到PATH。

[root@localhost ~]# PATH=$PATH:/home
[root@localhost ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/home:/home

 

二、cp  命令

1. cp 用来复制目录或文件。 -r 只有加它才能复制目录,不加只能复制文件。

[root@localhost dir]# ls
11 1.txt 22 2.txt
[root@localhost dir]# echo 123 > 1.txt
[root@localhost dir]# cp 1.txt 2.txt 

[root@localhost dir]# cat 2.txt 

123

[root@localhost dir]# cp 11 22

cp: 略过目录"11"

[root@localhost dir]# cp -r 11 22
[root@localhost dir]#

2. -i  询问提示

[root@localhost dir]# cp -i 1.txt 2.txt
cp:是否覆盖"2.txt"? y

三、mv 命令

1.移动,当文件和目录都存在的时候,会移动到该目录下,或文件中。

[root@localhost dir]# ls
1.txt 2.txt 3.txt a b c
[root@localhost dir]# mv a c
[root@localhost dir]# ls
1.txt 2.txt 3.txt b c
[root@localhost dir]# cd c
[root@localhost c]# ls
a

[root@localhost dir]# ls
1.txt 2.txt 3.txt b c
[root@localhost dir]# echo 11 > 1.txt
[root@localhost dir]# mv 1.txt 3.txt
[root@localhost dir]# cat 3.txt
11

2.重命名,当文件或目录不存在的时候,相当于重命名。

[root@localhost dir]# ls
2.txt 3.txt b c
[root@localhost dir]# mv b d
[root@localhost dir]# ls
2.txt 3.txt c d
[root@localhost dir]# mv 2.txt 4.txt
[root@localhost dir]# ls
3.txt 4.txt c d

四、cat 与 tac

1. 两者的作用是查看文件。 cat   -n 显示行号。-A 显示所有内容,包括特殊字符。

[root@localhost ~]# cat -n 1.txt
1 1111111111
2 2222222222
3 3333333333

[root@localhost ~]# cat -n -A 1.txt
1 1111111111$
2 2222222222$
3 3333333333$

2.tac 从最后一行开始显示, - n 不能使用。

[root@localhost ~]# tac 1.txt
3333333333
2222222222
1111111111

[root@localhost ~]# tac -n 1.txt
tac:无效选项 -- n
Try 'tac --help' for more information.

五、more 与less

1.more  文件名,查看文件内容,当内容太多事,more 可以上下翻屏,Ctrl + D  向上  Ctrl + F 向下 空格继续向下,q 键退出。

ts_state: ud
output_state: 90
isDep: False
reason: user
reinstall: False
relatedto: NetworkManager-ppp,x86_64,1,1.8.0,11.el7_4@a:updatedby
updated_by: NetworkManager-ppp,x86_64,1,1.8.0,11.el7_4@a
--More--(4%)

2.less 同more一样,功能多一点,可搜索字符串。方向上下键移动上下。 支持 /xx 搜索字符xx,搜索时 N 向上查找,n 向下查找。

updates: java-1.8.0-openjdk,x86_64,1,1.8.0.131,11.b12.el7@i
mbr: python-sss-murmur,x86_64,0,1.15.2,50.el7_4.8 70
repo: updates
/mbr

六、head 与 tail

1.head 显示文件前10行, head 文件名  -n 数字  指定想看前多少行

[root@localhost ~]# head my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

只显示前3行,有无空格和 n 都行

[root@localhost ~]# head -n 3 my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

[root@localhost ~]# head -3 my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
[root@localhost ~]# head -n3 my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

tail 显示文件末尾10行,tail 文件名  -n 数字  指定想看末尾多少行

[root@localhost ~]# tail my.cnf

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

[root@localhost ~]# tail -n 5 my.cnf
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
122312231223122312231223122312231223122312231223

[root@localhost ~]# tail -5 my.cnf
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
122312231223122312231223122312231223122312231223
[root@localhost ~]# tail -n5 my.cnf
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
122312231223122312231223122312231223122312231223

 

posted on 2017-12-20 01:21  天梭  阅读(129)  评论(0编辑  收藏  举报