Skip to content

Instantly share code, notes, and snippets.

@maitret
Forked from epsa-dev/chucherias.md
Last active October 11, 2023 22:37
Show Gist options
  • Save maitret/a7c1d0fb6c9ffc3c71e2ea9563c4e665 to your computer and use it in GitHub Desktop.
Save maitret/a7c1d0fb6c9ffc3c71e2ea9563c4e665 to your computer and use it in GitHub Desktop.
Terminal: Buscar, mover, listar, eliminar

** Listar y ordenar por tamaño Linux **

du -sh * | sort -h

** Listar y ordenar por tamaño NuShell**

ls -d | sort-by size -r

Buscar archivos con cierta ext:

find . -type f -name "*.php"

Checar el tamaño de carpetas:

du -h --max-depth=1 | sort -h 
du -sh /mnt/volume_nyc3_01/weekly/

Elimina error_log:

find -name "error_log" -exec rm -f '{}' \;

Mueve archivos a otra carpeta:

find -name "error_log" -exec mv '{}' /home/cliente/basura_el/ \;
find -name "error_log" -exec mv '{}' /home2/cliente/public_html/basura_el \;

find ~/public_html/admin/lib/files/productos -name ".htaccess" -exec mv '{}'  ~/.trash \;

http://www.ducea.com/2008/02/12/linux-tips-find-all-files-of-a-particular-size/

Buscar archivos:

find -type f -exec ls -lh {} \;
find -name "error_log" -type f -exec ls -lh {} \;
find -name "error_log" -type f -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
find -name "error_log" -type f -exec ls -lh {} \; | awk '{ print $5 ": " $9 }'

**Por tamaño: **

find /home/ -type f -size +512k -exec ls -lh {} \;

Espacio en virtfs: https://www.digitalocean.com/community/questions/virtfs-consuming-a-lot-of-space-cpanel http://docs.cpanel.net/twiki/bin/view/AllDocumentation/WHMDocs/VirtFS

Make sure that no users have jailed shell access in the "Manage Shell Access" interface. You can then use the script that you found in the blog post to unmout any bind-mounted directories:

for i in `cat /proc/mounts | awk '/virtfs/ {print $2}'`; do umount $i;done

CPanel also provides a script to remove the virtfs mounts:

/scripts/clear_orphaned_virtfs_mounts --clearall

How to Delete Every error_log File on a cPanel Server: https://www.webcitz.com/blog/tutorials/how-to-delete-every-error_log-file-on-a-cpanel-server.html

Locate All error_log Files:

find /home/*/public_html -type f -name error_log -exec du -sh {} \;

Locate All error_log Files and Sort by Disk Size:

find /home/*/public_html -type f -name error_log -exec du -sh {} \; | sort -n

Locate All files over 10mb:

find /home/*/public_html -type f -size +10000k -exec du -sh {} \;

Locate All error_log Files Over 100MB:

find /home/*/public_html -type f -name error_log -size +100000k -exec du -sh {} \;

Delete All error_log Files:

find /home/*/public_html -type f -iname error_log -delete

Delete All error_log Files Over 100MB:

find /home/*/public_html -type f -iname error_log -size +100000k -delete

Cron-Based Deletion of cPanel Server Error Log Files To setup a cronjob to run one of the two deletion commands above on a scheduled basis, you can do the following:

crontab -e

Which will open the crontab for root, then insert at the bottom of the file this command to delete all error_log files every day at 11PM server time:

* 23 * * * find /home/*/public_html -type f -iname error_log -delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment