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.
Leave a Reply