If you have a few years of experience in the Linux ecosystem, and you’re interested in sharing that experience with the community, have a look at our Contribution Guidelines.
1. Introduction
In this article, we’ll take a look at hidden files and directories in Linux, including their purpose and some common misconceptions.
We’ll also see how we can use simple flags to show hidden files and directories on the command line and explore some special-purpose hidden files.
2. Purpose of Hidden Files
In some instances, we may want to hide specific files or directories inside another directory. For example:
- User preferences
- Operating system files
- Project-specific files (e.g., Eclipse configuration in an Eclipse project)
- Repository-specific files (e.g., Git configuration in a Git repository)
To hide a file, we prepend a dot to its name.
Thus, we can create a hidden file named .hidden.sh using touch:
$ touch .hidden.shWe can also create a hidden directory by prepending a dot to the directory name.
For example, we can create a hidden directory named .preferences using mkdir:
$ mkdir .preferencesTo differentiate between hidden and visible files, we also create a visible file using touch:
If we display the files in the current directory using the ls -l command, we only see visible.sh — we don’t see our hidden file or directory:
$ ls -l -rw-rw-rw- 1 jalbano jalbano 0 Jan 4 09:53 visible.shSince we have hidden our .hidden.sh file and .preferences directory, ls only displays our visible.sh file by default.
A common misconception, though, is that hidden files can be used as a means of security. Obscurity is not security, so hidden files should not be used as a means of security. As we will see below, we can easily display hidden files and directories using ls and, therefore, hidden files provide no protection from unwanted eyes.
3. Display Hidden Files
To display hidden files or directories, we include the a flag in our ls command.
The a flag instructs the ls command to include all files — and not ignore files starting with a dot.
Therefore, we can display the hidden files and directories we created by executing ls -al:
$ ls -al drwxrwxrwx 1 jalbano jalbano 512 Jan 4 09:53 . drwxr-xr-x 1 jalbano jalbano 512 Jan 3 22:37 .. -rw-rw-rw- 1 jalbano jalbano 0 Jan 3 22:37 .hidden.sh drwxrwxrwx 1 jalbano jalbano 512 Jan 3 22:37 .preferences -rw-rw-rw- 1 jalbano jalbano 0 Jan 4 09:53 visible.shUsing this command, we can now see both the hidden and visible files in the current directory.
4. Special-Purpose Hidden Files
Besides .hidden.sh and .preferences, our ls -al command also lists the current directory (.) and the parent directory (..).
These two directories are included in all directories by default and act as references that allow us to navigate relative to our current directory.
For example, if we wish to navigate to the parent of the directory we are currently in, we can execute:
To hide these two directories while displaying all other hidden files and directories, we use the A flag in our ls command.
This command displays almost all files and directories, including hidden ones, except for the current and parent directories.
If we execute ls -Al, we’ll see:
$ ls -Al -rw-rw-rw- 1 jalbano jalbano 0 Jan 3 22:37 .hidden.sh drwxrwxrwx 1 jalbano jalbano 512 Jan 3 22:37 .preferences -rw-rw-rw- 1 jalbano jalbano 0 Jan 4 09:53 visible.shThis allows us to view all of the files and directories we have created — ignoring the default hidden directories — thus removing clutter.
5. Conclusion
In this tutorial, we looked at the purpose of hidden files, how to create them, and how to view them.
We also explored some of the special-purpose hidden directories included in Linux by default.
As noted above, we should use hidden files as a mechanism for reducing clutter and not as a means of securing a file or directory.
If you have a few years of experience in the Linux ecosystem, and you’re interested in sharing that experience with the community, have a look at our Contribution Guidelines.
Home / How To / Using ls Command to Show Hidden Files in Linux Terminal
How to show hidden files in Linux command line. Know which command will list the hidden files in Linux Ubuntu? Use Ubuntu ls command to show hidden files in Linux command line.
Ubuntu LS Command
The ls command can be used to show hidden files in Ubuntu using terminal (command line). Ls command has many options which can be used to get info about files. Ls command options “-a” and “-l” can be used with Ubuntu ls command to show hidden files in Ubuntu using terminal command line.
The ‘ls’ program lists information about files (of any type, including directories). Options and file arguments can be intermixed arbitrarily, as usual. For non-option command-line arguments that are directories, by default ‘ls’ lists the contents of directories, not recursively, and omitting files with names beginning with ‘.’. For other non-option arguments, by default ‘ls’ lists just the file name. If no non-option argument is specified, ‘ls’ operates on the current directory, acting as if it had been invoked with a single argument of ‘.’.
By default, the output is sorted alphabetically, according to the locale settings in effect.(1) If standard output is a terminal, the output is in columns (sorted vertically) and control characters are output as question marks; otherwise, the output is listed one per line and control characters are output as-is.
Because ‘ls’ is such a fundamental program, it has accumulated many options over the years. They are described in the subsections below; within each section, options are listed alphabetically (ignoring case). The division of options into the subsections is not absolute, since some options affect more than one aspect of ‘ls’’s operation.
Show Hidden Files in Ubuntu Terminal
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.
The following command options can be used:
- ‘-a’ or ‘–all’: In directories, do not ignore file names that start with ‘.’.
- ‘-A’ or ‘–almost-all’: In directories, do not ignore all file names that start with ‘.’; ignore only ‘.’ and ‘..’. The ‘–all’ (‘-a’) option overrides this option.
- ‘-l’ or ‘–format=long’ or ‘–format=verbose’: In addition to the name of each file, print the file type, file mode bits, number of hard links, owner name, group name, size, and timestamp (note Formatting file timestamps::), normally the modification time. Print question marks for information that cannot be determined. For each directory that is listed, preface the files with a line ‘total BLOCKS’, where BLOCKS is the total disk allocation for all files in that directory. The block size currently defaults to 1024 bytes, but this can be overridden (note Block size::). The BLOCKS computed counts each hard link separately; this is arguably a deficiency.
Using ls Command to Show Hidden Files in Ubuntu Terminal
You can use the following ls command options to list hidden files (see screenshots):
Note that there is a difference between -a and -A option. The -a option displays hidden files and directories with current directory (.) and parent directory (..) where -A ls command options doesn’t show it.