Aliens

Linux命令技巧

April 3, 2021

tar

1.压缩文件夹时忽略.git

1
tar --exclude-vcs -zcvf foo.tar.gz ./FOLDER_NAME

https://unix.stackexchange.com/questions/18657/tar-a-folder-without-git-files

2.多线程压缩

使用pigz实现多线程压缩

1
2
3
4
tar --use-compress-program="pigz --best --recursive" -cf archive.tar.gz YourData

# 显示压缩进度
tar --use-compress-program="pigz --best --recursive | pv" -cf archive.tar.gz YourData

https://stackoverflow.com/questions/36917882/how-to-use-pigz-with-tar

wget 命令

将下载的结果输出到命令行:

1
2
3
wget -qO- http://whatever.com/page.php
# 或者
wget -qO /dev/null http://whatever.com/page.php

https://superuser.com/questions/321240/how-do-you-redirect-wget-response-to-standard-out

运行来自url的shell脚本

以下命令仅在bash中测试过:

不带参数:

1
2
3
4
5
6
7
curl -sSL http://mywebsite.com/myscript.txt | bash
# 或者
wget -qO- http://mywebsite.com/myscript.txt | bash
# 或者
bash <(wget -qO- http://mywebsite.com/myscript.txt)
# 或者
source <(curl -s http://mywebsite.com/myscript.txt)

带参数:

1
2
3
4
5
curl -sSL http://mywebsite.com/myscript.txt | bash -s arg1 arg2
# 或者
curl -sSL http://mywebsite.com/myscript.txt | bash -s -- arg1 arg2
# 或者
curl -sSL http://mywebsite.com/myscript.txt | bash /dev/stdin arg1 arg2

https://stackoverflow.com/questions/5735666/execute-bash-script-from-url https://unix.stackexchange.com/questions/622213/pass-args-to-bash-script-from-git-using-curl

rsync 命令

利用 rsync 快速删除海量文件

1
2
mkdir empty_dir
rsync -a --delete empty_dir/    yourdirectory/

https://unix.stackexchange.com/questions/37329/efficiently-delete-large-directory-containing-thousands-of-files