How to Find and Remove#
find /home/user/code -used +7 -type d -name node_modules -prune -print0 | xargs -0 /bin/rm -rf
- to find inside
/home/user/code - directories (
-type d) - named
node_modules(-name node_modules) - that were used more than 7 days ago (
-used +7) - if found, stop looking inside
-prune - and output a full name
-print0(with 0 instead of newline) - pass the found full name (
xargs -0) - to
rm(/bin/rm -rf)
Save Script#
/home/user/bin/cron/remove_node_modules:
#!bin/bash
find /home/user/code -used +7 -type d -name node_modules -prune -print0 | xargs -0 /bin/rm -rf
How to Automate#
Add the script to crontab
- open a crontab file
crontab -e(to change editor runselect-editor) - speicfy an interval and a path to the script file
@weekly /home/user/bin/cron/remove_node_modules - list user’s crontab:
crontab -l