Techolac - Computer Technology News
  • Home
  • Internet
  • Business
  • Computers
  • Gadgets
  • Lifestyle
  • Phones
  • Travel
  • Tech
  • More
    • Automotive
    • Education
    • Entertainment
    • Health
    • SEO
    • Linux
    • WordPress
    • Home Improvement
    • How to
    • Games
No Result
View All Result
  • Home
  • Internet
  • Business
  • Computers
  • Gadgets
  • Lifestyle
  • Phones
  • Travel
  • Tech
  • More
    • Automotive
    • Education
    • Entertainment
    • Health
    • SEO
    • Linux
    • WordPress
    • Home Improvement
    • How to
    • Games
No Result
View All Result
Techolac - Computer Technology News
No Result
View All Result
Home Linux

How to remove hidden files in Linux

by Editorial Staff
November 22, 2018
in Linux
Reading Time: 4 mins read

[ad_1]

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.

Table of Contents
How to display hidden / dot files in Linux
Command to remove hidden files in Linux
Getting rid of warning message rm: refusing to remove ‘.’ or ‘..’ directory: skipping
How to delete hidden files in Linux
A note about the GNOME desktop environment and hidden files
Conclusion

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

Linux display hidden files command
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 ~/.??*

Just display hidden dot files in Linux with ls
See “Linux / Unix: Find And List All Hidden Files Recursively” for more info.

Command to remove hidden files in Linux

To remove hidden files in Linux, try:
rm .file
rm -i /path/to/.fileName
rm -i /path/to/.dirName
rm -rf /path/to/dir/.*

Of course, you can not delete two individual directories:

  1. . – The current directory indicated by a single dot.
  2. .. – The parent directory indicated by two successive dots.

Let us try out:
cd /tmp/
mkdir demo
cd demo
mkdir app
>.config
>.vimrc
>.bashrc
ls -a | egrep '^.'
ls
rm .vimrc
ls -a | egrep '^.'
rm -rfv /tmp/demo/.*

Delete or remove hidden files in Linux command

Getting rid of warning message rm: refusing to remove ‘.’ or ‘..’ directory: skipping

Simply add the following 2> /dev/null at the end of the rm command:
rm -rfv /dir/.* 2>/dev/null
rm -rfv /tmp/demo/.* 2>/dev/null

Sample outputs:

removed '/tmp/demo/.bashrc'
removed '/tmp/demo/.vimrc'

/dev/null is nothing but a special file that discards all data written to it. See the following for more info:

How to delete hidden files in Linux

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/ -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

## 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

See

A note about the GNOME desktop environment and hidden files

In GNOME’s file manager, the keyboard shortcut Ctrl+H enables or disables the display of hidden files. CTRL+H act as a toggle button to hide or show hidden dot files in the GNOME.

Gnome Hide or show hidden dot files
Gif.01: Gnome Hide or show hidden dot files using CTRL+H or options menu

Conclusion

This page explains how to remove hidden files in Linux or Unix-like operating systems. Further, it explained how to redirect output to avoid warning message while using the rm command.

[ad_2]

Related Posts

Apache, MySQL Performance

How to Optimize Apache, MySQL Performance for 1GB RAM VPS Centos/RHEL

April 7, 2024
Top 5 MySQL Performance Tuning Tips

Top 5 MySQL Performance Tuning Tips

January 25, 2023

Top Commands to Check the Running Processes in Linux

May 27, 2022

4 Tips to Prevent and Troubleshoot the ImagePullBackOff Kubernetes Error

March 30, 2022

How Common Signals are Used in Kubernetes Pod Management

November 20, 2021

How to Transfer Windows 10 to SSD?

April 14, 2022

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Articles

  • Biometric Banking: Why Your Face, Fingerprint, and Voice Are the New PIN
  • The Revolution in Telecommunications: How technology is changing connections
  • Understanding the Differences: BACS vs CHAPS Payment Systems Explained
  • Why CSPM Is the Unsung Hero of Enterprise Cloud Security
  • The New Face of Antivirus: Smarter, Faster, and Built for 2025 Threats
  • What are The Responsibilities of your tax preparer?
  • Best 10 Cryptocurrency Exchange Development Companies 2025

Related Posts

None found

  • DashTech
  • TechDaddy
  • Terms and Conditions
  • Disclaimer
  • Write for us

© Techolac © Copyright 2019 - 2022, All Rights Reserved.

No Result
View All Result
  • Home
  • Internet
  • Business
  • Computers
  • Gadgets
  • Lifestyle
  • Phones
  • Travel
  • Tech
  • More
    • Automotive
    • Education
    • Entertainment
    • Health
    • SEO
    • Linux
    • WordPress
    • Home Improvement
    • How to
    • Games

© Techolac © Copyright 2019 - 2022, All Rights Reserved.