linuxbashmv

Linux Bash: Move multiple different files into same directory


As a rather novice Linux user, I can't seem to find how to do this. I am trying to move unique files all in one directory into 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 vehicle.

Right now I do this by moving the files individually:

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

How can I do this in one line?


Solution

  • You can do

    mv car.txt bicycle.txt vehicle/
    

    (Note that the / above is unnecessary, I include it merely to ensure that vehicle is a directory.)

    You can test this as follows:

    cd               #Move to home directory
    mkdir temp       #Make a temporary directory
    touch a b c d    #Make test (empty) files ('touch' also updates the modification date of an existing file to the current time)
    ls               #Verify everything is there
    mv a b c d 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)