views:

564

answers:

3

Dear all,

I have a directories that look like this

fool@brat:/mydir/ucsc_mm8> tar -xvf *.tar 
1/chr1.fa.masked
1/chr1_random.fa.masked
2/chr2.fa.masked
3/chr3.fa.masked
4/chr4.fa.masked
5/chr5.fa.masked
5/chr5_random.fa.masked
19/chr19.fa.masked
Un/chrUn_random.fa.masked

What I want to do is to move out all the "*.masked" files in the subdirectories /1 upto /Un. Is there a compact way to do it in Linux/Unix?

+3  A: 

Many unix shells support the * operator in the directory portion of the path as well. The following works in at least bash and zsh:

ls */*.masked

This will return all of the files that end in .masked one directory deeper.

So to move them:

mv */*.masked destination
Brian Pellin
+2  A: 
mv */*.masked .
vladr
+8  A: 

The typical way of moving files all files matching a particular expression is

mv 1/*.masked targetDir

where targetDir could be ..

If you want to move it from directories 1,2,3 then you can do something like

mv */*.masked targetDir

Or, if you want to specifically move it from numbered directories, you can just run something like

mv [0-9][0-9]/*.masked targetDir
bsdfish