Linux 删除大量的文件和移动大量的文件(Argument list too long)

来源:互联网 发布:sql 不包含指定条件值 编辑:程序博客网 时间:2024/04/30 12:53

1.

find ./ -name '*' | xargs -i mv {}  ../test/

 

find ./ -name '*' | xargs rm -rf

 

2.Question :

 

    [user@localhost directory]$ mv * ../directory2

    bash: /bin/mv: Argument list too long

#Method1 : when file name can be distributed across the alphabet.
[user@localhost directory]$ mv [a-l]* ../directory2
[user@localhost directory]$ mv [m-z]* ../directory2

#Method2: using find and exec commands
[user@localhost directory]$ find $directory -type f -name '*' -exec mv {} $directory2/. /;
find $directory -type f -name '*' -exec scp {} username@servername:/$path/. /;

#Method3: using function
function large_mv ()
{ while read line1; do
mv directory/$line1 ../directory2
done
}
ls -1 directory/ | large_mv