Linux Bash: move several different files to the same directory

As a pretty newbie Linux user, I cannot find how to do this. I am trying to move unique files in one directory to another directory. Example:

$ ls vehicle car.txt bicycle.txt airplane.html train.docx (more files) 

I want car.txt, bicycle.txt, airplane.html and train.docx inside the car.

Now I am doing this by moving the files individually:

 $ mv car.txt vehicle $ mv bicycle.txt vehicle ... 

How to do it in one line?

+5
source share
3 answers

You can do

 mv car.txt bicycle.txt vehicle/ 

(Note that / above is not necessary, I only enable it so that vehicle a directory.)

You can check it as follows:

 cd #Move to home directory mkdir temp #Make a temporary directory touch abcd #Make test (empty) files ('touch' also updates the modification date of an existing file to the current time) ls #Verify everything is there mv abcd temp/ #Move files into temp ls #See? They are gone. ls temp/ #Oh, there they are! rm -rf temp/ #DESTROY (Be very, very careful with this command) 
+7
source

You can try using a wildcard. In the code below, "*" will match all files that have any name ending in .txt or .docx and move them to the vehicle folder.

 mv *.txt *.docx vehicle/ 
+5
source

mv command in linux allows us to move more than one file to another directory. All you have to do is write down the name of each file you want to move, separated by the space character.

The following command will help you:

mv car.txt bicycle.txt airplane.html train.docx vehicle

or

mv car.txt bicycle.txt airplane.html train.docx vehicle/

both will work.

+2
source

Source: https://habr.com/ru/post/1261693/


All Articles