### Basic Commands
cd public_html
ls
cd ..
wget --limit-rate=1m http://www.example.com/example.zip
wget --no-check-certificate https://example.com/download
### Working with Tar Files
Extract Tar File:
tar zxf public_html.tar.gz
Make Tar File:
tar cfvz public_html.tar.gz public_html
Solaris Tar:
tar cvf - directory1 | gzip -c > file.tar.gz
Exclude Folders:
tar cfvz example.com-08-05-2023.tar.gz public_html --exclude="public_html/oldsite" --exclude="public_html/assets/pdf" --exclude="public_html/new_website.zip" --exclude="trunk.zip"
### MySQL Database Commands
Export Database:
mysqldump -u username -p database_name > dumpfile.sql
Import Database:
mysql -u username -p"password" database_name < dumpfile.sql
Advanced Export:
mysqldump --extended-insert -Q -v --opt -h localhost --password="password" --user=username database_name | gzip > database_name.sql.gz
Unzip SQL File:
gunzip testing.sql.gz
Grant Permissions:
grant all on *.* to user@localhost identified by "password";
Set Global Variables:
set global net_buffer_length=1000000;
set global max_allowed_packet=1000000000;
### System Monitoring and Management
top
show processlist;
### Change Ownership
chown -R user:group .
### Move Directory
Rename Directory:
mv directory newdirectory
Move Directory:
mv directory.old /home/user/directory.old
### Change Permissions
chmod -R 777 /home/admin/domains/domain_name/public_html/folder/
find . -type d -exec chmod 0755 {} \;
find . -type f -exec chmod 0644 {} \;
find . -type f -name '*.php' -exec chmod 644 {} \;
### Find and Search
Find Modified Files:
find -mtime -1 -type f -name '*.php' -exec ls -l {} \;
Search Access Log:
cat example.com-ssl_log | grep "POST /"
zcat example.com-ssl_log | grep "POST /"
Search Text Inside Files:
grep -r --include=*.php "search string"
### Copy Files Without Overwrite
cp -vur /source/* /dest
### Magento Log Cleanup
php -f shell/log.php clean
### Environment Variable Change
export ALLOW_PASSWORD_CHANGE=1
### Directory and File Operations
Find Directory Count:
find . -type d -name contact-form-7 | wc -l
ls | wc -l
Sort by Size:
ls -lhS
Sort by Size + Limit:
ls -lhS | head -1
List per Column:
ls -lhS | less
Find Directory:
find / -type d -name "MyDirectory"
Find File:
find / -type f -name "MyFile"
Find Real Path:
realpath sitedir
### User Management
Add FTP User:
adduser mydev
passwd mydev
Modify User:
usermod -g primarygroup mydev
usermod -a -G secondarygroup mydev
usermod -G "" mydev # Delete secondary group
usermod -d /var/www/sitedir/www.example.com mydev
Check User Directory:
eval echo "~sitedir"
Check User Group:
groups username
List Current Users:
cd /home
ls -l
# OR
cat /etc/passwd
Delete User:
userdel username
Restart SSH Service:
service sshd restart
Change Ownership of Directories:
chown -R mydev:mydev /var/www/sitedir/www.example.com
Find Recently Changed Files:
find /var/www/sitedir -mmin -1 -ls
### Log Management
Log Truncate:
truncate -s 0 /var/log/httpd/error_log
### Disk and System Info
Disk Space Check:
df -h
Finding OS:
hostnamectl
CentOS 7 Restart HTTP:
systemctl restart httpd.service
### SSL Certificate Operations
Convert PFX File:
openssl pkcs12 -in ExampleCert2023.pfx -clcerts -nokeys -out www.example.org.crt
openssl pkcs12 -in ExampleCert2023.pfx -nocerts -nodes -out www.example.org.key
openssl pkcs12 -in ExampleCert2023.pfx -out www.example.org.chain.crt -nodes -nokeys -cacerts
### Find Zip Files
find . -name "wp-content*.zip"
### Install Let's Encrypt
/usr/local/cpanel/scripts/install_lets_encrypt_autossl_provider
### Setting Up Cron Jobs
Cron Job Setup Guide: https://zeropointdevelopment.com/set-up-a-cron-job-in-cpanel-wpquickies/