I am trying to create a loop to sort files within each of many directories by size, then copy the largest two to another location, keeping the directory format (below).
folder/sample 1
.../s1.fastq.gz
.../s2.fastq.gz
.../s3.fastq.gz
.../s4.fastq.gz
folder/sample 2
.../s1.fastq.gz
.../s2.fastq.gz
.../s3.fastq.gz
.../s4.fastq.gz
I'm new to Linux, so I'm struggling. I tried:
#!/bin/bash
mkdir newfolder
for dir in folder/*
do
echo $dir
ls -S $dir/*.gz | head -n +2 | cp -T newfolder
done
However, I get the following error.
cp: missing destination file operand after 'newfolder.'
How do I correctly feed the large files into the copy function?
I've also tried using xargs, but I get the error
xargs: invalid option -- 'w'
because I am not correctly feeding in one line at a time.
zsh
shell:cp *.fastq.gz(.OL[1,2]) newfolder
in each directory. – Kusalananda Nov 14 '19 at 06:37bash
to solve the issue? – Kusalananda Nov 14 '19 at 08:13newfolder
tonew folder
here, it introduces another error). – Stephen Kitt Nov 14 '19 at 10:07zsh
as I am executing this on a cluster/server that only operatesbash
. – Holly Jenkins Nov 15 '19 at 00:50