In this article we will cover below topics
- Create hidden files and folders/directories
- Linux show hidden files and folders/directories
- Linux find hidden files and folder/directories
- Check size of hidden files and folder/directories
The commands from this article to view hidden files and folders can be used across any Linux platform such as Ubuntu, Debian, Linux Mint, RHEL, CentOS, SuSE etc or any Unix node such as HP-UX, Solaris, etc.
I am using RHEL/CentOS 8 node installed on Oracle VirtualBox. Please do let me know via comment section if you face any issues following the commands from this article to view hidden files or folders in Linux or Unix.
Create hidden Files
To create hidden files you just need to make sure the filename
starts with dot character (.). In Linux any filename which starts with
dot (.) character is considered as hidden file. For example here I
create a normal file using
touch command

# touch hidden_file
To list the file, as you see since the filename does not starts with dot
(.) character, it is not hidden
# ls -l
total 0
-rw-r--r--. 1 root root 0 Jan 21 18:51 hidden_file
Next we rename the file and make it .hidden_file starting with (.)
# mv hidden_file .hidden_file
Next if you try to list the available files, we don’t see hidden_file anymore.
# ls -l
total 0
In some Linux or Unix environment it is possible that ls command has
an alias to “ls -a”, so in such case even if you execute ls or
ls -l, this will show hidden files. For example here ls command
without -a will show hidden files
In such case execute alias command from the terminal
# ls -l
total 68
drwxr-xr-x. 3 root root 4096 Jan 21 19:05 .
dr-xr-x---. 6 root root 4096 Jan 21 18:51 ..
drwxr-xr-x. 2 root root 4096 Jan 21 19:51 .hidden_directory
-rw-r--r--. 1 root root 54894 Jan 21 19:28 .hidden_file
-rw-r--r--. 1 root root 0 Jan 21 19:05 normal_directory
-rw-r--r--. 1 root root 0 Jan 21 19:05 normal_file
Check alias on this node
# alias ls
alias ls='ls -a'
As you see there is an alias for ls command so by default it is
configured to hidden files and folders. To remove this temporarily
execute “unlias ls”
# unalias ls
Next show hidden files and folders using ls, now this works as
expected as we don’t see hidden folders or files.
# ls -l
total 0
-rw-r--r--. 1 root root 0 Jan 21 19:05 normal_directory
-rw-r--r--. 1 root root 0 Jan 21 19:05 normal_file
This is temporary fix only for the current session, you need to check
where this setting is configured for alias, it may be /etc/profile
or /etc/bashrc some other system file based on your distribution.
Similarly to create hidden files you can just put a (.) infront of the
filename, for example to create hidden files with filename “my_file”:
# touch .my_file
Create hidden folder or directory

The steps to create hidden folder or directory in Linux or Unix is
similar to create hidden files. We just need to make sure the folder
name starts with dot (.) character.
[root@server3 test]# mkdir .hidden_directory
Now list the available files in current directory, as expected we don’t see any directory/folder since the folder is hidden. So we were able to create hidden folder here.
[root@server3 test]# ls -l
total 0
Linux show hidden files and folders with ’ls’ command
- In this example we will use
lscommand in Linux show hidden files and folders. - We can use
lscommand with “-a” to show all files including hidden files and folder. - With
-a“we do not ignore entries starting with.” that means also Linux show hidden files and folders. - For example to show hidden files and folders which we created in above
steps, navigate to your directory and execute
ls -a - We have also used
-lto give us a long list so we usels -alto show all files under test directory in long list format

[root@server3 test]# ls -al
total 12
drwxr-xr-x. 3 root root 4096 Jan 21 19:05 .
dr-xr-x---. 6 root root 4096 Jan 21 18:51 ..
drwxr-xr-x. 2 root root 4096 Jan 21 19:02 .hidden_directory
-rw-r--r--. 1 root root 0 Jan 21 18:51 .hidden_file
As you see we were able to show hidden folders and files with “ls -a”
which we had created earlier in this article.
[root@server3 test]# ls -al
total 8
drwxr-xr-x. 2 root root 4096 Jan 21 18:53 .
dr-xr-x---. 6 root root 4096 Jan 21 18:51 ..
-rw-r--r--. 1 root root 0 Jan 21 18:51 .hidden_file
Linux show hidden files and folders with ‘find’ command
Now with ls command we were able to show hidden files in one directory
or may be multiple directories in Linux and Unix. But with ls it is
little tricky to show hidden folders and files across all partitions.
Here we can find hidden files using find command in Linux or Unix.

Now from our chapter “create
hidden
files”
and “create hidden
directory”,
we know that hidden files start with dot (.) character. So we can
use this trick with find command to find hidden files.
For example to <strong>find hidden files</strong> use -type f under
/etc/ directory we can use below command
# find /etc/ -type f -name '.*'
/etc/selinux/targeted/.policy.sha512
/etc/skel/.kshrc
/etc/skel/.bash_profile
/etc/skel/.bashrc
/etc/skel/.bash_logout
/etc/.pwd.lock
/etc/.updated
Here we are only search of files using “-type f” and any filename
starting with dot (.)
With Linux show hidden files and folders we can use the same command
with -type dto find hidden folders under /usr
# find /usr/ -type d -name '.*'
/usr/java/jre1.8.0_172-amd64/.java
/usr/java/jre1.8.0_172-amd64/.java/.systemPrefs
/usr/local/avamar/etc/.tmp
Here we could not have used “ls -a” to show hidden files in all these
directories without using extra commands, so find is a better
alternative to find hidden folder and files in Linux or Unix.
Check size of hidden files and folders

Now once you find hidden files or folders, you may also wish to check size of hidden files or folders.
For example we will find hidden files under our ~/test directory
[root@server3 test]# find . -type f -name '.*'
./.hidden_file
./.hidden_directory/.hidden_file_2
So we have two hidden files, we can use ls with -Sh to check size of hidden files but it again has it’s own challenges.
Here
- -S means sort by file size
- -h means print sizes in human readable format (e.g., 1K 234M 2G)
We use ls -lSha to show and check size of hidden file but as you see
ls could only identify .hidden_file in the current folder but missed
.hidden_file_2 available inside .hidden_directory
[root@server3 test]# ls -lSha
total 68K
-rw-r--r--. 1 root root 54K Jan 21 19:28 .hidden_file
drwxr-xr-x. 3 root root 4.0K Jan 21 19:05 .
dr-xr-x---. 6 root root 4.0K Jan 21 18:51 ..
drwxr-xr-x. 2 root root 4.0K Jan 21 19:51 .hidden_directory
-rw-r--r--. 1 root root 0 Jan 21 19:05 normal_directory
-rw-r--r--. 1 root root 0 Jan 21 19:05 normal_file
ls -lSha .* which shall also check child
directory for hidden files and print it’s size but again this tool is
not very convenient.
We will use du command to check size of hidden files in Linux or
Unix. du command is used to estimate file space usage. We must combine
du with find commands to first we find hidden files and folders and
then we check size of hidden files using du command
For example to check size of hidden files under /test folder
[root@server3 test]# find ~/test/ -type f -name '.*' -exec du -ah {} +
56K /root/test/.hidden_file
984M /root/test/.hidden_directory/.hidden_file_2
Similarly to check size of hidden files under /tmp folder
# find /tmp/ -type f -name '.*' -exec du -ah {} +
4.0K /tmp/smem/smem-1.4/.hg_archival.txt
4.0K /tmp/smem/smem-1.4/.hgtags
4.0K /tmp/test1/usr/lib/x86_64-linux-gnu/firmware-cna-emulex-2018.02.01-1.24/.cpq_package.inc
1.6M /tmp/test1/usr/lib/x86_64-linux-gnu/firmware-cna-emulex-2018.02.01-1.24/.setup
Lastly I hope the steps from this article to Linux show hidden files and folders, create hidden files, create hidden folder and find hidden files and folders in Linux and Unix was helpful. So, let me know your suggestions and feedback using the comment section.


