Linux Shell Scripting Cookbook 读书笔记 6

wget,curl, tar, rsynchtml

wget ftp://example.com/somefile.img -t 5 -O download.img -o loggit

-t表示重试的次数算法

-O指定输出文件名cookie

-o指定一个日志文件app

wget -c URLcurl

断点续传,若是下载在完成前被中断,能够用-c从断点处开始下载svn

 

用curl指定参考页,指定cookiepost

curl -I --referer http://www.baidu.com https://www.cnblogs.com --cookie "user=xxx;pass=xxx"加密

用curl指定头部信息url

curl -H "Host:www.test.org" -H "Accept-language:en" URL

用curl进行认证

curl -u user:password http://www.test.org

curl -u user http://www.test.org #须要手动输入密码

发送post请求

curl -d "key1=var1&key2=var2"  URL -o output.html

 

tar命令自己只是归档功能,若是要压缩,须要指定压缩格式

-z gzip

-j bunzip

--lzma  lzma

其中-a选项能够经过归档文件的扩展名自动判断压缩格式

例如: tar -cavf file.tar.gz file1 file2

tar追加文件

tar -rvf original.tar new_file

因为tar命令可接受的参数有限,若是文件不少,能够考虑用-r

FILE_LIST="file1 file2 file3 file4......."

for f in $FILE_LIST;

do

tar -rvf file.tar $f

done;

gzip -9 file.tar #-9压缩率最高,-1速度最快

显示tarball里面的文件

 

-v 或者-vv用来显示更多细节

将文件名指定为命令行参数来提取特定的文件

tar -xvf file.tar file1 file2  #该命令只提取file1 file2

拼接两个归档文件

tar -Af file1.tar file2.tar   #将file2.tar的内容合并到file1.tar中

比较归档文件与本地文件差异

tar -df file.tar file1 file2

file1: Mod time differs

file2: Size differs

从归档文件中删除文件

tar -f file.tar --delete file1 file2

从归档文件中排除部分文件

tar -cf file.tar * --exclude "*.txt" #归档除了txt文件之外的全部文件

排除版本控制目录,如.git,.svn

tar --exclude-vcs -czvf file.tar * 

 

rsync备份

rsync is a file transfer program capable of efficient remote update
via a fast differencing algorithm.

相对于cp命令,rsync使用了高效的差别算法,而且会比较源端与目的端的差别,只有当文件有更新才会复制。

rsync也支持压缩,加密

rsync -av /opt/myapp sryan@192.168.10.10:/tmp/

相关文章
相关标签/搜索