Can you move hidden files with wildcards?

QuestionsQuestions8 SkillsProDec, 25 2025
0261

That's a great question! In Linux, files starting with a dot (e.g., .bashrc or .config) are considered hidden.

By default, the standard * wildcard does not match hidden files. This is a safety feature to prevent you from accidentally moving or deleting important configuration files.

Here are the ways to move hidden files with wildcards:

1. Match hidden files specifically

To move all hidden files (those starting with a dot), use .*:

mv .* destination_directory/

Note: Be careful with .* as it also matches the special directories . (current) and .. (parent), which might cause error messages, though the system usually prevents you from moving them.

2. Move everything (Hidden and Non-hidden)

If you want to move every single file in the directory using wildcards, you must specify both:

mv * .* destination_directory/

3. Change Shell behavior (Advanced)

If you are using the Bash shell (which is the default in your LabEx VM), you can change its behavior so that * includes hidden files by enabling the dotglob option:

shopt -s dotglob
mv * destination_directory/
shopt -u dotglob  # Use this to disable it again afterward

Summary for beginners:
The safest and easiest way to include a hidden file is to explicitly use the dot: mv .hidden_file destination/ or use .* if you want to catch all of them.

Would you like to try creating a hidden file and moving it to see how it works? (You can create one with touch .secret.txt)

0 Comments

no data
Be the first to share your comment!