Important Linux Commands

A list of commonly used linux commands, created for the purpose of my own use but shared for the benefits of others as well.

  • Adding user to to a ‘sudoer’ list
    • sudo visudo
    • Add the following line at the end of the file:
      • username ALL=(ALL) NOPASSWD:ALL
    • Press :wq to write and quit
  • Finding Memory Usage: cat /proc/meminfo
    • free -k (Free memory in KB)
    • free -m (Free Memory in MB)
    • free -g (Free Memory in GB)
  • Finding Disk  Space Usage:
    • df -k (Free disk space in KB)
    • df -m (Free disk space in MB)
  • Find a list of services
    • ls /etc/init.d
  • Start / Stop / Restart service
    • service <servicename> <start|stop|restart>
      • service hudson start
      • service hudson stop
      • service hudson restart
  • Top processes by CPU Usage
    • top
    • top -u <username>
      • top -u hudson (Top processes started by user hudson)
  • Kill a process:
    • kill <process_id> (Graceful killing of a process)
      • kill 12325
    • kill -9 <process_id> (Forceful killing of a process)
      • kill -9 12325
  • Update bash shell
    • yum -y update bash
  • Split a file into multiple
    • split -l 2000 bigFile.txt smallChunkFile (the first parameter is the max number of lines of the resulting chunks)
  • Finding a file e.g. php.ini etc
    • locate php.ini
    • or find -name *db2jcc*.jar
  • List directories only using ls command
    • ls -d */
  • Finding where a command such as java is running from:
    • readlink -f $(which java)
  • History of executed commands
    • history
  • Start Websphere Server from command prompt
    • cd/opt/IBM/WebSphere/AppServer/profiles/someProfile/bin
    • sudo ./startServer server1
  • Create WebSphere Profile from Command Prompt
    • cd /opt/IBM/WebSphere/AppServer/bin
    • sudo ./manageprofiles.sh -create -templatePath “/opt/IBM/WebSphere/AppServer/profileTemplates/default” -profileName someProfile -profilePath “/opt/IBM/WebSphere/AppServer/profiles/someProfile” -isDefault
  • Start /Stop HTTP Server
    • cd /opt/IBM/HTTPServer/bin
    • sudo ./apachectl start|stop

How to Fix a DNS Server Entry on Your Local Mac Machine

I registered a domain a while back and it was pointing to one of my virtual private server’s name servers.

The problem was, when I tried to access the new domain after keeping some sample website out there, I would be able to access it some day, and some other day, the browser would simply say that it cannot find the server. I had contacted my hosting service for support and they said that there was no problem with the website or the domain configuration and that they were able to access the website (while I was not on my machine).

So I somehow figured out it was a problem with my machine – something to do with local DNS. After doing a research, I found a way to fix it. I had to add the IP address of the name server of the domain to my local DNS configuration. These images show you how that was done.

Step 1 – Open System Preferences

Step 2 – Click on “Network” on the System Preferences window

Step 3 – Click “Advanced” button on your Network window.

Step 4 – Click on DNS Tab

Step 5 – Click on the plus (+) sign to add a new DNS entry

Step 6 – Add the IP address of your name server and click OK

Note:
If there are IP address on the list (which most probably will be there – and probably points to one of your ISPs DNS server), make sure to add your DNS entry at the end of the list. The order is important because, to resolve the IP address, the system will go through the first entry, if not found, goes to second entry and so on. If your new domain is not resolved by any other DNS entries, it then will fall to the entry that you just added.