Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving All Files From Directories One Step Up

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?

like image 589
neversaint Avatar asked Mar 10 '09 01:03

neversaint


People also ask

How do you move all files from a directory to another?

You can move a file or folder from one folder to another by dragging it from its current location and dropping it into the destination folder, just as you would with a file on your desktop. Folder Tree: Right-click the file or folder you want, and from the menu that displays click Move or Copy.

How do you move from the current directory to one up?

You need to use the mv command that moves one or more files or directories from one place to another. You must have have write permission for the directories which the file will move between. The syntax is as follows to move /home/apache2/www/html directory up one level at /home/apache2/www/ directory.

How do I move all files from one folder to another using the command line?

To move one or more files: MOVE [/Y | /-Y] [drive:][path]filename1[,...] destination To rename a directory: MOVE [/Y | /-Y] [drive:][path]dirname1 dirname2 [drive:][path]filename1 Specifies the location and name of the file or files you want to move. destination Specifies the new location of the file.

What command is used to move up one directory?

To navigate to your home directory, use "cd" or "cd ~" To navigate up one directory level, use "cd .." To navigate to the previous directory (or back), use "cd -"


2 Answers

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
like image 146
bsdfish Avatar answered Nov 04 '22 20:11

bsdfish


mv */*.masked .
like image 27
vladr Avatar answered Nov 04 '22 22:11

vladr