You are on page 1of 8

Ex.No: 1.

BASIC UNIX COMMANDS

AIM: To implementation of basic UNIX commands.

Procedure:

1.

2.

3.

FILE SYSTEM COMMANDS:

1. Syntax:
$ pwd

Description:

pwd – print working directory. It displays the current working directory.

2. Syntax:
$ mkdir dirname

Description:

This command is used to create a new directory.

3. Syntax:
$ rmdir dirname

Description:

This command is used to remove the directory.

4. Syntax:
$ cd

Description:
This command is used to change the current working directory.

5. Syntax:
$ clear

Description:

This command is used to clear the screen.

FILE HANDLING COMMANDS:

1. Syntax:
$ cat > filename

Description:

This command is used to create a file.

2. Syntax:
$ cat filename

Description:

This command is used to view the contents of the file.

3. Syntax:
$ cat >> filename

Description:

This command is used to add the contents to the existing file.

4. Syntax:
$ cp file1 file2

Description:

This command is used to copy the contents of one file to another file.

5. Syntax:
$ rm filename

Description:
This command is used to remove the file.

6. Syntax:
$ mv file1 file2

Description:

This command is used to move the file from one place to another. It removes the
specified file from the original location.

7. Syntax:
$ ls

Description: It is used to list all files and directories in the system.

8. Syntax:
$ wc filename

Description:

This command is used to count the number of words, lines and characters in the file.

9. Syntax:
$ id

Description:

This command is used to prints user and groups (UID and GID) of the current user.

10. Syntax:
$w

Description:

This command is used to check which users are logged in to the system and what
command they are executing at that particular time. It also shows the uptime, number of users
logged in and load average of the system.

GENERAL PURPOSE COMMANDS:

1. Syntax:
$ date
Description:

This command is used to display the current date with day, month & time.

2. Syntax:
$ echo text

Description:

This command is used to print the message on the screen.

3. Syntax:
$ cal month or year

Description:

This command is used to display the specified month or year calendar.

4. Syntax:
$ bc

Description:

It includes the calculator.

5. Syntax:
$ who

Description:

This command is used to display the data about all the users who are currently logged into the
system.

6. Syntax:
$ who am i

Description:

This command identifies the user and lists the user name, terminal line, the date and time of
login.

7. Syntax:
$ tty

Description:

tty - teletype. It is used to know the terminal name that we are using.

8. Syntax:
$ passwd

Description:

This command is used to change the password.

FILTER COMMANDS:

1. Syntax:
$ head filename

Description:

This command is used to display the first 10 lines of a file.

2. Syntax:
$ tail filename

Description:

This command is used to display the last 10 lines of a file from end.

3. Syntax:
$ grep pattern file(s)

Description:

grep – Global Regular Expression and Print. It is used to search and print specified patterns
from a file.

4. Syntax:
$ sort filename

Description:

This command is used to sort the contents of the file.


5. Syntax:
$ df

Description:

This command is used to show disk usage.

6. Syntax:
$ du

Description:

This command is used to show directory space usage

RESULT:

Thus the basic UNIX commands were studied successfully.

i. To study the difference between Bourne Shell and BASH shell. Summarize the ideas of
Device drivers of Unix and Windows.
ii. Create a directory named “Drive1”. In this directory create few numbers of files named
File1, File2, File3, etc., Use a shell command to display all the files you have created
inside this directory.
Solution:
$ ls
file1 file2 file3 file4
iii. A user created a file named “Large” which more numbers of lines. He founds difficult to
access the head and tail of the contents of that particular file. So, help him out to find the
head and tail of the file using any shell commands.
Solution:
$ head gaint
Hari
Hiranyagarbha
Hrishikesh
Jagadguru
Jagadisha
Jagannath
Janardhana
Jayantah
Jyotiraaditya
Kamalnath
Kamalnayan
Kamsantak
Kanjalochana
$ tail gaint
Jagadguru
Jagadisha
Jagannath
Janardhana
Jayantah
Jyotiraaditya
Kamalnath
Kamalnayan
Kamsantak
Kanjalochana
iv. Display the following details of the system uid, gid, groups, number of users,
authenticated users, local accounts using any shell commands.
Solution:
$ who am i
v. Display the list of shell command to display numbers of words, lines, and characters
counts of file content.
Solution:
$ wc -c text
36 text
$ wc -l text
2 text
$ wc -w text
2text
vi. Create a file, then sort it in the ascending order. Now number each line in the ascending
order such way all content of the files should start with a number. Finally, display the file
content.
Solution:
$ sort gaint
Apple
Ball
Cat
Dog
Elephant
vii. Create two directories named “dir1”and “newdir” separately. Change the path of
directory from “dir1” to “newdir”. Concatenate a file called “Wishes”. This file should
display your best friend’s birthday dates.
Solution:
$ pwd
/home/Sumathy
Sumathy@DESKTOP-0T3UVR2 ~
$ mkdir file1
Sumathy@DESKTOP-0T3UVR2 ~
$ mkdir file2
Sumathy@DESKTOP-0T3UVR2 ~
$ mkdir file3
Sumathy@DESKTOP-0T3UVR2 ~
$ mkdir file4
Sumathy@DESKTOP-0T3UVR2 ~
$ ls
file1 file2 file3 file4
viii. An anonymous user who tries to copy the file content from the Unix shell. He tries to
copies directly from the source file content. Is it possible for him to copy the file content
and delete the source file content?
Solution:
$ cat > cool
$ mv best cool
$ cat cool
12453365
abcsdefghijklmnopqrstuvwxz
$ cat best
cat: best: No such file or directory
ix. Concatenate a file named “OS”. Use “grep” command to search and display the specific
text from the “OS” file. Finally, show us the numbers of texts counts.

Solution:
$ wc -c text
36 text
$ wc -l text
2 text
$ wc -w text
2text

You might also like