- which 能够查看命令所在的路径
- which查询的路径是经过如下的路径,进行查询
[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命令了,有两种方法。mysql
方法一:从新赋值linux
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin (去除:/tmp/) 这时在执行ls2命令,就会失效
方法二:从新编辑文件/etc/profileredis
快捷键dd命令,删除PATH=$PATH:/tmp/并:wq保存 在去新建终端,执行echo $PATH 就会发现/tmp/目录消失了
cp = copysql
将源文件 拷贝成目标文件 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