Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Working with Hidden Files in Linux
Hidden files in Linux are files that are not displayed when the standard ls command is executed. A hidden file's name begins with a dot (period). Not only files, but also directories can be hidden in Linux. Files are hidden for various purposes ? primarily to prevent accidental modification or deletion of important system configuration files. Hidden files typically contain environment settings or application data that should only be accessed by specific programs, not manually edited by users.
In this article, we will explore different methods for finding, creating, and manipulating hidden files in Linux using command-line tools.
Finding Hidden Files Using ls Command
The most common way to view hidden files is using the ls command with the -a (all) flag
$ ls -a
This displays both hidden and normal files in the current directory
. .bashrc Documents Pictures Templates .. .cache Downloads .profile Videos .aws .config .gnupg Public .viminfo .bash_history Desktop .local results.txt wd .bash_logout .emacs.d Music .ssh
For detailed information about each file, combine the -a and -l flags
$ ls -al
This shows file permissions, ownership, size, and modification time
total 112 drwxr-xr-x 17 user user 4096 Mar 17 05:39 . drwxr-xr-x 3 root root 4096 Feb 17 20:53 .. drwxrwxr-x 2 user user 4096 Feb 25 01:13 .aws -rw------- 1 user user 6101 Mar 16 02:48 .bash_history -rw-r--r-- 1 user user 220 Feb 17 20:53 .bash_logout -rw-r--r-- 1 user user 3771 Feb 17 20:53 .bashrc
Finding Hidden Files Using Find Command
The find command provides more advanced search capabilities. To locate all hidden files recursively
$ find . -name ".*" -type f
This searches for files (-type f) whose names start with a dot
./.profile ./.bashrc ./.bash_history ./.bash_logout ./.viminfo ./.sudo_as_admin_successful ./Desktop/.hidden_project
To find only hidden directories in the current directory
$ find . -name ".*" -maxdepth 1 -type d 2> /dev/null
The -maxdepth 1 limits search to current directory, -type d finds directories only, and 2> /dev/null suppresses error messages
./.aws ./.cache ./.config ./.emacs.d ./.gnupg ./.local ./.ssh
Creating Hidden Files and Directories
To create a hidden file, simply prefix the filename with a dot when using touch
$ touch .hidden_file
Verify the file was created
$ ls -a | grep hidden
.hidden_file
To create a hidden directory
$ mkdir .hidden_directory
Manipulating Hidden Files
Hidden files can be manipulated using standard Linux commands. To copy a hidden file
$ cp .hidden_file .hidden_directory/
To edit a hidden file using a text editor like nano
$ nano .hidden_directory/.hidden_file
To move or rename hidden files
$ mv .old_hidden_file .new_hidden_file
To delete hidden files, use rm with caution
$ rm .hidden_file $ rm -rf .hidden_directory
Common Hidden Files
| File/Directory | Purpose |
|---|---|
| .bashrc | Bash shell configuration |
| .bash_history | Command history |
| .ssh/ | SSH keys and configuration |
| .config/ | Application configuration files |
| .cache/ | Application cache data |
Conclusion
Working with hidden files is essential for Linux system administration and configuration management. The ls -a and find commands provide powerful ways to locate hidden files, while standard file operations work seamlessly with dot-prefixed filenames. Understanding hidden files helps maintain system configurations and protect important data from accidental modification.
