linux 常用技巧

Bash 操作快捷键:
ctrl-l -- clear screen
ctrl-r -- does a search in the previously given commands so that you don't
have to repeat long command.
ctrl-u -- clears the typing before the hotkey.
ctrl-a -- takes you to the begining of the command you are currently typing.
ctrl-e -- takes you to the end of the command you are currently typing in.
esc-b -- takes you back by one word while typing a command.
ctrl-c -- kills the current command or process.
ctrl-d -- kills the shell.
ctrl-h -- deletes one letter at a time from the command you are typing in.
ctrl-z -- puts the currently running process in background, the process
can be brought back to run state by using fg command.
esc-p -- like ctrl-r lets you search through the previously given commands.
esc-. -- gives the last command you typed.
!!       -- 执行上一个命令
!m     -- 执行上一个以m开头的命令
!9      -- 执行history中编号为9的命令


ls命令的几个技巧:
按时修改间(modification time)排序:ls -t, ls -lt, ls -Ct
按访问时间(access time)排序:ls -u
按文件大小排序:ls -lS

cd命令技巧:

cd -           #回到上次所在目录
cd !$        #把上个命令的参数作为输入
cd             #回到主目录
cd ~         #同样回到主目录
cd ..          #返回上级目录(若当前目录为“/“,则执行完后还在“/";".."为上级目录的意思)
cd ../..       #返回上两级目录


查看系统信息 :
cat /proc/cpuinfo - CPU (i.e. vendor, Mhz, flags like mmx) 
cat /proc/interrupts - 中断 
cat /proc/ioports - 设备 IO端口 
cat /proc/meminfo - 内存信息(i.e. mem used, free, swap size) 
cat /proc/partitions - 所有设备的所有分区 
cat /proc/pci - PCI设备的信息 
cat /proc/swaps - 所有 Swap 分区的信息 
cat /proc/version - Linux 的版本号 相当于 uname -r 
uname -a - 看系统内核等信息

lsof 用法技巧:
lsof abc.txt            #显示开启文件 abc.txt 的进程 
lsof -i :22              #显示 22 端口现在运行什么程序 
lsof -c vim            #显示 vim 进程现在打开的文件 
lsof -g                  #gid 显示归属 gid 的进程情况 
lsof +d /proc        #显示目录下被进程开启的文件 
lsof +D /proc        #同上,递归搜索目录下的目录,时间较长 
lsof -d 4               #显示使用 fd 为4 的进程
lsof -p 12             #看进程号为 12的进程打开了哪些文件
lsof -n                  #不将 IP转换为 hostname,预设是不加上-n参数

lsof -i 
               #用以显示符合条件的进程情况 
语法: lsof -i[46] [protocol][@hostname|hostaddr][:service|port]
[46] --> IPv4 or IPv6 
[protocol] --> TCP or UDP 
[hostname] --> Internet host name 
[hostaddr] --> IPv4 位置 
[service] --> /etc/service中的 service name (可多个) 
[port] --> 端口号(可多个)
eg:
lsof -i TCP:80  # 查看TCP协议占用80端口的进程信息
lsof -i 4            #查看IPV4协议占用信息
lsof -i TCP:80 -i TCP:25 -i UDP 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值