#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