Hot answers tagged

6 votes

Copy the n-largest files from a certain directory to the current one

Using zsh you can avoid all the pitfalls associated with parsing and sorting the output of ls: cp -n -- specific/directory/*(.DOL[1,5]) ./ or with GNU cp (for the -toption): cp -n -t ./ -- specific/...
steeldriver's user avatar
  • 77.4k
6 votes

Copy the n-largest files from a certain directory to the current one

All my solutions treat only files, as requested, and can treat all type of files (even with special characters). If you want to use ls -S do it the right way: ls --zero -S | head -z -n5 | xargs -r0 cp ...
Gilles Quénot's user avatar
2 votes
Accepted

Copy the n-largest files from a certain directory to the current one

To integrate the other answers: TL; DR: See below for viable solutions for bash and POSIX shells. Why is the pipe working for the first item and failing for the rest? Because the shell does not ...
LL3's user avatar
  • 4,960
2 votes

Copy the n-largest files from a certain directory to the current one

EDIT: New answer, works more completely: The reason the original fails is that the directory name is added only to the first result, so the remaining results, not existing in the current directory, ...
Peter Whittaker's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible