Essential Linux Commands
0 Comments 1,178 viewsHere are some of most essential Linux commands which I often use and might be a one page reference for you as well.
Search/Find
find . -exec grep “searchterm” ‘{}’ \; -print
Above command will find a searchterm in all files in the present directory and will print it on screen.
If you want to search for a term in specific folders then use following command.
find /home/*/public_html/ -exec grep “searchterm” ‘{}’ \; –print
Above command comes very handy when you want to search for any term in all of your websites hosted on a single host. It also helps you to find any malware of hack scripts.
You can capture the result in a file using this command instead of displaying on the screen
find /home/*/public_html/ -exec grep “searchterm” ‘{}’ \; –print > result.txt
Find .htaccess files in /home
find /home/*/ -type f -name .htaccess
Searches for .htaccess files in /home/user top level folders and doesn’t search in the subfolders.
find /home -maxdepth 2 -type f -name .htaccess
find /home/*/public_html/wp-content/ -maxdepth 1 -type f -name .htaccess
IP Address related/Netowrking
/etc/ips – Contains the IP address and Netmasks.
If you want to change any entries in this file then you will have to run following commands
service ipaliases restart
/etc/init.d/ipaliases reload
/scripts/rebuildippool
Disk Space
df -k
This shows the disk space in kilo blocks. The following command shows the disk paces used and available.
df -hP
df -h |grep “[0-9]G” this is very handy command, it lists all the files in which has G size.
du -h |grep “[0-9]G” this is very handy command, it lists all the files in which has G size.
du -h |grep “^[0-9,]\+G” shows the file sizes in G
du -sh /home/* - this will show the sizes for the folders in /home folder.
cd /
du -sch *
This shows the directory sizes in M/G
du -h shows files in K/M/G sizes.
If / is full then remove the unused log files from /var/log/*
Hard Drive
S.M.A.R.T tool
S.M.A.R.T tool is a an excellent tool to obtain hard drive details and also to check hard drive’s overall health. If you have installed and configured this utility then it will also send you the alert if hard drive fails.
smartctl -H /dev/sda
Checks the overall health of hard drive. It will also report any hard disk failure.
smartctl -i /dev/sda
With this command you can obtain all the information on a hard drive.
Short test for hard drive
smartctl –test=short /dev/sda
Long test for hard drive
smartctl –test=long /dev/sda
Full test for hard drive
smartctl -a /dev/sda
FTP
To restart pure-FTP
service pure-ftpd start
Check FTP service status
service pure-ftpd status
Apache
Restart Apache in centOS
/sbin/service httpd restart
Start Apache in centOS
/sbin/service httpd start
Stop Apache in centOS
/sbin/service httpd stop
PHP
How to find the default php.ini file location.
php -r “phpinfo();” | grep Configuration
Configuration File (php.ini) Path => /usr/local/lib
Loaded Configuration File => /usr/local/lib/php.ini
Flush a Slow Query Log in MySQL
cd /var/lib/mysql
mv mysqladmin flush-logs mysqladmin flush-logs.old
mysqladmin flush-logs
Cleaning large eximstats mysql database
If eximstats directory (/var/lib/mysql/eximstats) contains large files and it is eating up space then celan it up by following commands
#mysql
#use eximstats
>delete from sends;
>delete from smtp;
>delete from failures;
>delete from defers;

No comments yet