Wednesday, February 10, 2010

The 15 Most Basic UNIX commands


  1. man - show manual and uses of command, uses man [command]   hit q to exit the man page. example:- man useradd 
  2. pwd - to show present working directory.
  3. useradd - to add a user, uses useradd [option] [uesrname] to assign different home directory other then /home use -d option, to add the user to a group use -g option, use -s to assign shell.  example:-useradd -d /opt/tset(home dir location) -g game(group name)  -s /bin/bash(shell name)  test(username)
  4. passwd - to set  or change password of user, uses passwd  [username]. example passwd test to set password for test user. 
  5. mkdir - to create directory, uses mkdir  [directory name]. example mkdir test  to create the test directory, mkdir  /opt/james/old/test to create the test directory inside /opt/james/old. 
  6. cd - change directory,  uses cd [location to change]example:- cd /temp
  7. ls - listing  directory, uses ls [option]  [location] . example:-  ls /etc, use ls  -l  /etc to see more detail, ls -a /etc  to see hidden file.
  8. cp - copy a file or directory,  uses cp [source]  [dest] example:-  cp /opt/a.txt  /etc/  to copy a.txt file for /opt to /etc,  if you want to copy a directory use the -R option for recursive:  cp -R /opt/Test /etc/os/  copy the Test folder from /opt to /etc. 
  9. mv - move or rename a file or directory, uses mv [source]  [dest]. example mv /usr/local/a.sh      /etc/  to move the file a.sh from /usr/local to /etc,  mv test.txt  a.txt  to rename  test.txt file to a.txt.
  10. rm - remove a file or directory,  uses rm  [file or directory name]. example: rm a.txt  to remove a.txt file  to remove a directory you may need the -R option, you can also use the -f (forcefully) option which don't ask conformation  for  each file:-  rm -Rf /dir  but don't use -f option every time.
  11. cat - to read the content inside a file, uses cat  [file name or location]. example cat a.txt  to read the a.txt file content, cat /opt/test/test.txt  to read  test.txt from /opt/test location.  
  12. tar - tape archiver, tar takes a bunch of files, and munges them into one .tar file, uses tar [option]      file.tar  [location of file or folder].  example:- tar test.tar /opt/test to tar the test folder for untar use untar file.tar  
  13. find - lists files and directories recursively with matching string, uses find [location] -name [string]. example find /opt/ -name test to list all file and directory matching string test inside /opt
  14. tail - prints the last few lines of a file, this is handy for checking log files, uses tail [option]  [file name or location]. example tail -5 ab.txt to print last five line of ab.txt file, tail -f /var/log/mail to see last 10 line of mail log file. 
  15. vi - text editor, there are several text editors such as emacs, and nano, but vi is usually installed on any server so its a good one to learn. To edit a file type vi file to edit a line press Esc i then to save changes and exit use Esc wq, or to quit without saving use Esc q!. There are a million other commands, but that will enable you to edit files at a basic level.
Once you learn these commands, and are comfortable with them, you should work all basic work on all Linux & Unix like Os .

2 comments:

amaya mishra said...

Great Tutorial...subscribed =)

a$hi$h said...

good though i understood nothing _Babloo

Post a Comment