I am a new Linux sysadmin and Ubuntu Linux user. How can I remove hidden files in Linux? How do I delete hidden files in Linux starting with . (dot) character?
Introduction: Linux and Unix like operating system allow users to hide files. By default, all hidden files not listed by the ls command. Any filename begins with a dot (.) becomes a hidden file. For example ~/.bashrc is a hidden file in Linux. Hidden files are often known as a dot file. All dot files used for storing user preferences on Linux. Please note that hidden or dot files are not a security mechanism. They exist to reduced “clutter” of the contents of a directory listing.
How to display hidden / dot files in Linux
One an display hidden files by passing the -a option to the ls command. For example: ls -a ls -la ls -l /path/to/.filename
You can add a “/” after directory names in Linux: ls -F ls -Fa One can get a reverse listing: ls -r ls -ra To just display dot/hidden files in Linux use any one of the following command along with grep command/egrep command: ls -a | egrep '^.' ls -A | egrep '^.' ls -l ~/.[^.]* | less ls -ld ~/.[^.]* ls -l ~/.??* ls -ld ~/.??*
One can use the find command to list or delete hidden files. The syntax is as follows:
## List all hidden dirs in /etc/ ##find/etc/-maxdepth1-type d -name".*"## List all hidden files in /etc/ ##find/etc/-maxdepth1-type f -name".*"## Find all hidden files in /tmp/data/ and delete it ##find/tmp/data/-maxdepth1-type f -name".*"-delete## Find all hidden files in /tmp/data/ (and it's sub-dirs) and delete it ##find/tmp/data/-type f -name".*"-delete
## List all hidden dirs in /etc/ ##
find /etc/ -maxdepth 1 -type d -name ".*" ## List all hidden files in /etc/ ##
find /etc/ -maxdepth 1 -type f -name ".*" ## Find all hidden files in /tmp/data/ and delete it ##
find /tmp/data/ -maxdepth 1 -type f -name ".*" -delete ## Find all hidden files in /tmp/data/ (and it’s sub-dirs) and delete it ##
find /tmp/data/ -type f -name ".*" -delete
The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.