How do I move all files from one folder to another using the command line?
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.
Solution 1:
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 ~/Videos
To 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 ~/Videos
here, -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
Solution 2:
mv ~/Downloads/* ~/Videos
It 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.
Solution 3:
For the simple case:
mv ~/Downloads/* ~/Videos
If you want to move dot (hidden) files too, then set the dotglob shell option.
shopt -s dotglob
mv ~/Downloads/* ~/Videos
This leaves the shell option set.
For one time dotglob use, run the commands in a subshell:
(shopt -s dotglob; mv ~/Downloads/* ~/Videos)
Solution 4:
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-files
This tellsrsync
to 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.