linux常用命令

查询配置文件有用信息且显示行号可上下翻页

[root@nmserver-7 ~]# cat /etc/ssh/sshd_config |egrep '^[a-Z]'|nl|less
     1  HostKey /etc/ssh/ssh_host_rsa_key
     2  HostKey /etc/ssh/ssh_host_ecdsa_key
     3  HostKey /etc/ssh/ssh_host_ed25519_key
     4  SyslogFacility AUTHPRIV
     5  AuthorizedKeysFile      .ssh/authorized_keys
     6  PasswordAuthentication yes
     7  ChallengeResponseAuthentication no
     8  GSSAPIAuthentication yes
     9  GSSAPICleanupCredentials no
    10  UsePAM yes
:

检查文件类型

[root@nmserver-7 zabbix]# file /etc/init.d/network 
/etc/init.d/network: Bourne-Again shell script, ASCII text executable
[root@nmserver-7 zabbix]# file zabbix-3.2.7
zabbix-3.2.7: directory
[root@nmserver-7 zabbix]# file zabbix-3.2.7.tar.gz 
zabbix-3.2.7.tar.gz: gzip compressed data, from Unix, last modified: Tue Jul 18 18:42:29 2017, max compression

 

 监视日志文件

[root@nmserver-7 zabbix]# tail -f /var/log/cron
Aug 14 10:13:04 nmserver-7 run-parts(/etc/cron.daily)[2594]: finished logrotate
Aug 14 10:13:04 nmserver-7 run-parts(/etc/cron.daily)[2579]: starting man-db.cron
Aug 14 10:13:06 nmserver-7 run-parts(/etc/cron.daily)[2611]: finished man-db.cron
Aug 14 10:13:06 nmserver-7 anacron[2562]: Job `cron.daily' terminated
Aug 14 10:33:02 nmserver-7 anacron[2562]: Job `cron.weekly' started
Aug 14 10:33:02 nmserver-7 anacron[2562]: Job `cron.weekly' terminated
Aug 14 10:53:02 nmserver-7 anacron[2562]: Job `cron.monthly' started
Aug 14 10:53:02 nmserver-7 anacron[2562]: Job `cron.monthly' terminated
Aug 14 10:53:02 nmserver-7 anacron[2562]: Normal exit (3 jobs run)

 

快速备份一个文件

cp filename{,.bak}

[zhi@nmserver-7 ~]$ cp a{,.bak}
[zhi@nmserver-7 ~]$ ls
a  a.bak
[zhi@nmserver-7 ~]$ 

普通用户打开文档不能保存

tee是一个把stdin保存到文件的小工具,而%,是vim当中一个只读寄存器的名字,总保存着当前编辑文件的文件路径

:w !sudo tee %

按名字查找文件传递给-exec后命令

[root@nmserver-7 ~]# find /etc/ -name 'passwd' -exec grep "zhi" {} \;
zhi:x:1000:1000:zhi:/home/zhi:/bin/bash

 

查找文件名,不取路径

[root@nmserver-7 ~]# find /root/zabbix/  -name 't*' -exec basename {} \;
telnet.h
threads.h
tr_comments.php
tr_events.php
toptriggers.php
tr_logform.js
touch-icon-192x192.png
triggers.inc.php
translateDefines.inc.php
triggers
tree
templates.php
tr_logform.php
tr_testexpr.php
tr
tree
tr_top_bottom.gif
tr_space.gif
tr_top_right.gif
tr_top_right_bottom.gif
triggers.php
trigger_prototypes.php
tr_status.php
touch-icon-192x192.png
template_item.c
template.h
trigger.c
tls.c
tls.h
tls_tcp.h
tls_tcp_active.h
telnet.c
telnet.Po
telnet.o
threads.c
threads.Po
threads.o
timer
timer.c
timer.h
timer.Po
timer.o
trapper
trapper.c
trapper.h
trapper.Po
trapper.o
taskmanager
taskmanager.c
taskmanager.h
taskmanager.Po
taskmanager.o
tru64
[root@nmserver-7 ~]# 

 

软件管理

[zhi@nmserver-7 ~]$ tar -cvf a.tar  /home/zhi/a  # 打包tar
tar: 从成员名中删除开头的“//home/zhi/a
[zhi@nmserver-7 ~]$ tar -rvf a.tar  ./testa  # 给tar追加文件
./testa
[zhi@nmserver-7 ~]$ ls
a  a.tar  testa

 

 

[zhi@nmserver-7 ~]$ tar tvpf  a.tar  #查看tar包
-rw-rw-r-- zhi/zhi       10240 2017-08-14 12:34 home/zhi/a
-rw-r--r-- root/root         0 2017-08-14 11:45 home/zhi/testa

[zhi@nmserver-7 ~]$ gzip -v a.tar # 压缩tar到gz
a.tar:     99.2% -- replaced with a.tar.gz
[zhi@nmserver-7 ~]$ ls
a  a.tar.gz  testa
[zhi@nmserver-7 ~]$
[zhi@nmserver-7 ~]$ tar --exclude /home/zabbix/ -zcvf  home.tar.gz  /hom/* #打包/home,但排除/home/zabbix;
[zhi@nmserver-7 ~]$ ls
a  a.tar.gz  home.tar.gz  testa

 

系统管理

终端锁屏 Ctrl+s

解锁屏    Ctrl+q

查找命令目录

whereis

查看当前要的执行的命令所在的路径

which

让命令在后台运行

命令 &
将前台程序放入后台(暂停)

ctrl+z

查看后台运行的程序

Jobs

后台运行不受shell 退出影响

nohup cmd &

清空整个屏幕

clear

ctrl+L

查看登陆过的用户信息

last

last -n user

who  /var/log/wtmp

防火墙日志

tail -f /var/log/messages

ssh日志

tail -f /var/log/secure

随机生成密码

mkpasswd

-l 位数  -C 大写 -c 小写 -d 数字 -s 特殊字符

 

posted @ 2017-08-14 15:03  JUSTZHI  阅读(466)  评论(0编辑  收藏  举报