I BASIC UNIX COMMANDS
UNIX COMMANDS
General Purpose commands:
1. cal
The cal command is used to display the specified month or year calendar.
Syntax:
$cal month or year
Example:
$cal 2010
It displays the calender for the entire year.
2. Date
The date command is used to display the current date, day of the week, month,
day, time and year.
Syntax:
$date
Output:
Mon Mar 30 3:45:30 2010
3. Echo
The Echo command is used to print the message on the screen.
Syntax:
$echo message
Example:
$echo Computer practice lab-II
Output:
Computer practice lab-II
4. who command
This is used to display the data about all the users currently logged into the system.
Syntax:
$who
Output:
User1 tty1 Mar 30 09:30
User2 tty2 Mar 30 09:40
5. who am i
It displays the login details pertaining to the user.
Syntax:
$who am I
Output:
User1 tty1 Mar 30 09:30
6. id command
It is used to display the numerical value corresponds to the login name, user-id and group-id.
Syntax:
$id
Output:
Uid=514(user1) gid=538(group)
7. tty
The tty command is used to know the terminal name that we are using.
Syntax:
$tty
Output:
dev/tty1
8. clear command
It is used to clear the screen and will place the $ prompt at the top left corner on the screen.
Syntax:
$clear
Directory Commands
1. mkdir – Make directory
It is used to make a new directory.
Syntax:
$mkdir dir_name
Example:
$mkdir turbo
2. chdir (or) cd command
It is used to move from one directory to another. Before using cd command, the directory has to be created using mkdir.
Syntax:
$cd dir_name
Example:
$cd turbo
3. pwd – present working directory
It is used to know the current working directory.
Syntax:
$pwd
Output:
user/turbo
4. rmdir – remove directory
It is used to remove a directory.
Syntax:
$rmdir dir_name
Example:
$rmdir turbo
File commands:
1. Creating a file:
Cat command is used to create a file.
Syntax:
$cat>filename
Example
$cat>sample
Press enter and type the information. After finished typing, press “ctrl+z” to save the Information and terminate.
2. Displaying the content of the file:
Cat command is used to display the content of the file.
Syntax:
$cat filename
Example:
$cat sample
3. Copying a file:
Cp command is used to copy the contents of one file to another.
Syntax:
$cp oldfile newfile
Example:
$cp sample sample1
The contents of sample are copied into sample1.
4. Removing a file:
rm command is used to remove an existing file.
Syntax:
$rm filename
Example:
$rm sample1
5. Moving a file:
mv command is used to move the contents of one file to another.
Syntax:
$mv oldfile newfile
Example:
$mv sample sample1
The contents of sample will be moved to sample1. File sample will be removed.
6. Listing files and directories:
ls command is used to view the contents of a directory.
Syntax:
$ls
7. Counting number of words in a file:
wc command is used to display number of lines, words and characters in a file.
Syntax:
$wc filename
Example:
$wc sample
Output:
5 10 45
Sample file contains 5 lines, 10 words and 45 characters.
8. Head command
It display first 10 lines of a file.
Syntax:
$head filename
Example:
$head sample
9. Tail command
It display 10 lines from the end of the file.
Syntax:
$tail filename
Example:
$tail sample
10. Grep command
It is used to print specified pattern from the file. Grep stands Global regular expression. The entire file is scanned for the required pattern.
$grep pattern filename
11. Uniq command
It removes duplicate records from the file.
Syntax:
$Uniq filename
12. nl command
nl command adds line number to a file.