Move file, folder, hidden file in CentOS

Move All Files Including Hidden Files Into Parent Directory

rsync is a Linux utility to move or copy files from one directory to another either locally or remotely. It also supports moving groups, permissions, links, and devices.

rsync uses a remote-update protocol to move or copy the files. This allows transferring just the differences between two sets of files.

First, let’s use rsync with the –dry-run option to see what files will be moved without performing the actual move operation:

sudo rsync --dry-run path/subfolder/ path/

Lets now see how to move all files including hidden files using rsync:

sudo rsync --remove-source-files /path/subfolder/ /path/

The above command moves all the files from the directory /path/subfolder/ to its parent, /path/.

Note here that rsync moves all the files, including hidden files, because we’ve used / at the end of the path. This denotes that the complete source directory should be synced with the target directory.

The –remove-source-files option will remove the files from the source directory once they are copied to the target directory. This will also remove the original folder, subfolder, as part of the sync operation.

Also, note we use sudo to execute the rsync command with admin privileges. This avoids any permission issues while creating the target directories.

If we don’t use sudo, and there are any permission issues while creating the target directories, the files won’t be copied, but they’ll still be removed from the original directory.

 

Leave a Comment

Your email address will not be published. Required fields are marked *