Ubuntu – how can I move files with specific names from one folder to another

command linefiles

I have read this Copying multiple specific files from one folder to another which could not help me.

I have thousands of files in /Users/Marine/Desktop/folderGN, some of which I want to keep and some of which I want to move.

There are several files with different names and I want to move only those that have a name containing Protein or MSMS or PSms.

I want to move them from

/Users/Marine/Desktop/folderGN

to

/Users/Marine/Descktop/myfolder 

Best Answer

To glob for the different names, you can use a for loop like so

for f in /Users/Marine/Descktop/folderGN/{*[Pp]rotein*,*MSMS*,*PSms*}; do echo mv -v -- "$f" /Users/Marine/Descktop/myfolder ; done

Remove the echo after testing to actually move the files.

I have copied your paths exactly (including the possible typo in Descktop?), but you could instead do this with relative paths:

cd /Users/Marine/Descktop/folderGN
for f in *[Pp]rotein* *MSMS* *PSms* ; do echo mv -v -- "$f" ../myfolder ; done 

(remove echo after testing as before)