Move several files with different formats simultaneously from the terminal

Arrow and directory icon

After reading the title you can think, well, very simple, I use the command cp or mv and I use the wildcard character * to move all at once. But that would move each and every one of the files in the directory where you are working. But we don't want that exactly, what we want to show in this mini-tutorial is something a little more refined, that is, to move only certain formats from inside that directory to another place.

Remember that when I say move, it could also be rename. With that being said, let's get down to business demonstrating how this can be done in a super easy and fast way, so that when you have to purge certain file formats you don't have to move them one by one, but you can automate everything from a single command line. Well, to move different formats of files from one directory to a different directory, the command format can be one of the following:

mv /ruta/origen/*.{ext1, ext2, extn} /ruta/destino

mv *.ext1 *.ext2 *.extn /ruta/destino

Both cases serve, in the first one what we do is specify the route of origin and then the extensions that we are going to move. Only those will be moved and not others, affecting any file, whatever its name. In the second case, it is assumed that we are already working from the directory where the files that we are going to move are located ...

For example, imagine that we want to move all the videos from one directory to a different one. Instead, in that directory there are .txt, .odt documents, and also music in .mp3. If we were only interested in moving the .flv, .mp4, .avi, and .mkv, what we would do would be the following:

mv /home/Documentos/*.{flv, mp4, avi, mkv} /home/Multimedia

It's that simple, when Let's list the content of said source directory with an lsWe will see that all the moved files are gone, but the ones we did not want to affect will be. A very simple example, but surely beginners appreciate!


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   gerarjors said

    excellent contribution and useful