Move All Files Including Hidden Files Into Parent Directory in Linux

In Linux, hidden files (also called dotfiles) are files whose names begin with a dot (.) character. These files typically store configuration data or system settings that should be handled carefully. When you need to move all files from a subdirectory to its parent directory, including these hidden files, Linux provides several effective methods.

Using the mv Command

The mv command is the standard tool for moving files and directories from one location to another. It can also be used to rename files and directories.

Moving Visible Files Only

To move all visible files from a subdirectory to its parent directory, use:

mv /path/subdirectory/* /path/

This command moves all visible files but excludes hidden files and directories.

Moving All Files Including Hidden Files

To move all files including hidden files, use the brace expansion syntax:

mv /path/subdirectory/{.,}* /path/

This command expands to:

mv /path/subdirectory/* /path/subdirectory/.* /path/

The * matches all visible files, while .* matches all hidden files. The -f option can be added to force overwrite existing files without prompting:

mv -f /path/subdirectory/{.,}* /path/

Using the rsync Command

rsync is a powerful utility for synchronizing files and directories. It can transfer files locally or remotely and supports advanced features like preserving permissions, ownership, and timestamps.

Preview Files Before Moving

To see which files will be moved without actually performing the operation, use the --dry-run option:

rsync --dry-run -av /path/subdirectory/ /path/

Moving All Files with rsync

To move all files including hidden files using rsync:

rsync --remove-source-files -av /path/subdirectory/ /path/

The --remove-source-files option removes files from the source directory after successful transfer, effectively moving them. The -a flag preserves file attributes, and -v provides verbose output.

Handling Permission Issues

If you encounter permission problems, add the --chmod option to set appropriate permissions:

sudo rsync --chmod=ugo=rwX --remove-source-files -av /path/subdirectory/ /path/

This sets read, write, and execute permissions for owner, group, and others on the moved files.

Comparison of Methods

Feature mv Command rsync Command
Speed Fast (direct move) Slower (copy then delete)
Preview No Yes (--dry-run)
Permission handling Preserves original Flexible with --chmod
Error recovery Limited Better (partial transfer)
Remote support No Yes

Important Considerations

  • Always verify the source and destination paths before executing the command

  • Use --dry-run with rsync to preview changes before actual execution

  • Be cautious with the .* pattern as it includes . and .. directory references

  • Consider backing up important data before performing bulk file operations

Conclusion

Both mv and rsync commands effectively move all files including hidden files to the parent directory. The mv command is simpler and faster for basic operations, while rsync offers more control and safety features like preview mode and better error handling.

Updated on: 2026-03-17T09:01:38+05:30

10K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements