Fullstack Wolfpack

Blog about full stack programming skills

Removing All Files And Directories, Including Hidden Ones

2/11/19 by Mark McDermott

When working with git On Linux, to remove all files and directories in a folder, including hidden ones, use

rm -r * .*

The rm is for remove. The -r flag is for recursive so it will delete folders. The first * means, "delete all files and directories in the current folder". The .* means delete any files/folders that begin with a period. Since hidden folders and files start with a period, this removes hidden files/folders. Hidden directories will be ignored by rm by default if you don't specify .*.

I work with git a lot and there's always the hidden .git folder and usually I also like to add a .gitignore file. This is great until I need to delete the parent folder. I was a bit confounded until I found the .* input to rm which takes care of it. One thing to note is that rm will throw an non-fatal error message:

rm: refusing to remove '.' or '..' directory: skipping '.'
rm: refusing to remove '.' or '..' directory: skipping '..'

This is fine. The . and .. are the "names" of the current folder and its parent folder, respectively. A linux directory is really just a list of names (and inode numbers) of the files and directories inside it. The . and .. cannot and should not be removed. Here is a good explanation of how inodes and Linux directories work, if you're interested.