• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Dev Tips / Quickly Delete Large Directory from the Command line

Quickly Delete Large Directory from the Command line

Last updated on April 23, 2022 by Sal Ferrarello

When deleting a large directory from the command line, it can take a frustratingly long time for the task to complete. This is a trick I use to speed things up.

For example, if I want to delete the node_modules directory from the current directory historically I would run the following slow command.

# Slow
rm -rf node_modules

It is much faster to break this into two steps:

mv node_modules delme
rm -rf delme &

Explanation of Steps

1. Move the Directory

First, I rename the directory to delme. This is very fast and allows me to recreate the node_modules directory.

mv node_modules delme

2. Delete the Directory in the background

By adding an ampersand (&) to the end of a command, the command runs in the background.

rm -rf delme &

This command is still a slow command, but since it is running in the background you can continue working.

Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit

Filed Under: Computing, Dev Tips, Solution Tagged With: command line

Reader Interactions

Leave a Reply Cancel reply

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

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in