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.