Saturday, March 8, 2025

Managing memory by removing cache files from PythonAnywhere Cloud

To See All Articles About Technology: Index of Lessons in Technology
Where are we?
04:40 ~ $ pwd
/home/keshavpawar137

04:41 ~ $ ls
README.txt  app_pt.py  models--openai--whisper-tiny.zip

04:43 ~ $ ls -a
.   .bashrc  .gitconfig  .keras  .my.cnf   .pythonstartup.py  .virtualenvs  app_pt.py
..  .cache   .ipython    .local  .profile  .vimrc             README.txt    models--openai--whisper-tiny.zip

04:43 ~ $ ls -lh
total 86M
-rwxr-xr-x 1 keshavpawar137 registered_users  232 Mar  5 09:53 README.txt
-rw-rw-r-- 1 keshavpawar137 registered_users 1.6K Mar  9 04:04 app_pt.py
-rw-rw-r-- 1 keshavpawar137 registered_users  86M Mar  9 04:42 models--openai--whisper-tiny.zip

04:43 ~ $ du -sh .
298M  

04:44 ~ $ rm -rf ~/.cache/pip
04:44 ~ $ find . -type d -name "__pycache__" -exec rm -rf {} +
04:45 ~ $ du -sh .
159M 

Can I delete : ~/.cache/pip

Yes, you can delete the ~/.cache/pip directory. This directory is used by pip to cache packages and metadata to speed up subsequent installations. Deleting it will not harm your system, but it will mean that pip will need to re-download any packages you install in the future, which might take a bit longer.

To delete the directory, you can use the following command in your terminal:

sh
rm -rf ~/.cache/pip

Make sure to double-check the command to avoid accidentally deleting the wrong files or directories.


... ... ... ... ... ...


Delete __pycache__ from all subdirectories

To delete all __pycache__ directories (including all their contents) from the current directory and its subdirectories, use the following find command:

bash
find . -type d -name "__pycache__" -exec rm -rf {} +

Explanation:

  • .: Start searching from the current directory.
  • -type d: Search for directories only.
  • -name "__pycache__": Match directories named __pycache__.
  • -exec rm -rf {} +: Executes the rm -rf command on each found directory ({} represents the directory name). The + batches the deletions into fewer rm calls, making it more efficient.

Important: This command permanently deletes the __pycache__ directories, so double-check you’re in the correct directory before running it.

Tags: Cloud,Linux,

No comments:

Post a Comment