Liang Xu | command line multiple file types simultaneously moving tips

We know that certain types of multiple files from one directory to another is very simple, but at the same time move multiple files of various types may be very troublesome, here are some let you move multiple file types in Linux Tips.

While moving multiple file types

method 1:

Assuming that dir1the directory There are many types of documents, such as .pdf .doc .mp3 .mp4 .txt, etc., let's view the dir1content:

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

At this point, you want certain file types (not all file types) to move to a different location. For example, you want to doc, pdf and txt file to another named one-time dir2directory, you can use the following command:

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

Then, we were look dir1and dir2content directory to see if the move came:

$ ls dir1/
song.mp3 video.mp4
$ ls dir2/
file.txt mydoc.doc personal.pdf

Can be seen, dir1the .doc .pdf and .txt file types indeed been moved to dir2.

You can add any file type within the braces in the above command to move them to another directory. How, is not it simple?

Method 2:

Let's switch to the source directory, here we are dir1:

$ cd ~/dir1

Then select the type of file to target directory dir2:

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

To move all files specific extensions, such as .doc:

$ mv dir1/*.doc dir2/

Here introduce so much more details, please refer to its manual page:

$ man mv

summary

Moving a few files to a different directory is easy, you can click the mouse in GUI mode or single-line command in CLI mode operation. However, if there are several thousands of different file types, you will be very speechless. Fortunately, however, it is that you learn over after today's tips for you this demand will become very easy!

-----------------

I am a good promise, the world's top 500 foreign Linux development engineer, specializing in the production of dry Linux. I welcome the attention of the public number " Liang Xu Linux " reply " 1024 " for the latest and most comprehensive technical information, respond to " the group " into the clearing technology exchange group.

img

Guess you like

Origin www.cnblogs.com/yychuyu/p/11415467.html