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