How To See Hidden Directories In Linux – Using Ls Command With Flags

Linux uses a simple naming convention to keep certain directories hidden from your regular view. If you want to know how to see hidden directories in linux, the answer is straightforward: hidden items start with a dot (.) in their name. This guide will show you every method to uncover them, from basic commands to advanced tricks.

Hidden directories are common in Linux. They store configuration files and user settings. You don’t see them by default, but they are easy to reveal once you know the right commands.

How To See Hidden Directories In Linux

The most common way to see hidden directories is using the ls command with the -a flag. This flag stands for “all” and shows every file and folder, including hidden ones.

Open your terminal and type:

ls -a

This lists all items in the current directory. Hidden directories appear with a dot prefix, like .config or .local.

If you want more details, use ls -la. The -l flag gives a long listing format with permissions, size, and modification date.

ls -la

Another option is ls -al. The order of flags doesn’t matter, so both work the same way.

For a cleaner view, try ls -A. This shows hidden files but omits the current (.) and parent (..) directory entries.

ls -A

This is useful when you only want hidden items, not the navigation shortcuts.

Using The Tree Command

The tree command displays directories in a tree-like structure. To include hidden directories, use the -a flag.

tree -a

This shows all hidden folders and files in a visual hierarchy. It’s great for understanding the structure of a directory.

If tree is not installed, you can add it via your package manager. For Debian/Ubuntu:

sudo apt install tree

For Fedora:

sudo dnf install tree

Using The Find Command

The find command is powerful for searching. To locate all hidden directories, use:

find . -type d -name ".*"

This finds every directory starting with a dot from the current location. The -type d limits results to directories only.

You can also search the entire system:

find / -type d -name ".*" 2>/dev/null

The 2>/dev/null part hides permission errors, making output cleaner.

Using The Grep Command With Ls

If you want to filter only hidden directories from a long list, combine ls with grep.

ls -la | grep "^d.*\."

This shows lines starting with d (directories) and containing a dot. It’s a bit advanced but very precise.

For a simpler version, just grep for the dot:

ls -la | grep "^\."

This filters all items starting with a dot, but includes files too.

Using The Ls Command With Wildcards

You can also use shell wildcards to list hidden directories specifically.

ls -d .*/

This lists only directories that start with a dot. The */ pattern matches directories, and the dot prefix filters hidden ones.

To include files, use:

ls -d .*

This shows all hidden items, both files and directories.

Using The Stat Command

The stat command shows detailed info about a file or directory. To check if something is hidden, look at its name.

stat .config

This displays metadata like permissions, size, and timestamps. It doesn’t directly show hidden status, but you can infer it from the name.

Using Graphical File Managers

If you prefer a GUI, most Linux file managers have a “Show Hidden Files” option. In Nautilus (GNOME), press Ctrl+H to toggle hidden files.

In Dolphin (KDE), click the menu button and select “Show Hidden Files” or press Alt+..

In Thunar (XFCE), go to View > Show Hidden Files or press Ctrl+H.

This method is visual and easy for beginners. You can see hidden directories like .cache and .ssh instantly.

Using The Bash Shell Options

You can make hidden files visible by default in your terminal. Use the shopt command to enable the dotglob option.

shopt -s dotglob

Now, ls without flags will show hidden directories. To disable it:

shopt -u dotglob

This is a handy trick for power users who work with hidden files often.

Using Alias For Convenience

Create an alias to always show hidden files. Add this line to your .bashrc or .zshrc file:

alias ls='ls -a'

Then reload the file:

source ~/.bashrc

Now, every time you type ls, it automatically shows hidden directories. Be careful, as this changes default behavior.

Understanding Hidden Directory Locations

Hidden directories are usually in your home folder. Common ones include:

  • .config – application settings
  • .local – user-specific data
  • .cache – temporary files
  • .ssh – SSH keys and config
  • .bashrc – shell configuration

System-wide hidden directories exist too, like /etc but they are not hidden by name. The dot prefix is user-specific.

Why Directories Are Hidden

Hidden directories reduce clutter. They store configuration files that you rarely need to see. By hiding them, the file system looks cleaner.

This convention is standard across Unix-like systems. It’s not a security feature, just a convenience.

Common Mistakes When Viewing Hidden Directories

Beginners often forget the -a flag. Without it, hidden directories don’t appear. Another mistake is using ls .* which can show unexpected results due to shell expansion.

For example, ls .* lists the current and parent directories first. Use ls -d .* to avoid this.

Using The Ls Command With Color Output

To make hidden directories stand out, enable color output. Most distributions have it by default. Use:

ls -la --color=auto

This shows directories in blue, files in white, and hidden items with the same color but a dot prefix. It helps visually identify them.

Using The Dir Command

The dir command is similar to ls but with different defaults. To see hidden directories:

dir -a

This works on most systems. It’s less common but equally effective.

Using The Vdir Command

vdir is another variant that shows long listings. Use it with -a:

vdir -a

This gives output similar to ls -la.

Using The Lsblk Command For Block Devices

If you need to see hidden directories on mounted drives, lsblk shows block devices. Hidden directories within those drives are still accessed via ls.

This is not directly related but useful for system administration.

Using The Mount Command

To see hidden directories on a mounted filesystem, navigate to the mount point and use ls -a. The mount command itself doesn’t show hidden directories.

Using The Df Command

The df command shows disk usage. Hidden directories contribute to usage, but df doesn’t list them individually.

Using The Du Command

To check the size of hidden directories, use:

du -sh .*

This shows the size of all hidden items in the current directory. The -s flag gives a summary, and -h makes it human-readable.

Using The Ncdu Tool

ncdu is a disk usage analyzer. Install it with your package manager, then run:

ncdu

It shows all directories, including hidden ones, in an interactive interface. Press Ctrl+H to toggle hidden files.

Using The Ranger File Manager

Ranger is a terminal file manager. Launch it with:

ranger

Press zh to toggle hidden files. This shows hidden directories in a navigable list.

Using The Midnight Commander

Midnight Commander (mc) is another terminal file manager. Press Ctrl+H to show hidden files. It displays directories in a two-pane view.

Using The Ls Command With The -1 Flag

For a single-column list, use:

ls -1a

This shows each hidden directory on its own line, useful for scripting.

Using The Ls Command With The -R Flag

To recursively list all hidden directories, use:

ls -Ra

This shows every hidden folder and file in subdirectories. Output can be long, so pipe it to less:

ls -Ra | less

Using The Grep Command With Find

Combine find and grep for specific patterns:

find . -type d -name ".*" | grep "config"

This finds hidden directories containing “config” in their name.

Using The Locate Command

The locate command searches a database. To find hidden directories:

locate .config

This is fast but may not be up-to-date. Run sudo updatedb first to refresh.

Using The Which Command

The which command locates executables. It doesn’t show hidden directories directly, but you can find hidden binaries.

Using The Type Command

type shows command types. Not useful for hidden directories.

Using The Lsattr Command

The lsattr command lists file attributes on some filesystems. It can show hidden attributes, but not hidden directories by name.

Using The Getfattr Command

For extended attributes, use getfattr. This is advanced and rarely needed.

Using The Setfacl Command

Access control lists (ACLs) can hide directories, but this is different from the dot convention.

Using The Chattr Command

You can make directories immutable with chattr +i. This doesn’t hide them but prevents changes.

Using The Sticky Bit

The sticky bit (chmod +t) affects deletion permissions, not visibility.

Using The Umask Command

Umask controls default permissions. It doesn’t hide directories.

Using The Ls Command With The -D Flag

The -d flag lists directories themselves, not their contents. Combine with .*:

ls -d .*

This shows hidden directories without listing their contents.

Using The Ls Command With The -F Flag

The -F flag appends indicators like / for directories. Use with -a:

ls -aF

Hidden directories will have a trailing slash.

Using The Ls Command With The -H Flag

The -h flag makes sizes human-readable. Combine with -la:

ls -lah

This shows hidden directories with file sizes in KB, MB, etc.

Using The Ls Command With The -S Flag

Sort by size with -S:

ls -laS

Hidden directories are sorted by size, largest first.

Using The Ls Command With The -T Flag

Sort by time with -t:

ls -lat

This shows hidden directories sorted by modification time.

Using The Ls Command With The -R Flag

Reverse order with -r:

ls -lar

This reverses the sort order for hidden directories.

Using The Ls Command With The -X Flag

Sort alphabetically by extension with -X:

ls -laX

Hidden directories (no extension) appear first.

Using The Ls Command With The –Group-directories-first Flag

This flag puts directories before files:

ls -la --group-directories-first

Hidden directories appear at the top of the list.

Using The Ls Command With The –Ignore Flag

To exclude certain patterns, use --ignore:

ls -la --ignore=".cache"

This hides the .cache directory from output.

Using The Ls Command With The –Hide Flag

Similar to --ignore, --hide excludes patterns:

ls -la --hide=".*"

This hides all hidden items, which is counterproductive but shows the flag’s use.

Using The Ls Command With The –Format Flag

Change output format with --format:

ls -la --format=comma

This lists hidden directories separated by commas.

Using The Ls Command With The –Time-style Flag

Customize time display:

ls -la --time-style=long-iso

Shows hidden directories with ISO-formatted timestamps.

Using The Ls Command With The –Color Flag

Force color output:

ls -la --color=always

This ensures hidden directories are colored even if piping.

Using The Ls Command With The –Quoting-style Flag

Quote names with special