Hidden Files in Linux: List, Copy, Delete and Secure

What hidden files in Linux are, ls -a vs ls -A, dotglob, copying and deleting dotfiles safely, key DevOps dotfiles, SSH permissions and auditing secrets.

Aug 1, 2025 - 17:27
Nov 5, 2026 - 04:38
 0  93
Hidden Files in Linux: List, Copy, Delete and Secure

A hidden file in Linux is any file or directory whose name starts with a dot, such as .bashrc or .ssh. There is no special attribute: ls and file managers simply skip dot names by default. Show them with ls -a or ls -A, create one by giving it a leading dot, and remember that hidden does not mean protected.

This guide is part of our Linux fundamentals track, which feeds into the RHEL 10 beginner's guide. It covers how dotfiles work, the ones you will edit as a DevOps engineer, how shell globs treat them, safe copy and delete patterns, and how to audit them for leaked secrets. Commands were checked against the GNU coreutils, Bash and OpenSSH manuals.

Key takeaways

  • The leading dot is a naming convention. The kernel and file system treat dotfiles like any other file.
  • ls -a shows everything including . and ..; ls -A shows hidden files without those two entries.
  • In Bash, * does not match dot names unless you enable shopt -s dotglob. This catches people out when copying or deleting.
  • Permissions, not the dot, protect files. ~/.ssh should be 700 and private keys 600.
  • Dotfiles such as .env and .git often hold secrets. Never serve them from a web root or commit them by mistake.

How hiding works

Early Unix ls skipped the . and .. directory entries by checking whether a name began with a dot. That shortcut also hid every other dot name, and programs started using it on purpose to keep configuration files out of the way. The convention stuck. Today ls, shell globs and graphical file managers all follow it, but nothing is enforced underneath. Any program that lists a directory directly sees dotfiles.

CommandShows hidden files?Shows . and ..?
lsNoNo
ls -aYesYes
ls -AYesNo
find .YesOnly the starting point
echo * (Bash default)NoNo
GNOME FilesToggle with Ctrl+HNo

Listing hidden files

# All entries, long format
ls -la ~

# Hidden entries only, without descending into directories
ls -ld ~/.[!.]* ~/..?* 2>/dev/null

# Hidden files anywhere below the current directory
find . -name '.*' -not -name '.' -type f

# Hidden directories one level down
find ~ -maxdepth 1 -name '.*' -type d

The pattern .[!.]* matches names that start with one dot followed by anything except a second dot, which excludes ... Adding ..?* catches rare names that start with two dots, such as ..config.

Creating, hiding and unhiding

# Create a hidden file or directory
touch .notes
mkdir .scratch

# Hide an existing file by renaming it
mv report.txt .report.txt

# Unhide it
mv .report.txt report.txt

Some graphical file managers also read a plain text file named .hidden in a directory and hide the names listed in it. That works only in those file managers; ls and the shell ignore it.

Dotfiles you will meet as a DevOps engineer

PathPurposeTypical permissions
~/.bashrcSettings for interactive non-login Bash shells: aliases, functions, prompt644
~/.bash_profile or ~/.profileRun by login shells; often sources .bashrc644
~/.bash_historyCommand history600
~/.ssh/Keys, authorized_keys, config, known_hosts700 (directory)
~/.ssh/id_ed25519Private key600
~/.gitconfigGit user name, email, aliases644
~/.config/XDG base directory for application settings700 or 755
~/.kube/configkubectl clusters, users and contexts, often with credentials600
~/.aws/credentialsAWS CLI access keys600
.gitignorePatterns Git should not track644
.envEnvironment variables for an app, frequently secrets600
/etc/skel/.*Templates copied into new users' home directories644

Editing .bashrc safely

# Back up first
cp ~/.bashrc ~/.bashrc.bak

# Add an alias and a PATH entry
cat >> ~/.bashrc <<'EOF'
alias k='kubectl'
export PATH="$HOME/bin:$PATH"
EOF

# Load it into the current shell
source ~/.bashrc

If a mistake breaks your shell, open a new session with bash --norc and restore the backup.

Setting SSH permissions

OpenSSH refuses to use keys or authorized_keys files that other users can write or read, depending on the file. Set them explicitly:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519 ~/.ssh/authorized_keys ~/.ssh/config
chmod 644 ~/.ssh/id_ed25519.pub

On RHEL, also restore SELinux labels if you copied the directory from elsewhere: restorecon -Rv ~/.ssh. Our SSH keys and security guide covers the rest of the setup.

Globs, copying and deleting

Why cp * misses dotfiles

By default, Bash does not expand * to names starting with a dot. So cp -r src/* dest/ silently leaves .env, .gitignore and .git behind.

# Copy the whole directory contents including dotfiles
cp -a src/. dest/

# Or enable dotglob for this shell
shopt -s dotglob
cp -r src/* dest/
shopt -u dotglob

# rsync copies hidden files by default
rsync -a src/ dest/

src/. means "the directory itself", so cp copies everything inside it. -a keeps permissions, ownership and timestamps.

Deleting hidden files carefully

The pattern .* also matches . and ... Modern GNU rm refuses to remove those two, but other tools and older systems may not, so avoid it.

# Preview first
ls -d .[!.]* ..?* 2>/dev/null

# Then remove specific names
rm -i .old_config .tmp_cache

# Remove hidden files older than 30 days in a cache directory
find ~/.cache -type f -mtime +30 -print   # check
find ~/.cache -type f -mtime +30 -delete  # then delete

Measuring hidden directories

Caches and tool data can grow large without showing in ls.

du -sh ~/.[!.]* 2>/dev/null | sort -h | tail

Common space users are ~/.cache, ~/.local/share/containers (rootless Podman images) and language package caches.

Hidden files and security

A dot hides a file from casual listing, not from anyone who looks. Treat hidden files with the same care as visible ones, and audit them because people forget they exist.

Keep secrets out of Git

# .gitignore
.env
.env.*
*.pem
.terraform/
.kube/

If a secret was committed, removing it in a new commit is not enough because history keeps it. Rotate the credential first, then clean history if needed. Our Git repository best practices explain secret scanning.

Do not serve dotfiles from a web root

A .git directory or .env file deployed into a web server's document root can expose source code and credentials. Deploy build artefacts rather than a working copy, and block dot paths in the server configuration. For Apache httpd:

<LocationMatch "/\.">
    Require all denied
</LocationMatch>

Adjust the rule if you serve /.well-known/ for certificates or other standards, and test it after reloading.

Audit hidden files on a server

Unexpected hidden files in /tmp, /var/tmp, /dev/shm or system directories deserve a look during a security review. List them, check owners and timestamps, and compare against package ownership:

sudo find /tmp /var/tmp /dev/shm -name '.*' -printf '%M %u %TY-%Tm-%Td %p\n'
rpm -qf /path/to/file   # RHEL: which package owns it, if any

For change detection at scale, use a file integrity tool such as AIDE or auditd watch rules rather than manual checks. See configuring auditd on RHEL 10.

Hidden files in containers and builds

Dotfiles matter in container builds too. A .dockerignore file (Podman and Buildah also read .containerignore) lists paths the build should not send to the builder. Without it, COPY . . can copy .git, .env and local caches into the image, which makes images larger and can ship secrets.

# .dockerignore
.git
.env
.env.*
.venv
node_modules
*.log

Hidden files inside an image are as visible as they are on a host. Anyone who can pull the image can unpack its layers and read them, and deleting a file in a later layer does not remove it from the earlier one. Keep secrets out of the build context and pass them at runtime through mounted secrets or a secrets manager. Our Dockerfile mistakes guide covers related pitfalls.

Inside a running container, configuration often lives in dotfiles under the application user's home directory. When a container runs as an arbitrary UID, as OpenShift does by default, $HOME may not be writable, and tools that try to create ~/.cache or ~/.config fail. Setting HOME or the XDG variables to a writable path in the image fixes that.

Managing dotfiles across machines

Many engineers keep their personal dotfiles in a Git repository and link them into place. A simple approach uses symlinks:

git clone https://github.com/yourname/dotfiles.git ~/dotfiles
ln -sf ~/dotfiles/bashrc ~/.bashrc
ln -sf ~/dotfiles/gitconfig ~/.gitconfig

Tools such as GNU Stow automate the linking. Keep anything with credentials, such as .aws/credentials or .kube/config, out of that repository. For team-wide defaults on new accounts, place files in /etc/skel, which useradd copies into each new home directory. The RHEL 10 user management guide shows this in practice.

Frequently asked questions

What makes a file hidden in Linux?

Only a name that starts with a dot. There is no hidden attribute in the file system; ls, shell globs and file managers skip dot names by convention.

What is the difference between ls -a and ls -A?

ls -a lists all entries including the . and .. directory links. ls -A lists hidden files but leaves out those two entries.

How do I copy hidden files with cp?

Use cp -a source/. destination/, enable shopt -s dotglob before using *, or use rsync -a source/ destination/.

Are hidden files secure?

No. Anyone with read permission can list and open them. Use file permissions, and for secrets use a secrets manager or encrypted storage.

How do I show hidden files in the GNOME file manager?

Press Ctrl+H, or enable "Show Hidden Files" from the menu.

Why is it risky to run rm -rf .*?

The pattern also matches . and ... GNU rm refuses those, but the habit is unsafe on other tools. List matches first and delete specific names.

What permissions should ~/.ssh have?

The directory should be 700, private keys and authorized_keys 600, and public keys 644. OpenSSH may reject keys with looser permissions.

Practise with a trainer

File management, permissions and shell configuration are covered early in our Linux administration training, in the Kharadi, Pune classroom or live online. Related reading: read, write and execute permissions.

References

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0
Mridul I am a passionate technology enthusiast with a strong focus on DevOps, Cloud Computing, and Cybersecurity. Through my blogs at DevOps Training Institute, I aim to simplify complex concepts and share practical insights for learners and professionals. My goal is to empower readers with knowledge, hands-on tips, and industry best practices to stay ahead in the ever-evolving world of DevOps.