List of 70 basic commands of UNIX


Here are very very basic unix commands you must know. These unix commands are related to the file and directory management in unix and some unix commands are general. You will also come to know how communication takes place between unix computers and also various security commands. So have a look on this exciting tutorial. 

A) File Management Unix Commands 

Creating a File

1. $ cat > test

Now hit the ENTER and start writing and then press CTRL + D to end the file.Your file is created whose name is test.

Creating an empty File

2. $ touch file1

It will create an empty file named file1.

Displaying the Contents of the File

3. $ cat test

It will display the contents of the file named test.

Concatenating the two Files

4. $ cat file1 file2

It will concatenate the file1 and file2

Copying a File to another File

5. $ cp file1 file2

It will copy the contents of file1 into a new file named file2

Moving a File to another File

6. $ mv file1 file2

It will move the contents of file1 into a new file named file2. Now file1 does not exists. This command is also indirectly used to rename a file. To move a file on parent directory we can use $ mv file1 ..

Deleting a File

7. $ rm file1

It will delete file1. But always use $ rm -i file1. It will prompt you a message that you are sure to delete this file. If you press ‘y’, then it will delete it otherwise not.

Appending a File to another File

8. $ file1 >> file2

It will append the contents of file1 at the end of the file2.

Displaying the type of a File

9. $ file file1

It will display the type of file1 that is whether it is Binary File, Empty File, English Text or Binary Text. If you write $ file *, then it will display the type of all files in the current directory.

 B) Directory Management Unix Commands 

Displaying the current working directory

10. $ pwd

It will display the current directory in which you are working.

Creating a Directory

11. $ mkdir dir1

It will create a new directory named dir1.

Removing a Directory

12. $ rmdir dir1

It will remove the directory dir1.

Changing a Directory

13. $ cd dir2

It will take you to dir2 directory from your previous directory dir1.

 C) File and Directory Listing Unix Commands 

14. $ ls *: lists all directories and files. 

15. $ ls t*: will display all the files starting with t and also the files of directories whose name starts with t.

16. $ ls [tT]*: will display all the files starting with t or T and also the files of directories whose name starts with t or T.

17. $ ls [m-t]*: will display all the files whose first alphabet of name lies in the range of m and t and also the files of directories whose first alphabet of name lies in m and t.

18. $ ls [!a-b]*: will display all the files whose first alphabet of name don’t lies in the range of a and z and also the files of directories whose first alphabet of name don’t lies in a and z.

19. $ ls -l: long lists all directories and files with some extra information.

20. $ ls -p: lists all directories and files but will attach slash with the name of directories.

21. $ ls -a: lists all files on your directory.

22. $ ls -d: displays data about directories.

23. $ ls -t: lists files in order of their last modification time. 

24. $ ls -lu: lists files in order of their last access time. 

25. $ ls -r: lists all directories and files but will attach slash with the name of directories and * with the name of executable files.

26. $ ls -Cs: lists all the files on your directory with a columnar format along the size of each file.

27. $ ls -lR: lists all the files on your directory in a recursive manner.

28. $ ls -ld t*: lists all directories and files starting the name with t.

 D) Unix Date Commands 

29. $ date: Fri Feb 14 11:00:12 IST 2009

In order to customize date you can use following switches along with date command

+%D = mm/dd/yy
 +%H = hour (0 - 23)
 +%M = minute (0 - 59)
 +%S = second (0 - 59)
 +%T = HH:MM:SS
 +%w = Day of the week, sunday = 0
 +%a = abbreviated week day
 +%h = abbreviated month (jan - dec)
 +%r = time in AM /PM
 +%y = last two digits of a year

 E) Unix General Command 

30. $ logname: displays your user name.

31. $ who: displays information about all users sitting online like their user name, terminal name and date and time

32. $ who -H: displays information about all users sitting online like their user name, terminal name and date and time with proper headings

33. $ who am i: displays information only about you like your user name, terminal name and date and time

34. $ finger: displays information about all users sitting online like their user name, terminal name and date and time and much more.

35. $ tput: clears the screen

36. $ cal: displays the calendar

37. $ bc: calculator

38. $ echo: Learning unix is fun : displays the string “Learning unix is fun”

39. $ banner: Learning unix is fun : displays the string “Learning unix is fun” in a stylish way.

40. $ man pwd: displays the mannual of pwd command.

41. $ uname: displays the system on which you are working.

42. $ uname -a: displays more info about the system on which you are working like name of the operating system, node and the version of the unix.

43. $ uname -X: displays detailed listing of info of unix.

44. $ id: displays id of the user

45. $ tty: displays name of the terminal of the user

46. $ sleep 5: the system will sleep for 5 seconds

47. $ spell file1: will display all the words which are misspelt in the file file1.

48. $ copy dir1 dir2: copies the content of one directory to another directory. This command is usually used to backup the data. 

F) Unix Security Commands 

49. $ passwd: used to change your password

50. $ passwd -s: displays status about password like its length and expiry date.

51. $ passwd -d: used to delete your password

52. $ passwd -x 120 user1: 120 is the minimum number of days up to when the password is valid for user1.

53. # passwd -l bb7: this command is used by super user to lock account of the user bb7.

54. # passwd -u bb7: this command is used by super user to unlock account of the user bb7.

 G) Unix Command Grouping 

Grouping of commands allow us to use more than one command at a time.

55. $ cal ; date: it will show first calendar and then date

56. $ ls file1 && cat t*: if file1 exists then it will show the content of all files whose name begins with t otherwise the whole command will fail.

57. $ ls file1 || cat t*: if file1 exists or not, it will show the content of all files whose name begins with t.

58. $ cat file1 file2 > file3: it wil concatenate the contents of the two files file1 and file2 and store it in file3.

59. $ cat < file1: cat will take the input from file2 and displays it. 

H) Unix Communication Commands 

60. $ mesg y: enables your terminal to receive messages from other terminals.

61. $ mesg n: disables your terminal to receive messages from other terminals.

62. $ who -T: displays all the terminals who have enabled the write permission on their terminal. The + sign in front of the terminal no. will show you have the write permission on that terminal and - shows you have no write permission.

63. $ who -TH: displays all the terminals who have enabled the write permission on their terminal. The + sign in front of the terminal no. will show you have the write permission on that terminal and - shows you have no write permission but in this case heading will appear on the top of each column.

64. $ write bb8: enables you to write on the terminal bb8. write this command and then type your message and then press CTRL + D. Your message will be sent to bb8.

65. # wall: this command is used by superuser to make an announcement to all the users.

66. # news: this command is used by superuser to deliver a news to all the users.

67. # motd: this command is used by superuser to give message of the day to all the users.

68. $ mail bb8: this command is used for sending mail to a user bb8.

69. $ mail: this command will display all the mails you have received.

70. $ reply bb8: this command is used for replying to the sender bb8.