环境变量:PATH
[[email protected] ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[[email protected] ~]# which ls 查看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 执行一下,效果和ls一样
1.txt anaconda-ks.cfg a.txt bb split_dir testb.txt testc.txt 学习计划安排.txt
[[email protected] ~]# ls
1.txt anaconda-ks.cfg a.txt bb split_dir testb.txt testc.txt 学习计划安排.txt
[[email protected] ~]#
[[email protected] ~]# ls2
-bash: ls2: 未找到命令
[[email protected] ~]# PATH=$PATH:/tmp/ 把/tmp/加入到路径当中
[[email protected] ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/tmp/
[[email protected] ~]# ls2
1.txt anaconda-ks.cfg a.txt bb split_dir testb.txt testc.txt 学习计划安排.txt
[[email protected] ~]# ls2 打开另一个终端,发现ls2并没有生效
-bash: ls2: 未找到命令
[[email protected] ~]#
[[email protected] ~]# /tmp/ls2
1.txt anaconda-ks.cfg a.txt bb split_dir testb.txt testc.txt 学习计划安排.txt
要使ls2在另一个终端生效,修改/etc/profile文件,使其开机就生效
[[email protected] ~]# ls2
1.txt anaconda-ks.cfg a.txt bb split_dir testb.txt testc.txt 学习计划安排.txt
[[email protected] ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/tmp/
[[email protected] ~]# PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin 使其不生效,取消路径,/etc/profile里面同样修改一下
[[email protected] ~]# ls2
-bash: ls2: 未找到命令
cp命令 copy
[[email protected] ~]# cp /etc/passwd /tmp/1.txt
[[email protected] ~]# ls /tmp/1.txt
/tmp/1.txt
[[email protected] ~]# cp -r /tmp/lizhipenglinux/ /tmp/lizhipeng
[[email protected] ~]# tree /tmp/lizhipeng/
/tmp/lizhipeng/
0 directories, 0 files
[[email protected] ~]# tree /tmp/lizhipenglinux
/tmp/lizhipenglinux
0 directories, 0 files
[[email protected] ~]# cp -r /tmp/lizhipenglinux/ /tmp/lizhipeng1/
[[email protected] ~]# tree !$ 上一条命令的最后一个参数
tree /tmp/lizhipeng1/
/tmp/lizhipeng1/
0 directories, 0 files
[[email protected] ~]# which cp
alias cp=‘cp -i‘
/usr/bin/cp
[[email protected] ~]# which rm
alias rm=‘rm -i‘
/usr/bin/rm
[[email protected] ~]# cp /etc/passwd /tmp/1.txt
cp:是否覆盖"/tmp/1.txt"? ^C
[[email protected] ~]# /usr/bin/cp /etc/passwd /tmp/1.txt 不会问是否覆盖
[[email protected] ~]# tree /tmp/lizhipeng1/
/tmp/lizhipeng1/
0 directories, 0 files
[[email protected] ~]# cp -r /tmp/lizhipenglinux/ /tmp/lizhipeng1/
[[email protected] ~]# ls /tmp/lizhipeng1/ 当目标目录已经存在时,会把原目录放到目标目录下;如果目标目录不存在,会把原目录拷贝过来,改个名字,改成目标目录的名字
lizhipenglinux
mv命令
[[email protected] ~]# cd /tmp/
[[email protected] tmp]# ls
1.txt bb lizhipeng lizhipeng1 lizhipenglinux ls2 split_dir test
[[email protected] tmp]# mv 1.txt /root/2.txt 把/tmp/1.txt放到/root/下,并改名2.txt
[[email protected] tmp]# ls /root/
1.txt 2.txt anaconda-ks.cfg a.txt bb split_dir testb.txt testc.txt 学习计划安排.txt
[[email protected] tmp]# mv ls2 lizhipeng/
[[email protected] tmp]# ls lizhipeng/
ls2
[[email protected] tmp]# touch ls2
[[email protected] tmp]# mv ls2 lizhipeng/
mv:是否覆盖"lizhipeng/ls2"? n
[[email protected] tmp]# ls
bb lizhipeng lizhipeng1 lizhipenglinux ls2 split_dir test
[[email protected] tmp]# mv lizhipeng/ lzp/ 目标目录不存在,原目录改名字
[[email protected] tmp]# ls
bb lizhipeng1 lizhipenglinux ls2 lzp split_dir test
[[email protected] tmp]# tree lzp/
lzp/
└── ls2
0 directories, 1 file
[[email protected] tmp]# mv lizhipeng1/ lzp/ 目标目录存在时,会把原目录放到目标目录下
[[email protected] tmp]# tree lzp/
lzp/
├── lizhipeng1
│ └── lizhipenglinux
└── ls2
2 directories, 1 file
[[email protected] tmp]# mkdir lizhipeng1/
[[email protected] tmp]# touch lizhipeng1/1.txt
[[email protected] tmp]# tree lizhipeng1/
lizhipeng1/
└── 1.txt
0 directories, 1 file
[[email protected] tmp]# mv lizhipeng1/ lzp/
mv:是否覆盖"lzp/lizhipeng1"? y
mv: 无法将"lizhipeng1/" 移动至"lzp/lizhipeng1": 文件已存在 因为lizhipeng1/下面有lizhipenglinux,所以无法覆盖。
[[email protected] tmp]# cd lzp
[[email protected] lzp]# ls
lizhipeng1 ls2
[[email protected] lzp]# cd lizhipeng1
[[email protected] lizhipeng1]# ls
lizhipenglinux
[[email protected] lizhipeng1]# rm -rf *
[[email protected] lizhipeng1]# ls
[[email protected] lizhipeng1]# mv lizhipeng1/ lzp/
mv: 无法获取"lizhipeng1/" 的文件状态(stat): 没有那个文件或目录
[[email protected] lizhipeng1]# cd ..
[[email protected] lzp]# cd ..
[[email protected] tmp]# mv lizhipeng1/ lzp/
mv:是否覆盖"lzp/lizhipeng1"? y
[[email protected] tmp]# ls lzp/lizhipeng1/
1.txt
[[email protected] tmp]# tree lzp/
lzp/
├── lizhipeng1
│ └── 1.txt
└── ls2
1 directory, 2 files
文档查看cat_more_less_head_tail
cat用于查看一个文件的内容并将其显示在屏幕上
-n:查看文件时,把行号也显示到屏幕上。
[[email protected] ~]# echo ‘1111‘ > 1.txt
[[email protected] ~]# echo ‘2222‘ >> 1.txt
[[email protected] ~]# cat 1.txt
1111
2222
[[email protected] ~]# cat -n 1.txt
1 1111
2 2222
-A:显示所有的内容,包括特殊字符。
[[email protected] ~]# cat -A 1.txt
1111$
2222$
[[email protected] ~]# cat -nA 1.txt
1 1111$
2 2222$
less
/字符串,然后回车,这样就可以查找这个字符串。如果是查找多个该字符串,可以按n键显示下一个,N向上;也可以用?键代替/键来搜索字符串,/是在当前行向下搜索,而?是在当前行向上搜索。g行首,G行尾
head
用于显示文件的前10行,后面直接跟文件名。如果加-n选项,则显示文件的前几行。
tail
用于显示文件的最后10行,后面直接跟文件名。如果加-n选项,则显示文件的最后几行。
tail -f可以动态显示文件的最后10行。tail -f /var/log/message可以动态、实时地查看文件/var/log/message中的内容