代码改变世界

实用脚本汇总

shell

内存占用排序

ps aux | head -1;ps aux | grep -v PID | sort -rn -k +4 | head

python

显示文件全路径

类似Linux下的realpath命令

#!/usr/bin/env python
# Get the full absolute path (realpath) of args
import sys
import os
for path in sys.argv[1:]:
      print os.path.realpath(path)

格式化JSON

echo '{"key": "value"}' | python3 -m json.tool

command

命令行操作剪贴板

# Mac系统 命令行复制文件内容到剪贴板
pbcopy < filename  或  cat filename | pbcopy

# Mac系统 命令行粘贴剪贴板中的内容到文件
pbpaste > filename

# Linux系统 安装xsel
sudo apt-get install xsel

# Linux系统 拷贝到剪贴板
cat file.txt | xsel -b

# Linux系统 从剪贴板粘贴
xsel -b >> example.txt
posted @ 2020-08-22 11:37  行无际  阅读(298)  评论(0)    收藏  举报