- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Working with Hidden Files in Linux
Introduction
Hidden files in Linux operating system are files that are not displayed when the ls command is executed. A hidden file's name begins with a dot. Not only files, but also directories, can be hidden in Linux. Files in Linux are hidden for a variety of purposes. One of them is to prevent us from accidentally modifying the contents of these files. Another possibility is to avoid these files from being accidentally deleted. Files on shared networks may be hidden for privacy reasons. The majority of hidden files contain environment settings or data that are viewed by applications that the user is running. They should not be edited by the user, and only the application should have access to them.
In this article, we will talk about some ways to work with hidden files. We will discuss about different methods for finding hidden files and how to manipulate them.
Find Hidden Files Using ls Command
The hidden files can be found using this ls command −
$ ls -a
This will show the hidden files as well as normal files.
.cache .emacs.d .profile Videos .. .config ff Public .viminfo .aws dd .gnupg results.txt wd ** many more files ** .bash_history Desktop .local .ssh .bash_logout Documents Music .sudo_as_admin_successful .bashrc Downloads Pictures Templates
To display hidden files with the ;ls’ command, we use the ‘-a’ flag. The ‘-a’ flag stands for "all" and instructs the “ls” command list all files (including hidden files). To display additional information about each file, we can use the ‘-l’ flag, which stands for "long listing." The ‘-l’ flag displays the file type, permissions, group, size, owner, and modification time.
$ ls -al
This command will display all files, including hidden files, in the current directory, along with detailed information for each file.
total 112 drwxr-xr-x 17 papan papan 4096 Mar 17 05:39 . drwxr-xr-x 3 root root 4096 Feb 17 20:53 .. drwxrwxr-x 2 -- -- 4096 Feb 25 01:13 .aws ** many more files… ** -rw------- 1 papan papan 6101 Mar 16 02:48 .bash_history -rw-r--r-- 1 papan papan 220 Feb 17 20:53 .bash_logout -rw-r--r-- 1 papan papan 3771 Feb 17 20:53 .bashrc
Find Hidden Files Using Find Command
This command is a useful tool for locating files and directories on Linux. To find hidden files using the find command, we can use the ‘-name’ option to indicate the name of the file. In Linux, hidden files begin with a dot, so we can use the -name ".*" option, this will search all the files present in our system that starts with a dot. Here we have used ‘-type f’ option to search for files only.
$ find . -name ".*" -type f
This command will search for all hidden files in recursive manner and also display their names and paths.
./.profile ./Desktop/cbl/.1.cbl.swp ./.bashrc ./.emacs.d/auto-save-list/.saves-6894-ubuntu~ ** many more folders ** ./.bash_history ./.bash_logout ./.viminfo ./.sudo_as_admin_successful
To find only hidden directories on Linux, we need to use some options to filter the results. The “-name” option matches the pattern against the name of files or directories, using ".*" to find filenames that start with a dot, which is the convention for hidden files in Linux. -type d only searches for directories, while -maxdepth limits the search to the current directory, preventing a large number of results. “2> /dev/null” redirects error messages to the null device, avoiding clutter in the output.
$ find . -name ".*" -maxdepth 1 -type d 2> /dev/null
This command will find and list only the hidden directories.
./.aws ./.cache ./.emacs.d ./.local ./.ssh ./.config ./.gnupg
Hide Files and Directories Using Terminal
We may want to hide files on Linux for security or other reasons. Hiding files or directories makes them invisible to user and file system. We can create and hide files and directories by using the terminal.
$ touch .hidden_file
The hidden file is created now to confirm this we can type this command −
$ ls -a .hidden_file
To create a hidden directory, we can type this command −
$ mkdir .hidden_directory
To confirm our hidden directory is created or not we can use this command −
$ ls -a .hidden_directory .hidden_file
Manipulate with the Hidden Files
Sometime we may also need to manipulate them in various ways like copy or edit.
To copy a hidden file from one directory to another, we can use the cp command to copy the file and any subdirectories it contains. For example −
$ cp .hidden_file .hidden_directory/
This command uses the cp command to copy the hidden file to the hidden directory.
To edit a hidden file, we can use any text editor we like, such as nano −
$ nano .hidden_directory/.hidden_file
This will open the hidden file in the nano text editor, allowing us to make changes to its contents.
GNU nano 4.8 .hidden_directory/.hidden_file Modified simaran roy!! ^G Get Help ^O Write Out ^W Where Is ^K Cut Text ^J Justify ^X Exit ^R Read File ^\ Replace ^U Paste Text ^T To Spell
Conclusion
Working with hidden folders is critical for handling system-related files and folders. In this article, we explained how to deal with hidden folders in Linux, including using the terminal and text editor. We can simply work with hidden files on our Linux operating system using these techniques.