linux常用命令总结

Administrator
发布于 2020-03-27 / 420 阅读 / 0 评论 / 0 点赞

linux常用命令总结

1、pgrep

image.png
类似于

 ps -ef | grep java | grep -v grep| awk '{print $2}'
[root@hzy ~]#  ps -ef | grep java | grep -v grep| awk '{print $2}'
2818
31912
[root@hzy ~]# 

2、 pstree

[root@hzy ~]# pstree
systemd─┬─YDLive───{YDLive}
        ├─YDService───12*[{YDService}]
        ├─acpid
        ├─2*[agetty]
        ├─atd
        ├─auditd───{auditd}
        ├─barad_agent─┬─barad_agent
        │             └─barad_agent───2*[{barad_agent}]
        ├─crond
        ├─dbus-daemon
        ├─java───61*[{java}]
        ├─java───40*[{java}]
        ├─lsmd
        ├─lvmetad
        ├─mysqld───52*[{mysqld}]
        ├─nginx───nginx
        ├─ntpd
        ├─polkitd───5*[{polkitd}]
        ├─redis-server───3*[{redis-server}]
        ├─rsyslogd───2*[{rsyslogd}]
        ├─sgagent───{sgagent}
        ├─sshd───sshd───sshd───bash───su───bash───pstree
        ├─svnserve
        ├─systemd-journal
        ├─systemd-logind
        ├─systemd-udevd
        └─tuned───4*[{tuned}]

3、date

在lin ux下可以用date命令轻松完成时间戳和时间的转换。
1、获取当前时间戳

[root@hzy var]# date  +%s
1585670486

2、将时间戳转换成可辨别的时间

[root@hzy var]# date -d @1585670640
Wed Apr  1 00:04:00 CST 2020

3、其他具体应用可以参看date的使用说明

[root@hzy var]# date  --h
Usage: date [OPTION]... [+FORMAT]
  or:  date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
Display the current time in the given FORMAT, or set the system date.

Mandatory arguments to long options are mandatory for short options too.
  -d, --date=STRING         display time described by STRING, not 'now'
  -f, --file=DATEFILE       like --date once for each line of DATEFILE

·····

Show the time on the west coast of the US (use tzselect(1) to find TZ)
  $ TZ='America/Los_Angeles' date

Show the local time for 9AM next Friday on the west coast of the US
  $ date --date='TZ="America/Los_Angeles" 09:00 next Fri'

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'date invocation'


4、egrep

对于grep应该都很熟悉,这也是对grep的灵活运用,查找文件中是否含有关键字,对于项目配置文件中查找很方便。
-n是显示localhost所在文件的行数,可以很快定位到关键字所在位置。

[root@hzy opt]# egrep -n  localhost
nginx.conf:60:           server localhost:8080  weight=1;
nginx.conf:61:	   server localhost:8080  weight=1;
nginx.conf:65:           server localhost:8088 weight=1;
nginx.conf:66:	   server localhost:8088 weight=1;
nginx.conf:69:	   server localhost:8089;
nginx.conf:126:		proxy_pass http://localhost:8080;


评论