Linux Shell Scripting Cookbook 读书笔记 6

wget,curl, tar, rsync

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

-t表示重试的次数

-O指定输出文件名

-o指定一个日志文件

wget -c URL

断点续传,如果下载在完成前被中断,可以用-c从断点处开始下载

 

用curl指定参考页,指定cookie

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

用curl指定头部信息

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/

 

posted @ 2018-07-14 16:31  平静缓和用胸音说爱  阅读(168)  评论(0编辑  收藏  举报