linux基础命令

1.ls list(列表) 列举目录和文件

参数

-r 倒序

-t 按照修改时间排序

-i inode print the index number of each file 显示文件的索引号

-h with -l, print sizes in human readable format (e.g., 1K 234M 2G)以易读的格式显示,和-l一起使用

$ls -lih /var/log/
总用量 4.0M
390163 -rw-------. 1 root root 4.5K 9月  16 19:42 anaconda.ifcfg.log
390152 -rw-------. 1 root root  22K 9月  16 19:42 anaconda.log
390158 -rw-------. 1 root root  32K 9月  16 19:42 anaconda.program.log
390162 -rw-------. 1 root root 147K 9月  16 19:42 anaconda.storage.log
390156 -rw-------. 1 root root 139K 9月  16 19:42 anaconda.syslog
390157 -rw-------. 1 root root  33K 9月  16 19:42 anaconda.xlog
390164 -rw-------. 1 root root  54K 9月  16 19:42 anaconda.yum.log

实例

ls -lrt

--color=auto 颜色

\ls --color=auto  #\取消别名:ls='ls --color=auto'

格式化属性时间

#ls -l --time-style=long-iso /data/
total 32
drwxr-xr-x. 26 root root 4096 2018-09-27 13:33 3
drwxr-xr-x. 26 root root 4096 2018-09-27 13:33 4
drwxr-xr-x. 26 root root 4096 2018-09-27 13:33 5
drwxr-xr-x. 26 root root 4096 2018-09-27 13:33 6
drwxr-xr-x. 26 root root 4096 2018-09-27 13:33 7
drwxr-xr-x.  2 root root 4096 2018-09-30 12:17 oldboy
-rw-r--r--.  1 root root    8 2018-09-29 14:24 test
-rw-r--r--.  1 root root    9 2018-09-29 14:24 test.bak

2.wc 

参数

-l(lines) 显示总行数

ps -ef | grep "/sshd"  | grep -v "grep" | wc -l 
#返回1,则ssh服务存活,否则,ssh服务已经挂了。

 

-L 显示字符数 

echo "abcd" | wc -c #结果为4

 3.chkconfig-管理系统自启动服务的命令

chkconfig --list  [服务名] 查看服务在哪个级别开机启动,默认是所有服务

$sudo chkconfig --list sshd
sshd            0:off   1:off   2:off   3:on    4:off   5:off   6:off

chkconfig [--level <levels>] <服务名>  <on|off>

$sudo chkconfig --level 4 sshd on 
[leiyf@leiyangfeng ~]
$chkconfig --list sshd
sshd            0:off   1:off   2:off   3:on    4:on    5:off   6:off

4. cut 切割,取列

-d 指定分隔符

$ifconfig eth0 | grep "inet addr:" | cut -d ":" -f2 | cut -d " " -f1
192.168.216.129

-c 字符

$ifconfig eth0 | grep "inet addr:" | cut -c 21-35
192.168.216.129

-f 取列

5.tr 逐个字符替换

$echo "abcde" | tr "abc" "123"
123de

 6.file

查看文件的类型,如下:

$file data/leiyf.txt 
data/leiyf.txt: empty  #空文件
[leiyf@leiyangfeng ~]
$file data/leiyf/leiyf.txt
data/leiyf/leiyf.txt: ASCII text #文本文件
[leiyf@leiyangfeng ~]
$file /bin/cat 
/bin/cat: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
#二进制文件
[leiyf@leiyangfeng ~]
$file /var/log/lastlog 
/var/log/lastlog: data #数据文件

7.lastlog 显示最近登陆的用户信息,对应的是/var/log/lastlog数据文件

8.last  显示用户登录信息,对应的是/var/log/wtmp数据文件

9.tree 大树的意思,显示目录树,-L layer层数,-d显示目录

显示~data目录下的第一层子目录,如下:

[leiyf@leiyangfeng ~]
$tree -Ld 1 data/
data/
└── leiyf

 

posted on 2018-10-02 18:13  licker  阅读(197)  评论(0编辑  收藏  举报

导航