[root@aminglinux-01 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@hf-01 ~]# which ls 查看ls所在路径
alias ls='ls --color=auto'
/usr/bin/ls
[root@hf-01 ~]# ls /usr/bin/ls
/usr/bin/ls
[root@hf-01 ~]# cp /usr/bin/ls /tmp/ls2 复制/usr/bin/ls路径到/tmp/ls2下
[root@hf-01 ~]# /tmp/ls2 使用命令/tmp/ls2查看结果,会发现和ls命令出来的结果一样
anaconda-ks.cfg
[root@hf-01 ~]# ls
anaconda-ks.cfg
[root@ahf-01 ~]# ls2 执行ls2命令,会提示未找到命令,因为这个命令不在上述目录里面
-bash: ls2:未找到命令
[root@hf-01 ~]# PATH=$PATH:/tmp/ 若想直接运行ls2命令,需要改变环境变量 重新给PATH赋值
[root@hf-01 ~]# echo $PATH 会发现多出了/tmp/
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/tmp/
[root@hf-01 ~]# ls2 这时在运行发现就可以执行了
anaconda-ks.cfg
[root@hf-01 ~]# which ls2
/tmp/ls2
1.在系统 vi /etc/profile (在开机、打开终端都会加载这个命令)
2.结尾处加上PATH=$PATH:/tmp/ 并保存退出
3.在使用cat /etc/profile查看下是否加载成功
4.这时echo $PATH会得到/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/tmp/:/root/bin
现在不管哪一个终端都可以执行ls2命令,都会执行成功
若不想要这个ls2命令了,有两种方法。
cp = copy
将源文件 拷贝成目标文件
cp -r 拷贝目录
统一约定, 使用cp 和其他命令的时候,把 路径后的/补充完整
!$ 上一条命令中最后的一个参数,以空格或叹号分割
[root@hf-01 ~]# which cp
alias cp='cp -i'
/usr/bin/cp
这里会看到cp 命令默认带有一个 -i 选项,
它是属于安全选项,询问操作是否进行下一步操作
若不想复制的时候,每天去询问,可以按如下复制
[root@hf-01 ~]# /usr/bin/cp /etc/passwd /tmp/1.txt
[root@hf-01 ~]# cp /etc/passwd /tmp/1.txt 拷贝文件直接复制即可
cp:是否覆盖"/tmp/1.txt"? y
[root@hf-01 ~]# cp -r /tmp/aminglinux/ /tmp/amning 拷贝目录需要加-r选项
[root@hf-01 ~]# cp -r /tmp/aminglinux/ /tmp/aming1/
[root@hf-01 ~]# tree !$ 这表示上一条命令的最后一条参数
tree /tmp/aming1/
/tmp/aming1/
└── 2
└── 2.txt
1 directory, 1 file
[root@hf-01 ~]# !tree
tree /tmp/aming1/
/tmp/aming1/
└── 2
└── 2.txt
1 directory, 1 file
[root@hf-01 ~]# tree /tmp/aming1/
/tmp/aming1/
└── 2
└── 2.txt
1 directory, 1 file
[root@hf-01 ~]# cp -r /tmp/aminglinux/ /tmp/aming1/
[root@hf-01 ~]# ls /tmp/aming1/
2 aminglinux 这说明,当目标目录已经存在的时候,他会把源目录放在目标目录下面去,
如果目标目录不存在,他会把源目录拷贝过来,并修改名称
[root@hf-01 ~]# tree /tmp/aming1/
/tmp/aming1/
├── 2
│ └── 2.txt
└── aminglinux
└── 2
└── 2.txt
3 directories, 2 files
[root@hf-01 ~]# cp -r /tmp/aminglinux/ /tmp/aming1/
cp:是否覆盖"/tmp/aming1/aminglinux/2/2.txt"? n
当再次拷贝相同目录的时候,就会提示是否需要覆盖,这时因为源目录已经存在
在cp拷贝目录的时候,在目录后面统一加上/,因为在后面有一种命令中加/和不加/是有很大区别的
[root@hf-01 ~]# mv anaconda-ks.cfg anaconda-ks.cfg.1 这里就是直接修改文件名
[root@hf-01 ~]# ls
anaconda-ks.cfg.1
[root@hf-01 ~]# cd /tmp/
[root@hf-01 tmp]# ls
1.txt aming1 aminglinux amning mysql.sock
[root@hf-01 tmp]# mv aming1/ aming/
[root@hf-01 tmp]# ls
aming aminglinux amning mysql.sock
[root@hf-01 tmp]# mv aming/ aming2/ 若把目录移动到当前一个不存在的目录,则会修改名称
[root@hf-01 tmp]# ls
aming2 aminglinux amning mysql.sock
[root@hf-01 tmp]# mv aming2/ aminglinux/ 如果目标目录存在了,就会把源目录放到目标目录下面去
[root@hf-01 tmp]# ls aminglinux/
2 aming2
cat 这个查看文件内容的
-A 显示文件的所有文件(包括字符)
-n 显示行号
tac 倒序查看文件内容,与cat相反
more 也是用来查看文件内容,但是不会像cat一样一下全部显示出来,他的显示方式为一屏一屏的显示,
(可使用空格键查看下一行或ctrl+b 可以往前看,内容查看完以后会自动结束命令的运行)
wc -l 可以查看文件的行数
[root@localhost ~]# wc -l anaconda-ks.cfg.1
51 anaconda-ks.cfg.1 显示改文件的行数
[root@localhost ~]# wc -l anaconda-ks.cfg.1
51 anaconda-ks.cfg.1
[root@localhost ~]# cat /etc/passwd >> anaconda-ks.cfg.1 这就是把/etc/passwd中的文件内容增加到anaconda-ks.cfg.1文件中去
[root@localhost ~]# cat /etc/passwd >> anaconda-ks.cfg.1
[root@localhost ~]# wc -l anaconda-ks.cfg.1
93 anaconda-ks.cfg.1
[root@localhost ~]# cat /etc/passwd >> anaconda-ks.cfg.1
[root@localhost ~]# cat /etc/passwd >> anaconda-ks.cfg.1
[root@localhost ~]# more anaconda-ks.cfg.1
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
cdrom
# Use graphical install
此处省略....
head 查看文件的前 10行 (默认10行)
-n 数字 (指定查看文件的多少行)
tail 查看文件的尾部,最后 10行
-f 动态显示文件
-n 数字 显示文件以数字为单位的行数(头几行,为几行)
[root@localhost ~]# head anaconda-ks.cfg.1
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
cdrom
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
[root@localhost ~]# head -n 2 anaconda-ks.cfg.1
#version=DEVEL
# System authorization information
[root@localhost ~]# tail -n 2 anaconda-ks.cfg.1
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
chrony:x:997:995::/var/lib/chrony:/sbin/nologin