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/...
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 ...
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 ...
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, ...
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" &...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
directory × 1738files × 291
linux × 262
bash × 212
permissions × 193
shell × 169
find × 145
shell-script × 128
filesystems × 126
ls × 107
rm × 102
command-line × 96
filenames × 86
symlink × 70
rename × 63
mv × 63
cd-command × 61
cp × 54
directory-structure × 53
tar × 46
recursive × 46
ubuntu × 44
mount × 37
scripting × 36
mkdir × 36