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