👉 https://amzn.to/4aLHbLD 👈 You’re literally one click away from a better setup — grab it now! 🚀👑
As an Amazon Associate I earn from qualifying purchases. Ubuntu: How to move multiple files at once to a specific destination directory?
Question: I got a bunch of files in some directory (along with many other files) that I
want to move.
Luckily, all the files I want to move contain a certain identifier in their
names, so I can ls | grep IDENTIFIER to get the exact list of files to move.
But, how can I execute mv file /path/to/dest/folder/ at once, and not one by
one (there's a lot of files to move)?
Solutions Sample (Please watch the whole video to see all solutions, in order of how many people found them helpful):
== This solution helped 10 people ==
I use tuomaz's technique, but slightly modified:
mv file1 file2 file3 -t DESTINATION
I find this easier to remember and harder to screw up since it uses the same
ordering as the vanilla mv operation:
mv file1 DESTINATION
== This solution helped 182 people ==
You could use
mv -t DESTINATION file1 file2 file3
and
mv -t DESTINATION `ls|grep IDENTIFIER`
works, but I'm not sure if mv is invoked multiple times or not as grep will
output a new line for each match.
== This solution helped 1 person ==
Easiest way is like this
mv {file1,file2,file3} DESTINATION
or directory
mv {directory1,directory2,directory3} DESTINATION
or both files and directories
mv {file1,file2,file3,directory1,directory2,directory3} DESTINATION
Hope this helps
== This solution helped 1 person ==
Using this command you can move multiple files.
mv SourceFilenames ~DestinationPath
== This solution helped 20 people ==
In case you want to move a set of irrelevant files (no common pattern in the
names and types) you can do as Mr. Rajanand said: first go to the directory
that contains the files you want to move
mv file1.ext1 file2.ext2 file3.ext3.. /destination/
In case the files are scattered in different directories, you only need to
specify the path for each file in the move command
== This solution helped 22 people ==
You can use http://www.tuxfiles.org/linuxhelp/wil....
Example: To move all files having extension .doc
mv *.doc /path/to/dest/folder/
This will move all doc file under the current directory to the specific
destination.
Edit
To answer the comment.
mv *.ext Posts.xml TODO.txt WIP.txt /path/to/dest/folder/
== This solution helped 2 people ==
You can use the output from ls to input into mv commnad
mv $(ls | grep IDENTIFIER) /path/to/dest/dir
The command between $() returns a list of the file names matching your search,
and that can be provided as a parameter for the mv command.
== This solution helped 3 people ==
find -type f -name "[range]" -exec mv {} target-directory ';'
this command will move file names with any pattern/range to target-directory.
eg.
find -type f -name "file[1-50000]" -exec mv {} target-directory ';'
it will move files with names like file1, file2 ... file50000 to target-
directory.
== This solution helped 5 people ==
If the files are in the same dir you can use
mv /path/to/source/dir/{file1,file2,*.ext1,*.ext2} /path/to/destination/
(tested in Ubuntu 16.04)
With thanks & praise to God! With thanks to all the many who have made this project possible! | Content (except music & images) licensed under cc by-sa 3.0 | Music & music license: https://www.bensound.com/royalty-free... | Images & images license: https://stocksnap.io/license and others | With thanks to user Zanna (https://askubuntu.com/users/527764), user user734124 (https://askubuntu.com/users/734124), user tuomaz (https://askubuntu.com/users/107995), user Sruli (https://askubuntu.com/users/483497), user Sabrina (https://askubuntu.com/users/769117), user Rajanand (https://askubuntu.com/users/86476), user muru (https://askubuntu.com/users/158442), user Ismail AL-taharwa (https://askubuntu.com/users/262127), user ignite (https://askubuntu.com/users/58990), user gilad hoch (https://askubuntu.com/users/30812), user Fuad Saud (https://askubuntu.com/users/48176), user Evandro Silva (https://askubuntu.com/users/92745), user Blake Frederick (https://askubuntu.com/users/251257), user AggieBill (https://askubuntu.com/users/101524), user Achu (https://askubuntu.com/users/9701), and the Stack Exchange Network (http://askubuntu.com/questions/214560). Trademarks are property of their respective owners. Disclaimer: All information is provided "AS IS" without warranty of any kind. You are responsible for your own actions. Please contact me if anything should be amiss at Roel D.OT VandePaar A.T gmail.com.