27 February 2014

Some Essential Linux Command

// // 9 comments

Some Essential Linux CommandMaybe the command line isn't your favorite place to hang out, but to be an effective Linux admin, you need to be able to wield a few essential commands.We understand that many of you don't want to use the command line in Linux (or in any operating system, for that matter). But the truth is, to be a good administrator, you have to know the command line. Why? Well, with Windows there are times when the command line is the only thing that can save your skin. With Linux, the command line is vast, reliable, flexible, fast...we could go on and on.


And of the 2,119 possible commands from the /usr/bin directory (in Mandriva Spring 2008) and the 388 possible commands from /usr/sbin/, a few are indispensable. Here are some of them that might make your Linux admin life -- or your introduction to Linux -- a whole lot simpler.


 Must Read Control Android From PC

We could make this easy and go with the most used commands (cd, ls, rm, etc -- okay, etc isn't a command, but you get the point). But instead,we're going with the most useful commands, and we'll keep it as distribution-neutral as we can.





Commands

  • 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/*

  • 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;



 Must Read : Customize Your Video with Wondershare

These  Linux commands make Linux administration possible. There are other helpful commands, as well as commands that are used a lot more often than these. But the commands outlined here fall into the necessity category. We don't know about you, but we can't go a day without using at least half of them. Do you have a Linux command or two that you can't live without? If so, then share through the below comment sections.
Articles You May Like

9 comments: Leave Your Comments

  1. Your article is very nice. It is a great tutorial for developers and to someone learning and having it's own server...thank you for sharing such post..

    ReplyDelete
  2. Just why do we try to keep on trying so as to re-invent the wheel? Linux had an experimentation, and came to be very popular considering that it was more freely and readily available. It is derived on UNIX... Thus the child of UNIX along with all its utensils. :)

    ReplyDelete
  3. Very informative article. I'm planning to install another OS on my laptop. Dual OS. I've tried Red Hat and Ubuntu before so maybe I'll use Ubuntu again. Thanks for sharing this. :)

    ReplyDelete
  4. This are a lot of commands but it does make life easier once you get the hang of it.

    ReplyDelete
  5. I once tried the Linux platform and realized that it was not very friendly especially in installing new apps because of the command prompt. You're right. Even with helpful tutorials like these I don't think I will be able to do well. :| So I switched back to Windows.

    ReplyDelete
  6. I'm not a Linux user but this looks really helpful especially for those with no programming background. Thank you!

    ReplyDelete
  7. Wow interacting with files has never been easier following your tutorials! Moreover, Linux is the most often ignored third wheel to Windows and Mac. If you use Ubuntu do these Linux commands apply to Ubuntu as well?

    ReplyDelete
  8. im not a linux use and i still didn't try it but thanks for the information :)

    ReplyDelete