[英]How do I copy multiple files at once in linux? With the source and the destination locations of these files being the same directory
[英]How do I copy the beginning of multiple files in Linux?
我想在Ubuntu中将一堆文件(* .txt)从一个目录复制到另一个目录。 我想减小它们的大小,所以我使用head来获取每行的前100行。
我希望新文件保留其原始名称,但位于子目录small/
。 我努力了:
head -n 100 *.txt > small/*.txt
但这会创建一个名为*.txt
文件。 我也尝试过:
head -n 100 *.txt > small/
但这给出Is a directory
错误。
这一定很容易,但是我对Linux很不好。 任何帮助深表感谢。
您必须改为创建一个循环:
for file in *.txt; do
head -n 100 "$file" > small/"$file"
done
这将循环遍历所有.txt
文件,在所有.txt
文件中执行head -n 100
并输出到small/
目录中的新文件中。
尝试
for f in *.txt; do
head -n 100 $f > small/$f
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.