Some Unix Commands

  1. The tar command:
    • To tar all the files with extensions cpp and doc into a tar file called abc.tar do the following tar cvzf abc.tar *.cpp *.doc
    • To tar all the files and the subdirectories of a directory called temp into a tar file named abc.tar do the following tar cvzf abc.tar temp If you want to put abc.tar in a different directory, proceed abc.tar by the path of the directory. For example, if you are in directory called parent and you want to tar a directory called child and call the tar file abc.tar and put abc.tar in the subdirectory child, type tar cvzf child/abc.tar child
    • To see the table of contents of the tar file abc.tar do the following: tar tzf abc.tar
    • To untar the file abc.tar, do the following: tar xvzf abc.tar
  2. To change the password on Unix, type: passwd
  3. To check your quota on Unix, type: quota -v
  4. To print using Unix, type: lpr -Pprintername filename
  5. To change the ownership of a file/directory called abc to NewOwner, do the following: chown NewOwner abc
  6. To change your "plan" file, type: pico .plan
  7. To change your "finger" information, type chfn
  8. To create a directory called abc: mkdir abc
  9. To remove an empty directory called abc: rmdir abc
  10. To remove a directory called abc and all of its contents: rm -rf abc
  11. Permissions for the web directory and all of its subdirectories: 711
  12. Permissions for files on the website: 744
  13. To find out which groups you belong to, type: groups
  14. To find out which groups a user called abc belongs to, type: groups abc
  15. To find out who are the members of a group called abc, type getent group abc
  16. To append the contents of file2 to file1, type cat file2 >> file1
  17. To list all files including hidden files whose names begin with a dot in the current directory and its subdirectories, and put the list in a file called t.txt, type: ls -la * >> t.txt
  18. To list all files in the current directory and its subdirectories and sort them by modification date, and put the list in a file called t.txt, type: ls -lt * >> t.txt
  19. To search for a file called abc.txt in the current directory and all of its subdirectories, type find -name 'abc.txt'
  20. To search for a file whose name contains the substring abc in the current directory and all of its subdirectories, type find -name '*abc*'
  21. To search for a file whose size is greater than 300k in in the current directory and all of its subdirectories, type find -name '*' -size +300k
  22. To search for a file called abc.txt in the root and all of its subdirectories, type find / -name 'abc.txt'