Sunday, March 28, 2010

List of Commands I use frequently in Linux/Unix

Being a developer, I hardly ever use Unix/Linux. However,every now and then I need to do work on Linux. Instead of keep searching internet or bug my friendly colleagues, I think it is a better idea to list out Linux commands below. So here goes (I will keep updating as I come across more)...


  • remove directory /files.
    • rm -fr *.*
    • f flag will force remove (and not interactively ask whether you need to remove or not)
    • r flag will allows for recursively deleting all files and directories
    • note: if there is a need to ask before deleting any file, then use i flag
  • How to find ip address in Linux?
    • ifconfig will print the ip address
    • note: if the above command returns "not found", then, use /sbin/ifconfig
  • How to find Disk Usage: Link to baobob: Linux Disk usage analysis and cleanup tools
  • How to find out where "java" or any other file installed (its complete path)?
    • the command whereis java will list the complete path
  • How to execute .bash_profile after changes?
    • . ./.bash_profile (there should be a space between the first dot and the second one)
  • create alias for commands
    • alias cls=`clear tput`
  • How to count number of files in a directory?
    • file . -type f wc -l
  • How to display present working directory in the prompt?
    • In bash shell, set PS1=`\w` (I also add a colon ":" and a greater than symbol ">" at the end like this: PS1=`\w :>` for further references goto everything.com
  • Vi Commands
    • How to display filename while working inside vi?
      Type Ctrl+G
    • How to display line numbers?
      Press ':' and type set number
    • How to display mode we are working on (APPEND or OPEN...)?
      Press ':' and type set showmode

No comments: