开发者

Shell copying file with biggest size to another folder

I am new to Linux shell and I found a way to get the name of the file I want:

ls *.*g -S| grep -v ^d | head -1

I am going to be repeating this for a number of file. I am trying to copy this file to another directory (cp command?). But the below code is failing.

I am trying this, but its not working:

cp ls -S| grep -v ^d | head -1 ../directory

Also, I was won开发者_如何转开发dering how to loop through directorys that are in a particular directory.

Any help is much appreciated.

Thanks, Bryan


cp $(ls *.*g -S| grep -v ^d | head -1) ../directory


cp "$(find . -type f -name "*.*" -printf "%f:%s\n" | sort -t":" -k2 -n | awk -F":" 'END{print $1}')" ../directory

Use quotes in case there are white spaces in your file. add -maxdepth 1 if you don't want to recurse subdirectories

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜