Find largest folder in SSH

Find largest folder in ssh

Is your cPanel server running out of space? Need to find out where the usage is coming from?

Finding the largest folder is as easy as running the following simply command from an SSH (or Terminal in cPanel’s WHM) session:

du -hs * | sort -rh | head -5

The above command will output the largest folders in the current directory in a human readable format that is easy to understand.

You can continue to further nail down the source of the usage by entering the next folder and entering the above command again and again until you find the exact source of the high usage.

Find Current Inode Usage Using SSH

Find largest folder in ssh

Need to find out how many inodes each user is using on your cPanel server?

Simply run the following command from SSH:

 

cd /home

echo "Inode usage for: $(pwd)" ; for d in `find -maxdepth 1 -type d |cut -d\/ -f2 |grep -xv . |sort`; do c=$(find $d |wc -l) ; printf "$c\t\t- $d\n" ; done ; printf "Total: \t\t$(find $(pwd) | wc -l)\n"

 

The above command will create a list of users and their current inode usage. The list can be long depending on how many users you have.

cPanel Find and Delete Trash Folders

cPanel emtpy trash for all users

If you find you have a lot of users with large amounts of files in their Trash in cPanel, you can run the following command from SSH to delete them all in one go!:

 

find /home/*/.trash/* -exec rm -rf {} \;

 

Keep in mind it is not possible to retrieve any data in the folders you are deleting, so only do this if you know what you are doing and are absolutely sure you do not need the data! 

Find and Remove a File or Folder in SSH

Find largest folder in ssh

Need to find and remove a particular file and/or folder and know the name, but not the location?

Use the following command to find and remove it!:

find . -name "error_log" -exec rm -rf {} \;

 

The above will search the current folder and subfolders for the file named "error_log" and delete every one it finds.

You can substitute "error_log" with any file or folder name you want!

cPanel Log Locations

cPanel emtpy trash for all users

 

cPanel

All cPanel logs are located in the folder:

/usr/local/cpanel/logs

The access_log contains all traffic to WHM, cPanel, and Webmail:

/usr/local/cpanel/logs/access_log

The error_log contains all errors when accessing a cPanel related site:

/usr/local/cpanel/logs/error_log

 

Apache

On cPanel servers each site has its own traffic log, but Apache's main access log can be viewed here:

/usr/local/apache/logs/access_log

To view each cPanel accounts individual access-logs:

/usr/local/apache/domlogs

Apache errors are logged to the error_log file:

/usr/local/apache/logs/error_log

 

Exim

The exim main log contains all transaction information:

/var/log/exim_mainlog

The reject log contains all connections that were rejected:

/var/log/exim_rejectlog

 

FTP

Regardless of the FTP server chosen in cPanel, it does not have it's own log and instead logs to:

/var/log/messages

 

SSH

On most servers the SSH service will log to the secure and system messages log files:

/var/log/secure
/var/log/messages

 

 

 

Manually Export MySQL Database

Find largest folder in ssh

How do I manually export or "dump" a MySQL database from command line or SSH?

You can dump a MySQL database to the current folder from an SSH session using the following command:

mysqldump –no-create-db=true -uUSERNAME -pPASSWORD DATABASE > filename.sql

So if your database name is "USER_MYDATABASE" and your database username is "USER_USER1" and the password is "PASSWORD1" and you would like to save the dump as "mydump.sql", you would use the following:

mysqldump –no-create-db=true -uUSER_USER1 -pPASSWORD1 USER_MYDATABASE > mydump.sql

 

 

 

Search For Specific Text In File

Find largest folder in ssh

How can I find a specific text string in a file or multiple files from an SSH session?

You can use the grep command to easily find text within files.

From an SSH session, run the following command:

grep -H -r "<Text-To-Find>" <search-location>

Where <Text-To-Find> would be replaced with the text you want to search for and <search-location> is where the files are located that you want to search within.

For example, if you wanted the find all files containing the string "base64_decode" in the home folder, you would use:

grep -H -r "base64_decode" /home

 

 

 

Bulk Edit DNS Zone On cPanel

cPanel emtpy trash for all users

How do I bulk edit a DNS zone on cPanel?

Changed nameserver name and need to update all the DNS zones on your cPanel server?

Using the replace command from an SSH session will make it simple.

Just use the following command:

replace "<old-nameserver>" "<new-nameserver>" — /var/named/*.db

Where <old-nameserver> is the hostname of the old nameserver and <new-nameserver> is the new namserver hostname you want to replace it with.

You should then restart the DNS service:

service named restart

 

 

 

Explanation Of Cron Times

Find largest folder in ssh

New to setting up cron jobs and need to know what each digit means?

The following is an example of each digit and its function:

*    *    *    *    *        command to be executed
|     |     |    |    |
|     |     |    |    +—– day of week (0 – 6) (Sunday=0)
|     |     |    +——- month (1 – 12)
|     |     +——— day of month (1 – 31)
|     +———– hour (0 – 23)
+————- min (0 – 59)

 

 

Find And Remove Old cPanel Backups

cPanel emtpy trash for all users

How do I find and remove old cPanel backups?

Use the following command from an SSH session to find all backups that are older than 60 days and delete them:

find /backup/weekly/incremental/accounts -maxdepth 1 -type d -ctime +60 -exec rm -rf {} \;

In the above example we find all weekly incremental backups that are older than 60 days and delete them.

You can change the folder location to suit your needs.

Please note: Be very careful to make sure you get the folder path right because it does not prompt you for approval and goes simply by age, so it does not know the difference between a backup folder and an unrelated folder.