设为首页 收藏本站
查看: 1193|回复: 1

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

[复制链接]

尚未签到

发表于 2018-5-24 08:29:17 | 显示全部楼层 |阅读模式
  #ls命令:通过ls 命令不仅可以查看linux文件夹包含的文件,而且可以查看文件权限(包括目录、文件夹、文件权限),查看目录信息等等
[root@VM_168_102_centos /]# ls
bin   data  etc   lib    lost
+found  mnt  proc  sbin     srv  tmp  var
boot  dev   home  lib64  media       opt  root  selinux  sys  usr


  ls –a:显示所有文件,包含.开头的隐藏文件

[root@VM_168_102_centos /]# ls -a
.             .readahead_collect  dev   lib64       opt   selinux  usr
..            bin                 etc   lost
+found  proc  srv      var
.autofsck     boot                home  media       root  sys
.autorelabel  data                lib   mnt         sbin  tmp


  ls –l:列出文件的详细信息

[root@VM_168_102_centos tmp]# ls -l
total
24
drwxr
-xr-x 2 wanghan root 4096 Aug  4 21:21 2014-08-04-212053
drwxr
-xr-x 3 wanghan root 4096 Aug  4 20:45 a
srwxrwxrwx
1 root    root    0 Aug  9 10:05 agent_cmd.sock
-rw------- 1 root    root  105 Aug  2 11:36 ap_1002.pid
-rw------- 1 root    root    0 Aug  2 09:48 ap_1004.pid
-rw------- 1 root    root  103 Aug  2 11:36 ap_1005.pid
-rw------- 1 root    root    0 Aug  2 10:51 ap_1007.pid
-rw------- 1 root    root    0 Aug  2 10:09 ap_1008.pid
-rw------- 1 root    root    0 Aug  4 13:58 ap_1014.pid
drwxr
-xr-x 2 wanghan root 4096 Aug  4 20:44 ceshi
d
//文件类型  rwxr-xr-x //文件权限 3 //硬链接数 wanghan //属主 root //属组 4096 Aug  4 20:41 //最近一次修改时间 wanghan //文件名

  ls –d:显示目录自身的信息,结合-l使用直接查看目录自身详细信息

[root@VM_168_102_centos etc]# ls -d
.
[root@VM_168_102_centos etc]# ls
-ld
drwxr
-xr-x 75 root root 4096 Aug  9 03:28 .
[root@VM_168_102_centos etc]#


  ls -r:逆序显示

drwxr-xr-x 2 wanghan root 4096 Aug  4 21:21 2014-08-04-212053
drwxr
-xr-x 3 wanghan root 4096 Aug  4 20:45 a
srwxrwxrwx
1 root    root    0 Aug  9 10:05 agent_cmd.sock
-rw------- 1 root    root  105 Aug  2 11:36 ap_1002.pid
-rw------- 1 root    root    0 Aug  2 09:48 ap_1004.pid
-rw------- 1 root    root  103 Aug  2 11:36 ap_1005.pid
-rw------- 1 root    root    0 Aug  2 10:51 ap_1007.pid
-rw------- 1 root    root    0 Aug  2 10:09 ap_1008.pid
-rw------- 1 root    root    0 Aug  4 13:58 ap_1014.pid
drwxr
-xr-x 2 wanghan root 4096 Aug  4 20:44 ceshi
drwxr
-xr-x 3 wanghan root 4096 Aug  4 20:41 wanghan
[root@VM_168_102_centos tmp]# ls
-rl
total
24
drwxr
-xr-x 3 wanghan root 4096 Aug  4 20:41 wanghan
drwxr
-xr-x 2 wanghan root 4096 Aug  4 20:44 ceshi
-rw------- 1 root    root    0 Aug  4 13:58 ap_1014.pid
-rw------- 1 root    root    0 Aug  2 10:09 ap_1008.pid
-rw------- 1 root    root    0 Aug  2 10:51 ap_1007.pid
-rw------- 1 root    root  103 Aug  2 11:36 ap_1005.pid
-rw------- 1 root    root    0 Aug  2 09:48 ap_1004.pid
-rw------- 1 root    root  105 Aug  2 11:36 ap_1002.pid
srwxrwxrwx
1 root    root    0 Aug  9 10:05 agent_cmd.sock
drwxr
-xr-x 3 wanghan root 4096 Aug  4 20:45 a
drwxr
-xr-x 2 wanghan root 4096 Aug  4 21:21 2014-08-04-212053
[root@VM_168_102_centos tmp]#


  ls -R:同时显示其下子目录文件

[root@VM_168_102_centos tmp]# cd a
[root@VM_168_102_centos a]# ls
b
[root@VM_168_102_centos a]# ls
-R
.:
b
.
/b:
c
.
/b/c:
d
.
/b/c/d:
e
.
/b/c/d/e:
f
.
/b/c/d/e/f:
abcd
.
/b/c/d/e/f/abcd:
[root@VM_168_102_centos a]#


  ls -h:以容易理解的方式显示文件大小

[root@VM_168_102_centos tmp]# ls -l
total
24
drwxr
-xr-x 2 wanghan root 4096 Aug  4 21:21 2014-08-04-212053
drwxr
-xr-x 3 wanghan root 4096 Aug  4 20:45 a
drwxr
-xr-x 2 wanghan root 4096 Aug  4 20:44 ceshi
drwxr
-xr-x 3 wanghan root 4096 Aug  4 20:41 wanghan
[root@VM_168_102_centos tmp]# ls
-lh
total 24K
drwxr
-xr-x 2 wanghan root 4.0K Aug  4 21:21 2014-08-04-212053
drwxr
-xr-x 3 wanghan root 4.0K Aug  4 20:45 a
drwxr
-xr-x 2 wanghan root 4.0K Aug  4 20:44 ceshi
drwxr
-xr-x 3 wanghan root 4.0K Aug  4 20:41 wanghan

  ls -i:显示出文件inode号

[root@VM_168_102_centos tmp]# ls -li
total
24
458762 drwxr-xr-x 2 wanghan root 4096 Aug  4 21:21 2014-08-04-212053
458767 drwxr-xr-x 3 wanghan root 4096 Aug  4 20:45 a
458758 srwxrwxrwx 1 root    root    0 Aug  9 10:05 agent_cmd.sock
458755 -rw------- 1 root    root  105 Aug  2 11:36 ap_1002.pid
458756 -rw------- 1 root    root    0 Aug  2 09:48 ap_1004.pid
458759 -rw------- 1 root    root  103 Aug  2 11:36 ap_1005.pid
458760 -rw------- 1 root    root    0 Aug  2 10:51 ap_1007.pid
458757 -rw------- 1 root    root    0 Aug  2 10:09 ap_1008.pid
458761 -rw------- 1 root    root    0 Aug  4 13:58 ap_1014.pid
458766 drwxr-xr-x 2 wanghan root 4096 Aug  4 20:44 ceshi
458764 drwxr-xr-x 3 wanghan root 4096 Aug  4 20:41 wanghan
// 458764 inode号

  #tree命令:显示磁盘目录结构

[root@VM_168_102_centos tmp]# tree
.
|-- 2014-08-04-212053
|-- a
|   `-- b
|       `-- c
|           `-- d
|               `-- e
|                   `-- f
|                       `-- abcd
|-- agent_cmd.sock
|-- ap_1002.pid
|-- ap_1004.pid
|-- ap_1005.pid
|-- ap_1007.pid
|-- ap_1008.pid
|-- ap_1014.pid
|-- ceshi
`
-- wanghan
`
-- test
11 directories, 7 files
[root@VM_168_102_centos tmp]#


  tree –L #:显示当前目录下指定最大深度的目录结构

[root@VM_168_102_centos tmp]# tree -L 1
.
|-- 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
4 directories, 7 files
[root@VM_168_102_centos tmp]# tree
-L 2
.
|-- 2014-08-04-212053
|-- a
|   `-- b
|-- agent_cmd.sock
|-- ap_1002.pid
|-- ap_1004.pid
|-- ap_1005.pid
|-- ap_1007.pid
|-- ap_1008.pid
|-- ap_1014.pid
|-- ceshi
`
-- wanghan
`
-- test
6 directories, 7 files
[root@VM_168_102_centos tmp]#


  #alias命令:设置指令别名
  单独使用alias直接显示当前shell中定义的所哟别名

[root@VM_168_102_centos tmp]# alias
alias cp
='cp -i'
alias l.
='ls -d .* --color=auto'
alias ll
='ls -l --color=auto'
alias ls
='ls --color=auto'
alias mv
='mv -i'
alias rm
='rm -i'
alias which
='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@VM_168_102_centos tmp]#


  定义指令别名:
  alias 别名=‘原始指令’

[root@VM_168_102_centos tmp]# alias test=ls  
[root@VM_168_102_centos tmp]# test
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
[root@VM_168_102_centos tmp]# alias test
='ls -l'
[root@VM_168_102_centos tmp]# test
total
24
drwxr
-xr-x 2 wanghan root 4096 Aug  4 21:21 2014-08-04-212053
drwxr
-xr-x 3 wanghan root 4096 Aug  4 20:45 a
srwxrwxrwx
1 root    root    0 Aug  9 10:05 agent_cmd.sock
-rw------- 1 root    root  105 Aug  2 11:36 ap_1002.pid
-rw------- 1 root    root    0 Aug  2 09:48 ap_1004.pid
-rw------- 1 root    root  103 Aug  2 11:36 ap_1005.pid
-rw------- 1 root    root    0 Aug  2 10:51 ap_1007.pid
-rw------- 1 root    root    0 Aug  2 10:09 ap_1008.pid
-rw------- 1 root    root    0 Aug  4 13:58 ap_1014.pid
drwxr
-xr-x 2 wanghan root 4096 Aug  4 20:44 ceshi
drwxr
-xr-x 3 wanghan root 4096 Aug  4 20:41 wanghan
[root@VM_168_102_centos tmp]#


  取消指令别名:

[root@VM_168_102_centos tmp]# unalias test
[root@VM_168_102_centos tmp]# tes


  #cat:查看文本文件内容

[root@VM_168_102_centos tmp]# cat /tmp/test.sh
test
[root@VM_168_102_centos tmp]#


  cat -E:在行结尾处显示行结束符

[root@VM_168_102_centos tmp]# cat -E /tmp/test.sh
test$
[root@VM_168_102_centos tmp]#


  cat -n:按行显示顺序编号

[root@VM_168_102_centos tmp]# cat -n /etc/passwd
1    root:x:0:500:root:/root:/bin/bash
2    bin:x:1:1:bin:/bin:/sbin/nologin
3    daemon:x:2:2:daemon:/sbin:/sbin/nologin
4    adm:x:3:4:adm:/var/adm:/sbin/nologin
5    lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
6    sync:x:5:0:sync:/sbin:/bin/sync
7    shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
8    halt:x:7:0:halt:/sbin:/sbin/halt
9    mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
10    uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin

  cat –s:多个连续的空白行显示为一个空白行

[root@VM_168_102_centos tmp]# cat -n test.sh
1    test
2   
3   
4   
5   
6    abc
[root@VM_168_102_centos tmp]# cat
-sn test.sh
1    test
2   
3    abc
[root@VM_168_102_centos tmp]#



  #tac命令:cat的逆序显示方式

[root@VM_168_102_centos tmp]# cat test.sh
test


abc
[root@VM_168_102_centos tmp]# tac test.sh
abc


test
[root@VM_168_102_centos tmp]#


  #more命令:将文件内容按页显示查看
  空格键向下显示一页
  b键向上显示一页
  只能向后翻看
  #less命令:将文件内容按页显示查看
  pageup 向上查看
  pagedown 向下查看
  #head命令:用来显示档案的开头至标准输出中,默认head命令打印其相应文件的开头10行

[root@VM_168_102_centos etc]# head /etc/passwd
root:x:
0:500:root:/root:/bin/bash
bin:x:
1:1:bin:/bin:/sbin/nologin
daemon:x:
2:2:daemon:/sbin:/sbin/nologin
adm:x:
3:4:adm:/var/adm:/sbin/nologin
lp:x:
4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:
5:0:sync:/sbin:/bin/sync
shutdown:x:
6:0:shutdown:/sbin:/sbin/shutdown
halt:x:
7:0:halt:/sbin:/sbin/halt
mail:x:
8:12:mail:/var/spool/mail:/sbin/nologin
uucp:x:
10:14:uucp:/var/spool/uucp:/sbin/nologin

  head –n:显示的行数
  heda –n #
  head –#
  显示文件的前5行:

[root@VM_168_102_centos etc]# head -n 5 /etc/passwd
root:x:
0:500:root:/root:/bin/bash
bin:x:
1:1:bin:/bin:/sbin/nologin
daemon:x:
2:2:daemon:/sbin:/sbin/nologin
adm:x:
3:4:adm:/var/adm:/sbin/nologin
lp:x:
4:7:lp:/var/spool/lpd:/sbin/nologin
[root@VM_168_102_centos etc]# head
-5 /etc/passwd
root:x:
0:500:root:/root:/bin/bash
bin:x:
1:1:bin:/bin:/sbin/nologin
daemon:x:
2:2:daemon:/sbin:/sbin/nologin
adm:x:
3:4:adm:/var/adm:/sbin/nologin
lp:x:
4:7:lp:/var/spool/lpd:/sbin/nologin

  显示文件除了最后N行的内容:
  head –n –#

[root@VM_168_102_centos etc]# head test.sh
1
2
3
4
5
6
7
8
9
10
[root@VM_168_102_centos etc]# head
-n -3 test.sh
1
2
3
4
5
6
7

  #tail命令:用于显示指定文件末尾内容,不指定文件时,作为输入信息进行处理,常用查看日志文件(默认显示10行)

[root@VM_168_102_centos etc]# tail /etc/passwd
abrt:x:
173:173::/etc/abrt:/sbin/nologin
haldaemon:x:
68:68:HAL daemon:/:/sbin/nologin
ntp:x:
38:38::/etc/ntp:/sbin/nologin
saslauth:x:
499:76:"Saslauthd user":/var/empty/saslauth:/sbin/nologin
postfix:x:
89:89::/var/spool/postfix:/sbin/nologin
sshd:x:
74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:
72:72::/:/sbin/nologin
nginx:x:
498:499:Nginx web server:/var/lib/nginx:/sbin/nologin
wanghan:x:
500:0::/home/wanghan:/bin/bash
ceshi:x:
501:501::/home/ceshi:/bin/bash

  tail –n 显示的行数
  tail –n #
  tail -#

[root@VM_168_102_centos etc]# tail -n 3 /etc/passwd
nginx:x:
498:499:Nginx web server:/var/lib/nginx:/sbin/nologin
wanghan:x:
500:0::/home/wanghan:/bin/bash
ceshi:x:
501:501::/home/ceshi:/bin/bash

  tail –n +5 从第N行开始显示

[root@VM_168_102_centos etc]# head test.sh
1
2
3
4
5
6
7
8
9
10
[root@VM_168_102_centos etc]# tail
-n +5 test.sh
5
6
7
8
9
10

  tail –f 循环查看文件内容

[root@VM_168_102_centos ~]# ping www.baidu.com > test.log &
[
1] 12906
[root@VM_168_102_centos
~]# tail -f test.log
64 bytes from 180.97.33.107: icmp_seq=8 ttl=49 time=37.2 ms
64 bytes from 180.97.33.107: icmp_seq=9 ttl=49 time=37.2 ms
64 bytes from 180.97.33.107: icmp_seq=10 ttl=49 time=37.2 ms
64 bytes from 180.97.33.107: icmp_seq=11 ttl=49 time=37.3 ms
64 bytes from 180.97.33.107: icmp_seq=12 ttl=49 time=39.4 ms
64 bytes from 180.97.33.107: icmp_seq=13 ttl=49 time=37.2 ms
64 bytes from 180.97.33.107: icmp_seq=14 ttl=49 time=37.3 ms
64 bytes from 180.97.33.107: icmp_seq=15 ttl=49 time=37.1 ms
64 bytes from 180.97.33.107: icmp_seq=16 ttl=49 time=37.2 ms

  #echo在显示器上显示一段文字,一般起到一个提示的作用。

[root@VM_168_102_centos etc]# echo abc  
abc


  echo –n:不要自动换行

[root@VM_168_102_centos etc]# echo -n `tail test.sh`
1 2 3 4 5 6 7 8 9 10[root@VM_168_102_centos etc]#

  echo 颜色控制:
  格式: echo -e "\033[字背景颜色;字体颜色m字符串\033[0m"

[root@VM_168_102_centos ~]# echo -e "\033[41;36m hello \033[0m"
hello
[root@VM_168_102_centos
~]# echo -e "\033[36m hello \033[0m"
hello
[root@VM_168_102_centos
~]# echo -e "\033[40;36m hello \033[0m"
hello

运维网声明 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-480475-1-1.html 上篇帖子: Linux 设置 DNS 下篇帖子: Linux分区的认识
累计签到:544 天
连续签到:1 天
发表于 2018-5-24 08:54:04 | 显示全部楼层
谢谢楼主分享

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

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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