[英]linux: touch empty file and zip in one command
I need to create a bunch of .gz files for testing something. 我需要创建一堆.gz文件来测试一些东西。 Is it possible (in unix based shell) to make an empty file (eg by
touch file1
) and zip (eg file1.gz) using a simple one-liner (along: touch file1 | zip
). 是否有可能(在基于unix的shell中)使用简单的单行程序(沿着:
touch file1 | zip
)创建一个空文件(例如通过touch file1
)和zip(例如file1.gz)。 How can I redirect the file into zip? 如何将文件重定向到zip?
gzip < /dev/null > file.gz
Ie feed gzip
empty input and redirect the output to file.gz
. 即提供
gzip
空输入并将输出重定向到file.gz
No temporary empty file needed. 不需要临时空文件。 😉
😉
This assumes that there's a /dev/null
available (ie a POSIX(-ish) system). 这假设有
/dev/null
可用(即POSIX(-ish)系统)。 Alternatives would be: 替代方案是:
: | gzip […]
true | gzip […]
printf '' | gzip […]
echo -n | gzip […] # Won't work in strictly POSIX environments
…
Ie anything that's available and prints nothing to STDOUT. 即任何可用的东西,并没有打印到STDOUT。
You mentioned zip
, but since you said you needed .gz
files I assume you want gzip
. 你提到了
zip
,但是因为你说你需要.gz
文件我假设你需要gzip
。
例如:
touch file1 && zip file1.zip file1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.