Weitere ähnliche Inhalte
Ähnlich wie 常用Mac/Linux命令分享 (20)
常用Mac/Linux命令分享
- 2. Linux 知 深似海识 ...
• http://www.aqee.net/useful-unix-commands-for-data-scienc
• cat data.csv | awk -F “|” ‘{ sum += $4 } END
{ printf “%.2fn”, sum }’
• awk -F "|" '{ sum += $4 } END { printf "%.2fn",
sum }' < data.csv
• awk -F "|" '{ sum += $4 } END { printf "%.2fn",
sum }' data.csv
• 《 Unix 程 》编 艺术
- 5. 基 知础 识
• 文件系统
• 根目录 /
• 用 目户 录 ~ /Users/xxx
• 一些配置常常保存在 ~/.xxx 里 ( 有一个还
地方是 /etc/)
• 例如 .m2 .bashrc .vimrc
• 藏文件 以”隐 .” 始的文件开
- 6. 境 量环 变
• PATH
• 些目 下的可 行程序无 完整路这 录 执 须
径
• /[s]bin/: /usr/[s]bin:/usr/local/[s]bin
• XX_HOME
• JAVA_HOME JAVA_PATH
- 9. 管道
• 重定向到文件 > &> 1> 2>
• 准 入标 输 0 准 出标 输 1 出错误输 2
• curl http://www.dianping.com/ >
index.html
• 重定向到 用程序应 |
• curl
http://code4craft.github.io/blackhole/install.sh |
sh
- 10. 基 知础 识
• 常用工具安装
• apt/yum
• homebrew (mac)
• 需要安装 gcc(Xcode 或者 command
line tools)
• brew install
- 11. 基 命令础 - 目 相录 关
• cd
• cd -
• ls
• ls -a -l -h -R
• pwd
• `pwd`
- 12. 基 命令础 - 控制台输
出
• cat
• more less
• head tail -n
• echo
• open (in Mac)
- 14. 基 命令础 - 文件操作
• mkdir
• mkdir -p
• cp/scp
• cp -r
• touch
- 15. 基 命令础 - 文件操作
• mv
• rm
• rm -rf
• ln
• ln -s from to ( 路径名绝对 )
• unlink
- 16. 常用命令 - 权限修改
• chmod
• chmod -R 755
• chown
• chown user:group file
- 17. 压缩 / 解压缩
• tar
• tar -czf soure output
• tar -xzf file
• unzip
• rar?
• mac rar http://rar.cn.uptodown.com/mac
- 18. 找文件查
• spotlight (in Mac)
• find
• find path -name “*.xxx”
• which find in PATH
• grep
• grep -r -v -F -e
- 20. 编码
• md5(in Mac) / md5sum(in Linux)
• md5 file
• md5 -s “xxxx”
• base64
• base64 file
• echo “xxx” | base64 -D
- 22. 系 控统监
• Activity monitor (in Mac)
• ps
• ps -ef | grep java
• top
• -pid -H
• iostat free sar dstat..
- 23. 网 相络 关
• telnet
• telnet host port
• ] ctrl+d
• nslookup
• dig
- 24. 网 相络 关
• rsync
• rsync -avz --delete source target
• 性能 于优 scp
• curl
• wget(not installed in Mac)
- 26. 文本 理处
• awk
• awk -F ',' '{print $0}' file
• awk '!i[$0]++' 去掉重 行复
• sed
• 不怎么会,大家知道就好 ...
- 28. 瑞士 刀军
• lsof
• lsof -i:port
• netcat
• netcat -lp 8888 -e xxx
• netcat host port
• 用法取决于你的想象力
- 31. shell 脚本格式
• 第一行 #!/bin/sh
• 指定 行脚本的程序执
• #!/bin/python ...
• 注意空格和 行!请 换
• a=”xxx” ✔
• a = “xxx” ✖
- 34. 保留字符
• (())
• 算数 算运
• for ((i=0;i<100;i++))
• command&
• 步 行异 执
• nohup & 步异 + 后台 行执
- 36. 判断逻辑
• if .. then .. else/elif .. fi
• 其 是根据程序退出状 判断实 态
• 条件判断逻辑 -test 表 式达
• if test “xx” == “xx”
• if [ “xx” == “xx” ]
• [[]] 内置判断,更强大
- 38. 循环
• for x [in array] do .. done
• for f in `ls`
• for f in *.java
• for ((i=0;i<100;i++))
- 39. 循环
• while .. do .. done
• until .. do .. done
• break
• break n 退出的 数层
• continue
- 40. 入输 / 出输
• 参数: $0~${n}
• $# 参数个数 $@ 参数数组
• read
• read varname
• echo
• printf
- 41. 函数
• 定 :义 functionName()
• 参数不写在声明中,而是用 $n 用调
• return
• 用:调
• functionName param1 param2