I would like to know how could I move all files from a folder to another folder with a command line.
Let's say I'm in my Downloads folder and there are a 100 files that I would like to move to my Videos folder, without having to write all the files name.
312 Answers
Open a terminal and execute this command:
mv -v ~/Downloads/* ~/Videos/It will move all the files and folders from Downloads folder to Videos folder.
To move all files, but not folders:
If you are interested in moving all files (but not folders) from Downloads folder to Videos folder, use this command
find ~/Downloads/ -type f -print0 | xargs -0 mv -t ~/VideosTo move only files from the Download folders, but not from sub-folders:
If you want to move all files from the Downloads folder, but not any files within folders in the Download folder, use this command:
find ~/Downloads/ -maxdepth 1 -type f -print0 | xargs -0 mv -t ~/Videoshere, -maxdepth option specifies how deep find should try, 1 means, only the directory specified in the find command. You can try using 2, 3 also to test.
See the Ubuntu find manpage for a detailed explanation
11mv ~/Downloads/* ~/VideosIt will move all the files including subfolders in the directory you want to mv. If you want to cp (copy) or rm (remove) you will need the -r (recursive) option to include subfolders.
For the simple case:
mv ~/Downloads/* ~/VideosIf you want to move dot (hidden) files too, then set the dotglob shell option.
shopt -s dotglob
mv ~/Downloads/* ~/VideosThis leaves the shell option set.
For one time dotglob use, run the commands in a subshell:
(shopt -s dotglob; mv ~/Downloads/* ~/Videos) 2 It's possible by using rsync, for example:
rsync -vau --remove-source-files src/ dst/where:
-v,--verbose: Increase verbosity.
-a,--archive: Archive mode; equals-rlptgoD(no-H,-A,-X).
-u,--update: Skip files that are newer on the receiver.
--remove-source-filesThis tellsrsyncto remove from the sending side the files (meaning non-directories) that are a part of the transfer and have been successfully duplicated on the receiving side.
If you've root privileges, prefix with sudo to override potential permission issues.
To move a directory with or without content to its new name just like how you would use the mv command to rename a file:
mv -T dir1 dir2
where:
-Ttreats the destination as a normal filedir1is the original name of the directorydir2is the new name of the directory
NB: dir2 doesn't have to exist.
I hope this saves someone a lot of time, as a noob, before this, I would create a directory with the new name and then move the contents of the directory to the directory created earlier.
Use for subdirectories
This command is useful when many files have been saved in a subfolder of the target directory i.e. Downloads/mp4. In this example, running mv -T Downloads/mp4 Videos will result in mp4 subfolder being removed and all files contained inside are moved to Videos folder.
Use
mv -v ~/rootfolder/branch/* ~/rootfolderI hope this helps. Because I had the same pain and wasted a lot of time fixing my mistake.
mv source_path/* destination_path/here you have to put forward slash and * after source path so that it will take files inside source_path instead of the complete source directory.
Example: mv /home/username/test/* /home/username/test2/
The above command moves all files (unless they are hidden) in the source directory to the destination directory.
- Go to the command line and get into the directory you want to move it to with
cd folderNamehere - Type
pwd. This will print the directory you want to move it too. - Then change to the directory where all of the files are with
cd folderNamehere - Now to move all the files type
mv *.* typeAnswerFromStep2here
That will move all files from that directory to the other.
1try it
find ~/Desktop -type f -iname "*.mp4" -exec mv {} ~/Videos \;-typewith the argument -type you can specify type file.on this statement that is the mean file.if using of -d that means directory.
-iname:the most common and obvious method to look for a file is using its -name argument.if you are not sure about its case-sensitivity you can use of -iname argument
mv {}and finally to specify target directory and then moving the files on there using mv {} argument
Just wanted to add one more answer. If you are already in the folder you want to move files out of, you can do this:
mv * ~/Videos 3 This command should do it:
sudo find ~/Downloads -mindepth 1 -prune -exec mv '{}' ~/Videos \;It moves all visible and hidden files, and doesn't throw unnecessary errors, not even if the source directory is empty.
you can copy all contents using rsync and remove all files using --remove-source-files remove copied directories using find -type d | rm :
rsync -auv --remove-source-files ./src ./dst \
&& find ./dst -type d | sed -n '1d;p' | xargs rm -rf -The command sed -n '1d;p' excludes first directory path from the directories listed, since the first directory in the list is directory dst itself!
OR you can run all in a single command (Thanks to good muslim @muru):
find ./dst -mindepth 1 -type d -delete 1