简体   繁体   English

如何删除目录中的前 50 个目录 linux bash

[英]how to delete first 50 directories within a directory linux bash

I am looking to run a script which moves 50 directories to a new directory, once it has carried out that action it then deletes those 50 from the original directory我正在寻找一个将 50 个目录移动到新目录的脚本,一旦它执行了该操作,它就会从原始目录中删除这 50 个

I have the below so far in my bash script:到目前为止,我的 bash 脚本中有以下内容:

cd /folder1/subfolder1/directories

mv `ls | head -50` ../subfolder2/
cd /folder1/subfolder1/directories
dirs=( ./*/ )                            # an array of directories
mv -t ../subfolder2/ "${dirs[@]:0:50}"   # first 50 array elements

For GNU coreutils mv , -t is the "target" (aka, destination) directory.对于 GNU coreutils mv-t是“目标”(又名目标)目录。 This can be very handy if there are hundreds/thousands of files to move (more than can fit in one command):如果有成百上千的文件要移动(超过一个命令可以容纳),这将非常方便:

some-process-that-produces-filenames-on-stdout | xargs mv -t dest_dir/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM