设为首页 收藏本站
查看: 1019|回复: 0

[经验分享] linux学习命令总结③

[复制链接]

尚未签到

发表于 2018-5-24 08:50:30 | 显示全部楼层 |阅读模式
  #cd ~ 回到当前用户的家目录
[root@VM_168_102_centos etc]# pwd
/etc //当前所在目录
[root@VM_168_102_centos etc]# cd ~ //回到当前用户家木里
[root@VM_168_102_centos ~]# pwd
/root //当前用户家目录
[root@VM_168_102_centos ~]# su wanghan
[wanghan@VM_168_102_centos rott]$ cd ~ //回到当前用户家木里
[wanghan@VM_168_102_centos ~]$ pwd
/home/wanghan  //当前用户家目录
[wanghan@VM_168_102_centos ~]$
  #cd - 回到上一次所在目录

[wanghan@VM_168_102_centos ~]$ cd /etc //切换到/etc目录
[wanghan@VM_168_102_centos etc]$ cd /tmp //从/etc目录切换到/tmp目录
[wanghan@VM_168_102_centos tmp]$ cd -  //从当前/tmp回到上一次所在目录
/etc //回到了/etc
[wanghan@VM_168_102_centos etc]$ cd - //再从/etc回到上一次所在目录
/tmp //回到了/tmp
[wanghan@VM_168_102_centos tmp]$
  #pwd命令:查看当前工作目录的完整路径

[wanghan@VM_168_102_centos /]$ pwd
/
[wanghan@VM_168_102_centos /]$ cd /etc
[wanghan@VM_168_102_centos etc]$ pwd
/etc
[wanghan@VM_168_102_centos etc]$
  #mkdir命令:用来创建指定的名称的目录,要求创建目录的用户在当前目录中具有写权限,并且指定的目录名不能是当前目录中已有的目录。
  mkdir [选项] 目录…

[wanghan@VM_168_102_centos tmp]$ ls
agent_cmd.sock  ap_1002.pid  ap_1004.pid  ap_1005.pid  ap_1007.pid  ap_1008.pid  ap_1014.pid
[wanghan@VM_168_102_centos tmp]$ mkdir /tmp/test
[wanghan@VM_168_102_centos tmp]$ ls
agent_cmd.sock  ap_1002.pid  ap_1004.pid  ap_1005.pid  ap_1007.pid  ap_1008.pid  ap_1014.pid  test
  mkdir –p 目录…

[wanghan@VM_168_102_centos tmp]$ ls
agent_cmd.sock  ap_1002.pid  ap_1004.pid  ap_1005.pid  ap_1007.pid  ap_1008.pid  ap_1014.pid  test
[wanghan@VM_168_102_centos tmp]$ mkdir /tmp/wanghan/test
mkdir: cannot create directory `/tmp/wanghan/test': No such file or directory
[wanghan@VM_168_102_centos tmp]$ mkdir -p /tmp/wanghan/test
[wanghan@VM_168_102_centos tmp]$ ls
agent_cmd.sock  ap_1002.pid  ap_1004.pid  ap_1005.pid  ap_1007.pid  ap_1008.pid  ap_1014.pid  test  wanghan
[wanghan@VM_168_102_centos tmp]$ ls wanghan
test
[wanghan@VM_168_102_centos tmp]$
  若创建的路径中有尚不再存的目录即可按照路径全部创建
  mkdir –v 目录…

[wanghan@VM_168_102_centos tmp]$ mkdir -pv /tmp/a/b/c/d/e/f/abcd
mkdir: created directory `/tmp/a'
mkdir: created directory `/tmp/a/b'
mkdir: created directory `/tmp/a/b/c'
mkdir: created directory `/tmp/a/b/c/d'
mkdir: created directory `/tmp/a/b/c/d/e'
mkdir: created directory `/tmp/a/b/c/d/e/f'
mkdir: created directory `/tmp/a/b/c/d/e/f/abcd'
  显示创建目录过程的详细信息
  #rmdir命令:删除已空的目录

[wanghan@VM_168_102_centos tmp]$ ls
a  agent_cmd.sock  ap_1002.pid  ap_1004.pid  ap_1005.pid  ap_1007.pid  ap_1008.pid  ap_1014.pid  ceshi  test  wanghan
[wanghan@VM_168_102_centos tmp]$ ls test
test_1
[wanghan@VM_168_102_centos tmp]$ rmdir /tmp/test
rmdir: failed to remove `/tmp/test': Directory not empty  //该目录非空
[wanghan@VM_168_102_centos tmp]$ rmdir /tmp/test/test_1
[wanghan@VM_168_102_centos tmp]$ ls test
[wanghan@VM_168_102_centos tmp]$ rmdir /tmp/test
[wanghan@VM_168_102_centos tmp]$ ls
a  agent_cmd.sock  ap_1002.pid  ap_1004.pid  ap_1005.pid  ap_1007.pid  ap_1008.pid  ap_1014.pid  ceshi  wanghan
  #shell中的引用
  ‘ ’:强引用,变量替换不会进行

[wanghan@VM_168_102_centos tmp]$ num=123
[wanghan@VM_168_102_centos tmp]$ echo $num
123
[wanghan@VM_168_102_centos tmp]$ echo '$num'
$num
  “ ”:若引用,能够执行变量替换

[wanghan@VM_168_102_centos tmp]$ num=456
[wanghan@VM_168_102_centos tmp]$ echo num
num
[wanghan@VM_168_102_centos tmp]$ echo "num"
num
[wanghan@VM_168_102_centos tmp]$
  · ·:命令替换,引用命令的执行结果;命令替换的另外一符号:$(命令);

[wanghan@VM_168_102_centos tmp]$ echo ls /tmp
ls /tmp
[wanghan@VM_168_102_centos tmp]$ echo `ls /tmp`
a agent_cmd.sock ap_1002.pid ap_1004.pid ap_1005.pid ap_1007.pid ap_1008.pid ap_1014.pid ceshi wanghan
  结合使用:

[wanghan@VM_168_102_centos tmp]$ echo $test
tmp
[wanghan@VM_168_102_centos tmp]$ echo "This is $test"
This is tmp
[wanghan@VM_168_102_centos tmp]$ echo `ls /$test`
a agent_cmd.sock ap_1002.pid ap_1004.pid ap_1005.pid ap_1007.pid ap_1008.pid ap_1014.pid ceshi wanghan
[wanghan@VM_168_102_centos tmp]$ echo "/tmp:`ls /$test`"
/tmp:a
agent_cmd.sock
ap_1002.pid
ap_1004.pid
ap_1005.pid
ap_1007.pid
ap_1008.pid
ap_1014.pid
ceshi
wanghan
  #创建一个一当前日期时间创建一个目录

[wanghan@VM_168_102_centos tmp]$ date=`date +%Y-%m-%d-%H%M%S`
[wanghan@VM_168_102_centos tmp]$ mkdir -pv /tmp/$date
mkdir: created directory `/tmp/2014-08-04-212053'
[wanghan@VM_168_102_centos tmp]$ ls
2014-08-04-212053  a  agent_cmd.sock  ap_1002.pid  ap_1004.pid  ap_1005.pid  ap_1007.pid  ap_1008.pid  ap_1014.pid  ceshi  wanghan
[wanghan@VM_168_102_centos tmp]$
  #history命令:查看在当前shell进程的保存在缓冲区中的执行过的命令列表,当shell退出时缓冲区的命令会自动化保存至当前用户的家目录中的.bash_history文件中。

[root@VM_168_102_centos ~]# su wanghan
[wanghan@VM_168_102_centos rott]$ history
1  exit
2  history
[wanghan@VM_168_102_centos rott]$ who
root     pts/0        Aug  4 19:11 (222.36.253.150)
[wanghan@VM_168_102_centos rott]$ pwd
/root
[wanghan@VM_168_102_centos rott]$ history
1  exit
2  history
3  who
4  pwd
5  history
[wanghan@VM_168_102_centos rott]$ cat /home/wanghan/.bash_history
exit
[wanghan@VM_168_102_centos rott]$ exit
exit
[root@VM_168_102_centos ~]# su wanghan
[wanghan@VM_168_102_centos rott]$ cat /home/wanghan/.bash_history
exit
history
who
pwd
history
cat /home/wanghan/.bash_history
exit
[wanghan@VM_168_102_centos rott]$
  !#:通过命令历史列表中的命令编号引用并执行第#条命令

[wanghan@VM_168_102_centos rott]$ history
1  exit
2  history
3  who
4  pwd
5  history
6  cat /home/wanghan/.bash_history
7  exit
8  cat /home/wanghan/.bash_history
9  history
10  history who
11  history pwd
12  history
13  history who
14  exit
15  history
16  who
17  history
[wanghan@VM_168_102_centos rott]$ !3
who
root     pts/0        Aug  4 19:11 (222.36.253.150)
[wanghan@VM_168_102_centos rott]$
!-#:通过命令历史列表中的命令编号引用并执行倒数第#条命令
[wanghan@VM_168_102_centos rott]$ history
1  exit
2  history
3  who
4  pwd
5  history
6  cat /home/wanghan/.bash_history
7  exit
8  cat /home/wanghan/.bash_history
9  history
10  history who
11  history pwd
12  history
13  history who
14  exit
15  history
16  who
17  history
18  who
19*
20  history
[wanghan@VM_168_102_centos rott]$ !-3
who
root     pts/0        Aug  4 19:11 (222.36.253.150)
[wanghan@VM_168_102_centos rott]$
  !!:执行上一次历史命令

[wanghan@VM_168_102_centos rott]$ pwd
/root
[wanghan@VM_168_102_centos rott]$ !!
pwd
/root
[wanghan@VM_168_102_centos rott]$ !!
pwd
/root
  ! string:执行命令历史列表中最近一次以string开头的命令

[wanghan@VM_168_102_centos rott]$ whatis
usage: whatis keyword ...
[wanghan@VM_168_102_centos rott]$ who
root     pts/0        Aug  4 19:11 (222.36.253.150)
[wanghan@VM_168_102_centos rott]$ !w
who
root     pts/0        Aug  4 19:11 (222.36.253.150)
[wanghan@VM_168_102_centos rott]$
  ! $:引用上一个命令的最后一个参数,快捷键:Esc .

[wanghan@VM_168_102_centos etc]$ cd /tmp
[wanghan@VM_168_102_centos tmp]$ ls /!$
ls //tmp
2014-08-04-212053  a  agent_cmd.sock  ap_1002.pid  ap_1004.pid  ap_1005.pid  ap_1007.pid  ap_1008.pid  ap_1014.pid  ceshi  wanghan
  history –c:清空当前缓存中的历史记录

[wanghan@VM_168_102_centos tmp]$ history
1  who
2  pwd
3  history
[wanghan@VM_168_102_centos tmp]$ history -c
[wanghan@VM_168_102_centos tmp]$ history
1  history
  history –d #:删除与命令历史列表中命令编号相对应的命令记录

[wanghan@VM_168_102_centos tmp]$ history
1  who
2  pwd
3  history
[wanghan@VM_168_102_centos tmp]$ history -d 1
[wanghan@VM_168_102_centos tmp]$ history
1  pwd
2  history
3  history -d 1
4  history
[wanghan@VM_168_102_centos tmp]$
  history -a:追加当前历史记录保存至命令历史文件中

[wanghan@VM_168_102_centos rott]$ cat /home/wanghan/.bash_history
exit
[wanghan@VM_168_102_centos rott]$ history
1  exit
2  cat /home/wanghan/.bash_history
3  history
[wanghan@VM_168_102_centos rott]$ who
root     pts/0        Aug  4 19:11 (222.36.253.150)
[wanghan@VM_168_102_centos rott]$ pwd
/root
[wanghan@VM_168_102_centos rott]$ histroy -a
bash: histroy: command not found
[wanghan@VM_168_102_centos rott]$ history -a
[wanghan@VM_168_102_centos rott]$ cat /home/wanghan/.bash_history
exit
cat /home/wanghan/.bash_history
history
who
pwd
histroy -a
history -a
[wanghan@VM_168_102_centos rott]$
  命令历史相关的环境变量:
  HISTSIZE:命令历史中可以保存的命令个数

[root@VM_168_102_centos ~]# echo $HISTSIZE
1000
  HISTFILESIZE:命令文件中可以保存的命令个数

[root@VM_168_102_centos ~]# echo $HISTFILESIZE
1000
  HISTFILE:命令历史文件

[root@VM_168_102_centos ~]# echo $HISTFILE
/root/.bash_history
  HISTCONTROL:控制命令历史的生成

[root@VM_168_102_centos ~]# echo $HISTCONTROL
ignoredups
  ignoredups:忽略重复记录的命令,连续相同的命令才算重复

[root@VM_168_102_centos ~]# history
1  history
[root@VM_168_102_centos ~]# who
root     pts/0        Aug  4 19:11 (222.36.253.150)
[root@VM_168_102_centos ~]# who
root     pts/0        Aug  4 19:11 (222.36.253.150)
[root@VM_168_102_centos ~]# history
1  history
2  who
3  history
[root@VM_168_102_centos ~]# who
root     pts/0        Aug  4 19:11 (222.36.253.150)
[root@VM_168_102_centos ~]# history
1  history
2  who
3  history
4  who
5  history
[root@VM_168_102_centos ~]#
  ignorespace:不记录以空白字符开头的命令

[root@VM_168_102_centos ~]# echo $HISTCONTROL
ignoredups
[root@VM_168_102_centos ~]# HISTCONTROL=ignorespace
[root@VM_168_102_centos ~]# echo $HISTCONTROL
ignorespace
[root@VM_168_102_centos ~]# history
1  history
2  echo $HISTCONTROL
3  HISTCONTROL=ignorespace
4  echo $HISTCONTROL
5  history
[root@VM_168_102_centos ~]#  who
root     pts/0        Aug  4 19:11 (222.36.253.150)
[root@VM_168_102_centos ~]#  pwd
/root
[root@VM_168_102_centos ~]# history
1  history
2  echo $HISTCONTROL
3  HISTCONTROL=ignorespace
4  echo $HISTCONTROL
5  history
6  history
[root@VM_168_102_centos ~]#
  ignoreboth:同时具有ignoredups和ignorespace的特性
  shell中的变量赋值:
  变量名=值

[root@VM_168_102_centos ~]# num=123
[root@VM_168_102_centos ~]# echo $num
123
  注意:变量在赋值时不能使用$
  变量名只能包含字母、数字和下划线,而且不能以数字开头
  变量名区别大小写

[root@VM_168_102_centos ~]# num=123
[root@VM_168_102_centos ~]# echo $NUM
[root@VM_168_102_centos ~]# echo $num
123

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-480490-1-1.html 上篇帖子: linux学习命令总结② 下篇帖子: PXE安装Linux
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表