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
2 votes

Find files with matching substrings and move them into directory

Should be something like: shopt -s nullglob extglob # dotglob for file in [^_]*_@(Grn|Red).idat; do dirname=${file%%_*} mkdir -p -- "$dirname" && mv -- "$file" &...
Stéphane Chazelas's user avatar
1 vote
Accepted

Where in Ubuntu . or .. is defined as current directory or parent directory and how I can add my own ...?

. and .. are things the operating system implements. They might actually exist in the on-disk filesystem structure the same as every other directory, or they might be implemented specially, but that ...
ilkkachu's user avatar
  • 130k

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