How to remove all files including hidden files in Linux ?
In this post, we will see how to remove all files from a directory in Linux including the hidden files.
Lets us have a look how to remove all files.
1. Goto desired directory and remove the files.
[root@ngelinux001 tmp]# pwd /tmp [root@ngelinux001 tmp]# rm -rf * [root@ngelinux001 tmp]# ls -ltr total 0
All files are removed now, however if you look at hidden files, there are many files available.
2. Check and remove hidden files.
[root@ngelinux001 tmp]# df -h . Filesystem Size Used Avail Use% Mounted on /dev/sda2 667G 39M 667G 1% /tmp [root@ngelinux001 tmp]# du -sh . 3.5M . [root@ngelinux001 tmp]# ls -altr total 44 drwxrwxrwt. 2 root root 6 Dec 7 2021 .XIM-unix drwxrwxrwt. 2 root root 6 Dec 7 2021 .Test-unix drwxrwxrwt. 2 root root 6 Dec 7 2021 .font-unix drwx------ 2 jojos ngegrp1 20 Sep 26 12:30 .esd-267140 drwx------ 2 avina ngegrp1 20 Nov 14 16:09 .esd-282551 -rw-rw-rw- 1 chauhan ngegrp1 0 Nov 21 10:33 .cdsor.15341109916920886994 drwx------ 2 jain12 ngegrp1 20 Dec 6 14:26 .esd-275345 drwxrwxr-x 3 chauhan ngegrp1 22 Dec 23 18:18 .temp_ptree_testcase_839751139 drwxrwxrwt. 2 root root 116 Dec 25 00:00 .ICE-unix drwx------ 2 mkigupt ngegrp1 20 Dec 25 00:00 .esd-34976 drwxr-xr-x 3 mkigupt ngegrp1 22 Dec 25 00:32 .temp_ref_5g_1317796151 drwxrwxrwx 3 userA ngegrp1 22 Jan 2 12:59 .temp_power_block_1862939599 drwxrwxr-x 3 userA ngegrp1 22 Jan 2 13:20 .temp_power_block_2215923748 drwx------ 2 userA ngegrp1 6 Jan 3 09:49 .esd-282314 drwxrwxrwt. 2 root root 6 Jan 3 09:49 .X11-unix -rw-r--r-- 1 root root 19661 Jan 3 09:58 .mount. dr-xr-xr-x. 62 root root 4096 Jan 3 10:00 .. drwxrwxrwx 3 amarjain ngegrp1 41 Jan 3 10:02 .ngegrp drwxrwxr-x 3 chauhan ngegrp1 22 Jan 3 10:02 .temp_ptree_testcase_3661102030 drwxrwxrwt. 18 root root 16384 Jan 3 10:06 . [root@ngelinux001 tmp]# rm -rf .* rm: refusing to remove ‘.’ or ‘..’ directory: skipping ‘.’ rm: refusing to remove ‘.’ or ‘..’ directory: skipping ‘..’ [root@ngelinux001 tmp]# ls -altr total 4 dr-xr-xr-x. 62 root root 4096 Jan 3 10:00 .. drwxrwxrwt. 2 root root 6 Jan 3 10:07 . [root@ngelinux001 tmp]#
Now as we can see all the files including hidden files are removed.