Linux delete hidden files in current directory

Original link: https://hellodk.cn/post/1045

We all know that using rm -rf ./* or rm -rf * cannot delete hidden files in the current directory. How do I delete hidden files ( start with . )?

 $ rm -rf .*

This works, but it will prompt you that . and .. cannot be deleted, that is, the current directory and the previous directory cannot be deleted. Obviously, this is not an elegant solution.

The best way is to make use of regular expressions, as follows

 $ rm -rf .[!.]*
  • The first dot means that the file starts with .
  • [!.] means the second character cannot be .
  • * represents any character (may not exist)

This perfectly achieves the goal.

This article is reprinted from: https://hellodk.cn/post/1045
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment