用proc收集信息
cat /proc/4295/environ
readlink /proc/4295/cwd cwd是一个到进程工作目录的符号链接
/proc/4295/fd fd由进程所使用的文件描述符
ps命令
ps -eo pid,comm,pcpu,pmem | head
根据参数排序,例如
ps -eo comm,pcpu --sort -pcpu | head
加号升序,减号降序
pgrep bash 列出所有Bash进程的进程ID
trap命令
通过这个命令为信号分配处理程序,例如 trap 'handler' SIGINT
在本地挂载点上挂载远程目录
sshfs user@remotehost:/home/path /mnt/mountpoint
umount /mnt/mountpoint
找出指定目录中最大的10个文件
du -ak /home/ubuntu/ |sort -nrk 1 | head
查看网络端口
netstat -tnp
lsof -i
散列命令 sha1num, md5sum, base64
加密命令 gpg, crypt
gpg -c filename加密文件
gpg filename 解密文件
grep命令
递归搜索文件 grep "text" . -R -n
匹配多个pattern. grep -e "pattern1" -e "pattern2"
只在目录中递归搜索所有的.c和.cpp文件
grep "main()" . -r --include *.{c,cpp}
其他
tr 命令 删除字符串,替换字符串
chattr +i file 设置文件为不可以修改
xargs 可以把多行输入转成单行输出,也可以把单行输入缓存多行输出。
echo -e "1\n2\n3" | xargs
echo -e "1\n2\n3\n4\n5" | xargs -n 2
-0参数的作用如下:
-0 Change xargs to expect NUL (``\0'') characters as separators, instead of spaces and newlines. This is expected
to be used in concert with the -print0 function in find(1).
csplit 能够根据字符串来分割文件,split只能根据数据大小和行数来分割文件