sh shell脚本函数和unix实用程序

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh shell脚本函数和unix实用程序相关的知识,希望对你有一定的参考价值。

# Find which linux distribution
cat /etc/*release

# diff- generate patch file
diff -Naur original fork > patch.txt

# diff exclude certain files
# http://stackoverflow.com/a/3775636
# -x or --exclude
diff -x '*.foo' -x '*.bar' -x '*.baz' /destination/dir/1 /destination/dir/2
  
# rsync files over ssh
# source: http://stackoverflow.com/a/9090859
# run from local machine :
rsync -chavzP --stats user@remote.host:/path/to/copy /path/to/local/storage
# run from remote machine if local machine has ssh daemon:
rsync -chavzP --stats /path/to/copy user@host.remoted.from:/path/to/local/storage

# Use wget to scan a webpage for broken links
# https://www.digitalocean.com/community/tutorials/how-to-find-broken-links-on-your-website-using-wget-on-debian-7
wget --spider --recursive --no-directories --no-verbose --span-hosts --level=1 --wait=2 --output-file=wget.log <URL>
# http://www.commandlinefu.com/commands/view/8234/check-broken-links-using-wget-as-a-spider
wget --spider --execute robots=off --wait 1 --recursive --page-requisites --output-file=wget.log  <URL>

# wget all files linked from a page
http://stackoverflow.com/a/13574050
wget --recursive --no-parent --level=1 --accept=<list of file extenstions> http://example.com/download/

# redirect all output to file
# http://stackoverflow.com/a/6674348
foo > allout.txt 2>&1

# run all python unit tests in a dir
# http://stackoverflow.com/a/15630454
python -m unittest discover <test_directory>

# run puppet and apply configs
puppet agent -t

# to double check SSL related server errors
# http://askubuntu.com/a/116059
openssl s_client -connect localhost:8000
# specifying cert files etc
openssl s_client -connect localhost:8000 -cert client.cert.pem -key client.key.pem -state -CAfile rootCA.pem

# validate and pretty print json file to console
python -m json.tool foo.json


# Get file perms in octal form
# http://askubuntu.com/a/152003
stat -c "%a %n" *

# delete files from accidentally extracted tar
# http://www.commandlinefu.com/commands/view/2573/remove-all-files-previously-extracted-from-a-tar.gz-file.
tar -tf <file.tar.gz> | xargs rm -r


# cd into realpath instead of symlinked dir
# https://stackoverflow.com/a/2299208
cd -P <dir>
pwd -P 

以上是关于sh shell脚本函数和unix实用程序的主要内容,如果未能解决你的问题,请参考以下文章

UNIX shell 脚本中的“#!/bin/sh”行是啥意思?

shell脚本调试技巧

在 Unix shell 脚本中设置退出代码

UNIX系统之shell 脚本之源

UNIX系统之shell 脚本之源

Unix shell 脚本 - 使用 /bin/sh shell 查找以前的日期