10

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?

Costique
  • 23,712
  • 4
  • 76
  • 79
neversaint
  • 60,904
  • 137
  • 310
  • 477

3 Answers3

16

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
  • 2,434
  • 1
  • 21
  • 20
  • The target directory of `..` will move files one step above the current working directory. Not what the OP wants. They want to move it one step above with respect to the actual source files. – Amin Ya Oct 14 '20 at 03:17
6
mv */*.masked .
vladr
  • 65,483
  • 18
  • 129
  • 130
5

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,859
  • 3
  • 23
  • 14