二周第二次课(12月19日)

Posted 两颗白菜

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了二周第二次课(12月19日)相关的知识,希望对你有一定的参考价值。

二周第二次课(12月19日)
2.10 环境变量PATH
2.11 cp命令
2.12 mv命令
2.13 文档查看cat/more/less/head/tail

 

 


环境变量 :
#PATH (环境变量)
#CP (拷贝)
#which (查看命令别名和所在的路径)

[[email protected] ~]# which alias PATH ^C
[[email protected] ~]# PATH ^C
[[email protected] ~]# which rm
alias rm=‘rm -i‘
/usr/bin/rm

[[email protected] ~]# which rmdir
/usr/bin/rmdir

[[email protected] ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/tmp/

[[email protected] ~]# rm /usr/bin/rm ^C
[[email protected] ~]# adkee
-bash: adkee: 未找到命令
[[email protected] ~]# which ls
alias ls=‘ls --color=auto‘
/usr/bin/ls

[[email protected] ~]# ls /usr/bin/ls
/usr/bin/ls

[[email protected] ~]# cp /usr/bin/ls /tmp/ls2

[[email protected] ~]# /tmp/ls2
anaconda-ks.cfg

[[email protected] ~]# ls
anaconda-ks.cfg

[[email protected] ~]# PATH=$PATH:/tmp/

[[email protected] ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/tmp/

[[email protected] ~]# ls
anaconda-ks.cfg

[[email protected] ~]# ls2
anaconda-ks.cfg

[[email protected] ~]# which ls2
/tmp/ls2

[[email protected] ~]# 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/
[[email protected] ~]#

副本

[[email protected] ~]# ls2
-bash: ls2: 未找到命令

[[email protected] ~]# /tmp/ls2
anaconda-ks.cfg

[[email protected] ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

[[email protected] ~]# vi /etc/profile

[[email protected] ~]# 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/
[[email protected] ~]#

副本

[email protected] ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/tmp/:/root/bin

[[email protected] ~]# ls2
anaconda-ks.cfg
[[email protected] ~]#
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
[[email protected] ~]# ls2

-bash: ls2: 未找到命令

[[email protected] ~]# vi /etc/profile
[[email protected] ~]# 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
[[email protected] ~]#

命令:

#cp >>copy (拷贝)
#cp -r (拷贝目录参数)
#cp -i (安全选项参数)
#源文件》》目标文件
#源目录》》目标目录

[[email protected] ~]# cp r /tmp/adkee//tmp/admin1

[[email protected] ~]# tree /tmp/admin1/
/tmp/admin1/
└── 2
└── 1.txt

1 directory, 1 file

[[email protected] ~]# tree /tmp/admin/
/tmp/admin/
└── 2
└── 1.txt

1 directory, 1 file

[[email protected] ~]# which cp
alias cp=‘cp -i‘
/usr/bin/cp

[[email protected] ~]# cp /etc/passwd /tmp/1.txt
cp:是否覆盖"/tmp/1.txt"? ^C^C

[[email protected] ~]# /usr/bin/cp /etc/passwd /tmp/1.txt

[[email protected] ~]# tree /tmp/admin1/
/tmp/admin1/
└── 2
└── 1.txt

1 directory, 1 file

[[email protected] ~]# cp -r /tmp/adkee/ /tmp/admin1/

[[email protected] ~]# ls /tmp/admin1/
2 adkee

[[email protected] ~]# tree /tmp/admin1/
/tmp/admin1/
├── 2
│   └── 1.txt
└── adkee
└── 2
└── 1.txt

3 directories, 2 files

[[email protected] ~]# cp -r /tmp/adkee/ /tmp/admin1/
cp:是否覆盖"/tmp/admin1/adkee/2/1.txt"? n
[[email protected] ~]#


命令:
#mv >> move

#mv >>(在同一目录下是改名字参数)

#mv >>(目标文件已存在会提示是是否覆盖)

#mv >>(目标目录且源也是目录,目标目录不存在就会更改目录名字)

#mv >>(目标目录且源也是目录,目标目录已存在就会把源放到目标目录里面)


[[email protected] tmp]# ls
1.txt
adkee
admin
admin1
ls2
systemd-private-ec35b47c3f9043809d70ccf6780ed722-vmtoolsd.service-sE1em2


[[email protected] tmp]# mv 1.txt /root/2.txt

[[email protected] tmp]# ls /root/
2.txt anaconda-ks.cfg.1

[[email protected] tmp]# ls
adkee
admin
admin1
ls2
systemd-private-ec35b47c3f9043809d70ccf6780ed722-vmtoolsd.service-sE1em2

[[email protected] tmp]# mv ls2 admin/

[[email protected] tmp]# ls admin
2 ls2

[[email protected] tmp]# which mv
alias mv=‘mv -i‘
/usr/bin/mv

[[email protected] tmp]# mv ls2 admin/
mv: 无法获取"ls2" 的文件状态(stat): 没有那个文件或目录

[[email protected] tmp]# touch ls2

[[email protected] tmp]# mv ls2 admin/
mv:是否覆盖"admin/ls2"? n

[[email protected] tmp]# which mv
alias mv=‘mv -i‘
/usr/bin/mv

[[email protected] tmp]# /usr/bin/mv ls2 admin/

[[email protected] tmp]# ls
adkee
admin
admin1
systemd-private-ec35b47c3f9043809d70ccf6780ed722-vmtoolsd.service-sE1em2

[[email protected] tmp]# ls admin
2 ls2

[[email protected] tmp]# ls
adkee
admin
admin1
systemd-private-ec35b47c3f9043809d70ccf6780ed722-vmtoolsd.service-sE1em2

[[email protected] tmp]# mv admin1/ admin

[[email protected] tmp]# ls
adkee
admin
systemd-private-ec35b47c3f9043809d70ccf6780ed722-vmtoolsd.service-sE1em2

[[email protected] tmp]# mv admin/ admin2/

[[email protected] tmp]# ls
adkee
admin2
systemd-private-ec35b47c3f9043809d70ccf6780ed722-vmtoolsd.service-sE1em2

[[email protected] tmp]# mv admin2/ adkee/

[[email protected] tmp]# ls
adkee
systemd-private-ec35b47c3f9043809d70ccf6780ed722-vmtoolsd.service-sE1em2

[[email protected] tmp]# ls adkee/
2 admin2

[[email protected] tmp]# touch adkee/admin2/1.txt

[[email protected] 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 动态显示文件内容)

以上是关于二周第二次课(12月19日)的主要内容,如果未能解决你的问题,请参考以下文章

二周第二次课(1月30日)

二周第二次课

二周第二次课(10月24日)

Linux学习笔记第二周第二次课(1月30日)

Linux20180421五周第二次课(4月19日)

Linux20180421五周第二次课(4月19日)