How To Find Hidden Files In Linux Using Find Command

Do you know which command can be used to show hidden files? Don’t worry. In this tutorial, you will learn how to find hidden files on Linux using the Find and ls commands.

Hidden files in the Linux operating system are files that are not displayed when the ls command is executed. A hidden file’s name begins with a dot. Any hidden file is not displayed by the file manager, but it is still there in its folder.

Find Hidden Files Using the LS Command

The ‘ls’ command lists information about files and directories. The ls command can be used to show hidden files in Ubuntu using the terminal command line.

By default, ‘ls’ lists the contents of directories, but it will not show hidden files and folders (files and folders with names beginning with ‘.’), and the on-screen result is not displayed recursively.

The most basic command usage of ls is “ls -a”. The “ls” command option “-a” will show all files and folders, including hidden ones. It shows the list in “long format,” which includes the permissions, owner, group, size, last-modified date, number of hard links, and the filename described.

You must note the difference between ‘-a’ and ‘-A’. Both have different meanings and are used accordingly.

  • ‘-a’ or ‘–all’: It shows hidden files and do not ignore file names that start with ‘.’.
  • ‘-A’ or ‘–almost-all’: It shows hidden files and do not ignore all file names that start with ‘.’; ignore only ‘.’ and ‘..’. If you are using both, the ‘-all’ (‘-a’) option overrides this option.

When you use the ls command options with “-a” and “-l” the command will show hidden files.  The ‘-l’ flag displays the file type, permissions, group, size, owner, and modification time.

But when you use ls -a command with the grep option, it will show only the hidden files (all that start with a . (dot)).

See the command below:

ls -a | grep "^\."

The main drawback of the above command is that it is quite hard to tell which is the file and which is the folder. To do so, you can see the hidden files and directories in the long listing format. To display only the hidden files and directories in the listing format, you can use the following command:

ls -dl .*

If you want to display only hidden files and do not wish to see the hidden directories/folders, run the following command:

ls -ld .* |grep -v ^d

When you execute ls -a, it looks in directories, and it does not ignore file names that start with ‘.’.

Always remember that hidden files have a dot (.) before their names.

Find Hidden Files In Linux Using find Command

Another UNIX base command that can be used to see hidden files is the find command. To find hidden files using the find command, use the ‘-name’ option to indicate the name of the file. 

Because in Linux, hidden files begin with a dot, the following command will search for all hidden files in a recursive manner and also display their names and paths.

find . -name ".*" -type f 

We can also use the other format of the find command to find and list all hidden files and to show all the files whose names begin with a dot (.).

find . -name ".*" -maxdepth 1 2> /dev/null

If you wish to see only the hidden files and folders, run the following command:

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

In this article, we will talk about some ways to work with hidden files. We will discuss different methods for finding hidden files and how to manipulate them.

Alternatively, you can use the GUI method to view hidden files on Linux. Simply navigate to that folder and press Ctrl+H. You will see all the hidden files. To hide these files, press Ctrl+H again.

Bonus Tip: Backup files are also hidden by default. A backup file is a file with a ~ at the end of its name and are automatically created backup copies of documents.

Author: Team Linux Ledger

The team of Linux experts and open source enthusiasts who are passionate about sharing their expertise with you through in-depth tutorials, news, and updates on various aspects of open source in general and Linux in particular A team that helps you become a better Linux user.

Leave a Comment