二周第二次课(12月19日)
2.10 环境变量PATH
2.11 cp命令
2.12 mv命令
2.13 文档查看cat/more/less/head/tail
环境变量 :
#PATH (环境变量)
#CP (拷贝)
#which (查看命令别名和所在的路径)
[root@localhost ~]# which alias PATH ^C
[root@localhost ~]# PATH ^C
[root@localhost ~]# which rm
alias rm=‘rm -i‘
/usr/bin/rm
[root@localhost ~]# which rmdir
/usr/bin/rmdir
[root@localhost ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/tmp/
[root@localhost ~]# rm /usr/bin/rm ^C
[root@localhost ~]# adkee
-bash: adkee: 未找到命令
[root@localhost ~]# which ls
alias ls=‘ls --color=auto‘
/usr/bin/ls
[root@localhost ~]# ls /usr/bin/ls
/usr/bin/ls
[root@localhost ~]# cp /usr/bin/ls /tmp/ls2
[root@localhost ~]# /tmp/ls2
anaconda-ks.cfg
[root@localhost ~]# ls
anaconda-ks.cfg
[root@centos-02 ~]# PATH=$PATH:/tmp/
[root@centos-02 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/tmp/
[root@centos-02 ~]# ls
anaconda-ks.cfg
[root@centos-02 ~]# ls2
anaconda-ks.cfg
[root@centos-02 ~]# which ls2
/tmp/ls2
[root@centos-02 ~]# vi /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
- - - - -- -删除分割线------------
unset i
unset -f pathmunge
PATH=$PATH:/tmp/
[root@centos-02 ~]#
副本
[root@centos-02 ~]# ls2
-bash: ls2: 未找到命令
[root@centos-02 ~]# /tmp/ls2
anaconda-ks.cfg
[root@centos-02 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@centos-02 ~]# vi /etc/profile
[root@centos-02 ~]# cat /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
- - - - -- -删除分割线------------
unset i
unset -f pathmunge
PATH=$PATH:/tmp/
[root@centos-02 ~]#
副本
root@centos-02 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/tmp/:/root/bin
[root@centos-02 ~]# ls2
anaconda-ks.cfg
[root@centos-02 ~]#
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
[root@centos-02 ~]# ls2
-bash: ls2: 未找到命令
[root@centos-02 ~]# vi /etc/profile
[root@centos-02 ~]# cat /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
- - - - -- -删除分割线------------
unset i
unset -f pathmunge
[root@centos-02 ~]#
命令:
#cp >>copy (拷贝)
#cp -r (拷贝目录参数)
#cp -i (安全选项参数)
#源文件》》目标文件
#源目录》》目标目录
[root@localhost ~]# cp r /tmp/adkee//tmp/admin1
[root@localhost ~]# tree /tmp/admin1/
/tmp/admin1/
└── 2
└── 1.txt
1 directory, 1 file
[root@localhost ~]# tree /tmp/admin/
/tmp/admin/
└── 2
└── 1.txt
1 directory, 1 file
[root@localhost ~]# which cp
alias cp=‘cp -i‘
/usr/bin/cp
[root@localhost ~]# cp /etc/passwd /tmp/1.txt
cp:是否覆盖"/tmp/1.txt"? ^C^C
[root@localhost ~]# /usr/bin/cp /etc/passwd /tmp/1.txt
[root@localhost ~]# tree /tmp/admin1/
/tmp/admin1/
└── 2
└── 1.txt
1 directory, 1 file
[root@localhost ~]# cp -r /tmp/adkee/ /tmp/admin1/
[root@localhost ~]# ls /tmp/admin1/
2 adkee
[root@localhost ~]# tree /tmp/admin1/
/tmp/admin1/
├── 2
│ └── 1.txt
└── adkee
└── 2
└── 1.txt
3 directories, 2 files
[root@localhost ~]# cp -r /tmp/adkee/ /tmp/admin1/
cp:是否覆盖"/tmp/admin1/adkee/2/1.txt"? n
[root@localhost ~]#
命令:
#mv >> move
#mv >>(在同一目录下是改名字参数)
#mv >>(目标文件已存在会提示是是否覆盖)
#mv >>(目标目录且源也是目录,目标目录不存在就会更改目录名字)
#mv >>(目标目录且源也是目录,目标目录已存在就会把源放到目标目录里面)
[root@localhost tmp]# ls
1.txt
adkee
admin
admin1
ls2
systemd-private-ec35b47c3f9043809d70ccf6780ed722-vmtoolsd.service-sE1em2
[root@localhost tmp]# mv 1.txt /root/2.txt
[root@localhost tmp]# ls /root/
2.txt anaconda-ks.cfg.1
[root@localhost tmp]# ls
adkee
admin
admin1
ls2
systemd-private-ec35b47c3f9043809d70ccf6780ed722-vmtoolsd.service-sE1em2
[root@localhost tmp]# mv ls2 admin/
[root@localhost tmp]# ls admin
2 ls2
[root@localhost tmp]# which mv
alias mv=‘mv -i‘
/usr/bin/mv
[root@localhost tmp]# mv ls2 admin/
mv: 无法获取"ls2" 的文件状态(stat): 没有那个文件或目录
[root@localhost tmp]# touch ls2
[root@localhost tmp]# mv ls2 admin/
mv:是否覆盖"admin/ls2"? n
[root@localhost tmp]# which mv
alias mv=‘mv -i‘
/usr/bin/mv
[root@localhost tmp]# /usr/bin/mv ls2 admin/
[root@localhost tmp]# ls
adkee
admin
admin1
systemd-private-ec35b47c3f9043809d70ccf6780ed722-vmtoolsd.service-sE1em2
[root@localhost tmp]# ls admin
2 ls2
[root@localhost tmp]# ls
adkee
admin
admin1
systemd-private-ec35b47c3f9043809d70ccf6780ed722-vmtoolsd.service-sE1em2
[root@localhost tmp]# mv admin1/ admin
[root@localhost tmp]# ls
adkee
admin
systemd-private-ec35b47c3f9043809d70ccf6780ed722-vmtoolsd.service-sE1em2
[root@localhost tmp]# mv admin/ admin2/
[root@localhost tmp]# ls
adkee
admin2
systemd-private-ec35b47c3f9043809d70ccf6780ed722-vmtoolsd.service-sE1em2
[root@localhost tmp]# mv admin2/ adkee/
[root@localhost tmp]# ls
adkee
systemd-private-ec35b47c3f9043809d70ccf6780ed722-vmtoolsd.service-sE1em2
[root@localhost tmp]# ls adkee/
2 admin2
[root@localhost tmp]# touch adkee/admin2/1.txt
[root@localhost tmp]# tree adkee/admin2/
adkee/admin2/
├── 1.txt
├── 2
│ └── 1.txt
├── admin1
│ ├── 2
│ │ └── 1.txt
│ └── adkee
│ └── 2
│ └── 1.txt
└── ls2
文档查看:
#cat 查看文件(-A显示所有,$文档结束符 ,-n显示行号)
#more(显示一屏,空格键显示剩余,看完直接退出,CTDL+B向上看)
#less(空格键一屏一屏向下显示,支持方向键。CTDL+B向上看,CTDL+F向下看。
字母“Q”退出,“/”向下搜索。“?”向上搜索。 g首页,G末尾。n向上看,N向下看 )
#head(查看文件开头10行)
(-n自定义行数)
#tail(查看文件末尾10行)
(-f 动态显示文件内容)