一些有用的Linux工具和命令

新浪微博 QQ空间

1、查看进程树:ps aufx,可以看到进程的派生关系、运行用户、启动时间、耗时和内存CPU等进程状态。

ps aufx

2、查看文本文件内容,并显示行号:nl,对比cat命令的效果如下:

root@shentar-raspberry:~# cat abc.txt 
a
bcd
cdef
123
root@shentar-raspberry:~# nl abc.txt 
 1 a
 2 bcd
 3 cdef
 4 123
root@shentar-raspberry:~# cat abc.txt |nl -
 1 a
 2 bcd
 3 cdef
 4 123

3、格式化xml文件输出:xmllint,按照规整的xml格式输出内容。

root@shentar-raspberry:~# cat a.xml 
<?xml version="1.0" encoding="utf-8"?>
<!--
picfilesuffix the file type with the suffix that can be scaned by the tool. It is ignorecase. 
inputdir specify the folder which nedd to scan.
minfilesize specify the min size of Pic file in byte.
maxpicsperonepage specify the max pic count of one index page.
threadcount specify the size of thread pool.
hashalog specify the file HASH fingerprint Algorithm. The common algorithms are: SHA-256, MD5, SHA-1. You can find the stand algorithm names in MessageDigest Algorithms.
excludedir specify the folder which you do not like the tool scan and display the content of it.
thumbnaildir specify the folder which to store the thumbnail to.-->
<config>
<picfilesuffix>
<suffix>jpg</suffix>
<suffix>jpeg</suffix>
<suffix>png</suffix>
</picfilesuffix>
<minfilesize>51200</minfilesize>
<maxfilesize>512000000</maxfilesize>
<threadcount>20</threadcount>
<maxpicsperonepage>25</maxpicsperonepage>
<hashalog>MD5</hashalog>
<accessAuth>true</accessAuth>
<inputdir>
<dir>D:\\</dir>
<dir>C:\\</dir>
</inputdir>
<excludedir>
<dir>C:\\windows\\</dir>
<dir>C:\\Program Files\\</dir>
<dir>./</dir>
</excludedir>
</config>
root@shentar-raspberry:~# cat a.xml |xmllint --format -
<?xml version="1.0" encoding="utf-8"?>
<!--
picfilesuffix the file type with the suffix that can be scaned by the tool. It is ignorecase. 
inputdir specify the folder which nedd to scan.
minfilesize specify the min size of Pic file in byte.
maxpicsperonepage specify the max pic count of one index page.
threadcount specify the size of thread pool.
hashalog specify the file HASH fingerprint Algorithm. The common algorithms are: SHA-256, MD5, SHA-1. You can find the stand algorithm names in MessageDigest Algorithms.
excludedir specify the folder which you do not like the tool scan and display the content of it.
thumbnaildir specify the folder which to store the thumbnail to.-->
<config>
  <picfilesuffix>
    <suffix>jpg</suffix>
    <suffix>jpeg</suffix>
    <suffix>png</suffix>
  </picfilesuffix>
  <minfilesize>51200</minfilesize>
  <maxfilesize>512000000</maxfilesize>
  <threadcount>20</threadcount>
  <maxpicsperonepage>25</maxpicsperonepage>
  <hashalog>MD5</hashalog>
  <accessAuth>true</accessAuth>
  <inputdir>
    <dir>D:\\</dir>
    <dir>C:\\</dir>
  </inputdir>
  <excludedir>
    <dir>C:\\windows\\</dir>
    <dir>C:\\Program Files\\</dir>
    <dir>./</dir>
  </excludedir>
</config>
root@shentar-raspberry:~# 

4、相应的json格式输出,则需要使用json工具包,python –m json.tool:

root@shentar-raspberry:~# cat /root/.mozilla/firefox/7dfkbioj.default/sessionCheckpoints.json
{"profile-after-change":true,"final-ui-startup":true,"sessionstore-windows-restored":true,"quit-application-granted":true,"quit-application":true,"sessionstore-final-state-write-complete":true,"profile-change-net-teardown":true,"profile-change-teardown":true,"profile-before-change":true}
root@shentar-raspberry:~# cat /root/.mozilla/firefox/7dfkbioj.default/sessionCheckpoints.json|python -m json.tool
{
    "final-ui-startup": true,
    "profile-after-change": true,
    "profile-before-change": true,
    "profile-change-net-teardown": true,
    "profile-change-teardown": true,
    "quit-application": true,
    "quit-application-granted": true,
    "sessionstore-final-state-write-complete": true,
    "sessionstore-windows-restored": true
}
root@shentar-raspberry:~#

5、查看目录大小,递归查询指定目录的大小,指定显示深度:du -max-depth=1 –h

root@shentar-raspberry:~# du --max-depth=1 -h
22M    ./.sync
156K    ./.local
4.0K    ./文档
392K    ./.rpmdb
4.0K    ./.dist
122M    ./jetty-distribution-8.1.17.v20150415
4.0K    ./视频
12M    ./.mozilla
6.7M    ./.cache
8.0K    ./.ssh
4.0K    ./桌面
160K    ./.config
8.0K    ./.vim
4.0K    ./下载
20K    ./.dbus
4.0K    ./模板
27M    ./psiphon
20K    ./.gnupg
12K    ./.oracle_jre_usage
132M    ./s3curl-4win
101M    ./.m2
4.0K    ./音乐
4.0K    ./公共的
4.0K    ./.themes
4.0K    ./.icons
4.0K    ./.gconf
4.0K    ./图片
280K    ./.kodi
56K    ./.vnc
4.0K    ./.nano
515M    .
root@shentar-raspberry:~# 

6、使用ping快速检查丢包率:ping -f -c 1000 example.com,-f为倾倒式的发送icmp包,-c指定次数。Windows下的ping命令无此参数选项,可以下载cygwin下的ping命令实现。

root@shentar-raspberry:~# ping -f -c 1000 example.com 
PING example.com (93.184.216.34) 56(84) bytes of data.
................                          
--- example.com ping statistics ---
1000 packets transmitted, 984 received, 1% packet loss, time 12018ms
rtt min/avg/max/mdev = 283.280/293.537/303.682/3.957 ms, pipe 27, ipg/ewma 12.030/296.774 ms

7、watch命令,循环运行指定命令,并将执行结果刷新到屏幕上:watch -t -c -n 1 "date",每间隔1秒执行一次date命令。

新浪微博 QQ空间

| 1 分2 分3 分4 分5 分 (5.00- 4票) Loading ... Loading ... | 这篇文章归档在:实用脚本, 软件技术 | 标签: , , , , , , . | 永久链接:链接 | 评论(0) |

评论

邮箱地址不会被泄露, 标记为 * 的项目必填。

8 - 2 = *



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <img alt="" src="" class=""> <pre class=""> <q cite=""> <s> <strike> <strong>

返回顶部