UnixCmds


UNIX COMMANDS

 

UNIX commands: 

  1. To create a directory.
    1. Syntax :  mkdir <directory name>
    2. Example :  mkdir oslab
  2. To rename a directory.
    1. Syntax :  mv <directory 1> <directory 2>
    2. Example :  mv CIVIL IT
  3. To change the directory.
    1. Syntax :  cd <directory name>
    2. Example :  cd IT1
  4. To copy the directory and its file to another directory.
    1. Syntax :  cp –r <source directory> <destination directory>
    2. Example :  cp –r IT1/ IT2
  5. To remove an empty directory.
    1. Syntax :  rmdir <empty directory name>
    2. Example :  rmdir IT1
  6. To remove an non–empty directory.
    1. Syntax :  rmdir –r <directory name>
    2. Example :  rmdir –r IT2
  7. To print present working directory. / To display complete path of the working directory.
    1. Syntax :  pwd
  8. To create a file.
    1. Syntax :  vi <file name>
    2. Example :  vi aa.txt
  9. To rename a file.
    1. Syntax :  mv <old file name> <new file name>
    2. Example :  mv aa.txt a1.txt
  10. To view a file.
    1. Syntax :  cat <file name>
    2. Example :  cat a1.txt
  11. To copy files.
    1. Syntax :  cp <source filename> <destination filename>
    2. Example :  cp a1.txt a2.txt
  12. To move files.
    1. Syntax :  mv <filename 1> <filename 2>
    2. Example :  mv a1.txt a2.txt
  13. To concatenate two files.
    1. Syntax :  cat <file 1> <file 2>  > <new file 3>
    2. Example :  cat a1.txt a2.txt > a3.txt
  14. To display the file contents.
    1. Syntax :  cat <file name>
    2. Example :  cat a3.txt
  15. To display the file contents with line number.
    1. Syntax :  cat –n <file name>
    2. Example :  cat –n a3.txt
  16. To create a file using cat command
    1. Syntax : cat > <filename>

<Type the information and press <ctrl+d> to terminate>

  1. Example :  cat > a4.txt
  1. To append the contents of one file to another.
    1. Syntax :  cat <file 1> >> <file 2>
    2. Example :  cat a1.txt >> a2.txt
  2. To append more than one file.
    1. Syntax :  cat <file 1> <file 2> <file 3>…>> <destination file>
    2. Example :  cat a1.txt a2.txt a3.txt >> aa.txt
  3. To link files. <Creates a link between two files. changes in file will reflect in the other file also>
    1. Syntax :  ln <file 1> <file 2>
    2. Example : ln a1.txt a2.txt
  4. To link 5 files.
    1. Syntax :  ln <source directory> <destination directory>
    2. Example : ln /home/anu/IT/* /home/anu/IT/
  5. To sort files in alphabetical order / Display the file contents in descending / ascending order.
    1. Syntax :  sort <file>   // ascending order
    2. Example :  sort a1.txt
    3. Syntax : sort –r <file>   // descending order
    4. Example :  sort –r a1.txt
  6. To list the contents of a directory.
    1. Syntax :  ls
  7. To list all directories of a user.
    1. Syntax :  ls –l | egrep ‘^d’
  8. To list only files from a directory.
    1. Syntax :  ls –l | egrep –v ‘^d’
  9. To list hidden directories.
    1. Syntax :  ls -a
  10. To display all files, subdirectories and files in the subdirectories including their sizes.
    1. Syntax :  ls -lR
  11. To list only the subdirectories available in the present working directory.
    1. Syntax :  ls –lR | egrep –v ‘^d’
  12. To list all directories / files that start with a specific character.
    1. Syntax :  ls <character>*
    2. Example : la a*
  13. To list all files in current directory whose 2ndcharacter is a digit.
    1. Syntax :  ls ?[0–9]*
  14. To list files and directories recursively on a single line.
    1. Syntax :  ls –LR
  15. To list all files which has dot at the end
    1. Syntax :  ls *.
  16. To list all filenames which has a specific extension
    1. Syntax :  ls *.<extension>
    2. Example : ls *.txt
  17. To list the file attributes and file size.
    1. Syntax :  ls -l
  18. To change the file to read only mode. / to change the permission of a file
    1. Syntax :  chmod u-wx <file>

chmod g-wx <file>

chmod o-wx <file>

  1. Example :  chmod u-wx a1.txt

chmod g-wx a1.txt 

chmod o-wx a1.txt

  1. To view one page of a file.
    1. Syntax :  ls –l | more
  2. To view the files page by page.
    1. Syntax :  ls –l | more

<press space bar to view next page> 

  1. To view first 10 lines of a file / to display the beginning of a file
    1. Syntax :  head <file>
    2. Example :  head a1.txt
  2. To view last 10 lines of a file / to display the end of a  file
    1. Syntax :  tail <file>
    2. Example :  tail a1.txt
  3. To display only the first two characters of all lines from a file.
    1. Syntax :  cut –c1–2 <file name>
    2. Example :  cut –c1–2 aa.txt
  4. To combine two files.
    1. Syntax :  cat <file 1> <file 2> > <new file 3>
    2. Example :  cat a1.txt a2.txt > a3.txt
  5. To combine two files without duplicates.
    1. Syntax :  cat <file 1> <file 2> | sort –u > <new file 3>
    2. Example :  cat a1.txt a2.txt | sort –u > a3.txt
  6. To add “;” to the end of the file.
    1. Syntax :  <cat <file>; echo “;”> > <new file>
    2. Example :  <cat a1.txt; echo “;”> > a5.txt
  7. To delete the 7th line of a file.
    1. Syntax :  sed ‘<line number>d’ <file>
    2. Example :  sed ‘7d’ a1.txt
  8. To split a file into smaller number of files with 3 lines in each file.
    1. Syntax :  split –l <number of lines> <file>
    2. Example :  split –l 3 aa.txt
  9. To convert lowercase to uppercase.
    1. Syntax :  cat <file> | awk ‘{print toupper<$0>}’
    2. Example :  cat aa.txt | awk ‘{print toupper<$0>}’
  10. To convert uppercase to lowercase.
    1. Syntax :  cat <file> | awk ‘{print toupper<$0>}’
    2. Example :  cat aa.txt | awk ‘{print tolower<$0>}’
  11. To combine two strings.
    1. Syntax :  echo <string1><string2>
    2. Example :  echo “IRTT” “CIVIL”
  12. To count the number of words in a file.
    1. Syntax :  wc –w <file>
    2. Example :  wc –w aa.txt
  13. To count the number of lines in a file.
    1. Syntax :  wc –l <file>
    2. Example :  wc –l aa.txt
  14. To count the number of characters in a file.
    1. Syntax :  wc –m <file>
    2. Example : wc –m aa.txt
  15. To search for a specific word in a file.
    1. Syntax :  grep <word> <file>
    2. Example :  grep civil aa.txt
  16. To count the number of occurrence of a character in a file.
    1. Syntax :  grep –c <word> <file>
    2. Example :  grep –c civil aa.txt
  17. To search for a specific file in a directory.
    1. Syntax :  find <present working directory> –type f –name <file>
    2. Example :  find /home/anu –type f –name aa.txt
  18. To translate the character “I” in a file to “E”.
    1. Syntax :  cat <file> | tr <original character> <replace character>
    2. Example :  cat aa.txt | tr I E
  19. To change the password.
    1. Syntax : passwd
  20. To view the commands which was executed
    1. Syntax :  history
  21. Show manual for a command
    1. Syntax :  man <command>
    2. Example :  man cat
  22. To clear the screen.
    1. Syntax :  clear
  23. To print todays date and calendar of the current month using a single command.
    1. Syntax :  cal
  24. To print the calendar for year 2013
    1. Syntax :  cal <year>
    2. Example :  cal 2013
  25. To print the calendar for 2012 for the month of March.
    1. Syntax :  cal <month> <year>
    2. Example :  cal 3 2012
  26. To print date and time.
    1. Syntax :  date
  27. Display user name.
    1. Syntax :  whoami
  28. To find out who is logged in. / To print who is using the system presently.
    1. Syntax :  who
  29. Display users full detail, user-id and group-id.
    1. Syntax :  id

 

 

Converted to HTML with WordToHTML.net | Document Converter for Windows

No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu