Home FAQ How To Move Multiple File Types Simultaneously From Commandline
Move Multiple File Types In Linux

How To Move Multiple File Types Simultaneously From Commandline

By sk

The other day I was looking for a way move (not copy) multiple file types from one directory to another. I already knew how to find and copy certain type of files from one directory to another. But, I don't know how to move multiple file types simultaneously. If you ever been in a situation like this, here is an easy way to do it from commandline in Linux.

Move multiple file types simultaneously in Linux

Picture this scenario. You have multiple type of files, for example .pdf, .doc, .mp3, .mp4, .txt etc., on a directory named 'dir1'.

Let us take a look at the contents of this directory:

$ ls dir1
file.txt image.jpg mydoc.doc personal.pdf song.mp3 video.mp4

You want to move some file types (not all of them) to different location. For  example, let us say you want to move doc, pdf and txt files to another directory named 'dir2' in one go.

To move .doc, .pdf and .txt files from dir1 to dir2 simultaneously, the command would be:

$ mv dir1/*.{doc,pdf,txt} dir2/

It's easy, isn't it?

Now, let us check the contents of dir2:

$ ls dir2/
file.txt mydoc.doc personal.pdf

See? the file types .doc, .pdf and .txt from dir1 have been moved to dir2.

mv command

You can add as many file types as you want to inside the curly braces in the above command to move them across different directories. The above command just works fine for me on Bash.

Another way to move multiple file types is to go to the source directory i.e dir1 in our case:

$ cd ~/dir1

And, move file types of your choice to the destination (E.g dir2) as shown below.

$ mv *.doc *.txt *.pdf /home/sk/dir2/

To move all files having a particular extension, for example .doc only, run:

$ mv dir1/*.doc dir2/

For more details, refer man pages.

$ man mv

Moving a few number of same or different file types is easy! You could do this with couple mouse clicks in GUI mode or use a one-liner command in CLI mode. However, If you have hundreds of different file types in a directory and wanted to move multiple file types to different directory in one go, it would be a cumbersome task. To me, the above method did the job easily! If you know any other one-liner commands to move multiple file types at a time, please share it in the comment section below. I will check and update the guide accordingly.

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More