Saturday, February 5, 2022

[SOLVED] How to delete a directory in Linux starting with dot "."?

Issue

I am using Linux environment, and I want to delete a folder starting with .(dot). For that I have used the command as below and it returns an error as mentioned:

rm -rf ${WORKSPACE}/.*

Error - rm: refusing to remove '.' or '..' directory: skipping '/home/workspace/myFile/.'

Inside my workspace I have files and directories starting with dot(.), I need to specifically delete a directory named as .jazz. Can someone help me with the Linux command for it ? Thanks!


Solution

The issue is your command is also instructing to remove . and .. which would not be possible. When trying to remove files starting with hidden ., you will need to at least provide a wildcard so it is not also attempting to remove . and ..

$ rm -rf "${WORKSPACE}"/.[a-z]*
or
$ rm -rf "${WORKSPACE}"/.[!.]* # As pointed out by tripleee

The second option will remove ALL hidden files and directories that start with a single .



Answered By - HatLess
Answer Checked By - Dawn Plyler (WPSolving Volunteer)