Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

DEPARTMENT OF CYBER SECURITY 21YD03-OPERATING SYSTEMS

Ex no: 1
BASIC UNIX COMMANDS

Date:

AIM:
To study and implement the basic UNIX commands.

1.DISPLAY COMMANDS
a)date – used to check the date and time Syntax: $ date
Format Purpose Example Result
+ % m To display only month $ date + % m
+ % h To display month name $ date + % h
+ % d To display day of month $ date + % d
+ % y To display last two digits of the year $ date + % y
+ % H To display hours $ date + % H
+ % M To display minutes $ date + % M
+ % S To display seconds $ date + % S
OUTPUT:

b)cal – used to display the calendar


Syntax: $ cal 2 2009
OUTPUT:

c)echo – used to print the message on the screen.

1 717822Y135-MYTHRA E
DEPARTMENT OF CYBER SECURITY 21YD03-OPERATING SYSTEMS

Syntax: $ echo “text”


OUTPUT:

d)ls – used to list the files. Your files are kept in a directory.
Syntax: $ ls
ls – s All files (include files with . prefix) ls – l Long detail (provide file statistics) ls – t Order
by creation time
ls – u Sort by access time (or show when last accessed together with –l) ls – s Order by size
ls – r Reverse order
ls – f Mark directories with / ,executable with * , symbolic links with @ , local sockets with =
, named pipes (FIFOs) with |
ls – s Show file size
ls – h “Human Readable”, show file size in Kilo Bytes & Mega Bytes (h can be used together
with –l or-s)
ls [a-m]* List all the files whose name begin with alphabets From “a” to “m” ls [a]*
List all the files whose name begins with “a” or “A”.
Eg: $ ls > mylist
Output of “ls” command is stored to disk file named “my list”.
OUTPUT:

e)lp – used to take printouts


Syntax: $ lp filename

2 717822Y135-MYTHRA E
DEPARTMENT OF CYBER SECURITY 21YD03-OPERATING SYSTEMS

OUTPUT:

f)man – used to provide manual help on every UNIX commands.


Syntax: $ man unixcommand
$ man cat
OUTPUT:

g)who & who am i – it displays data about all users who have logged in to the system
currently. The next command displays about current user only.
Syntax: $ who
Syntax :$ who am i
OUTPUT:

h)uptime – tells you how long the computer has been running since its last re boot or power-
off.
Syntax: $ uptime
OUTPUT:

i)uname – it displays the system information such as hardware platform, system name and
processor,OS type.

3 717822Y135-MYTHRA E
DEPARTMENT OF CYBER SECURITY 21YD03-OPERATING SYSTEMS

Syntax: $ uname –a
OUTPUT:

j)hostname – displays and set system host name Syntax :$ hostname


OUTPUT:

k)bc – stands for “best calcualtor‟ Syntax:$ bc


OUTPUT:

2.FILE MANIPULATION COMMANDS


a)cat – this create, view and concatenate files.
Creation:
Syntax: $ cat > filename
Viewing:
Syn: $ cat filename
Add text to an existing file:
Syntax: $ cat >> filename
Concatenate:
Syntax: $ cat file1 file2 > file3
$ cat file1 file2 >> file3 (no overwriting of file3)

4 717822Y135-MYTHRA E
DEPARTMENT OF CYBER SECURITY 21YD03-OPERATING SYSTEMS

OUTPUT:

b)grep – used to search a particular word or pattern related to that word from the file. Syntax:
$ grep searchword filename
Eg: $ grep anu student
OUTPUT:

c)rm – deletes a file from the file system


Syntax: $ rm filename
OUTPUT:

d)touch – used to create a blank file.


Syntax: $ touch file names
OUTPUT:

e)cp – copies the files or directories


Syntax: $ cp source file destination file
eg: $ cp student stud

5 717822Y135-MYTHRA E
DEPARTMENT OF CYBER SECURITY 21YD03-OPERATING SYSTEMS

OUTPUT:

f)mv – to rename the file or directory


Syntax: $ mv old file new file
Eg: $ mv –i student student list (-i prompt when overwrite)
OUTPUT:

g)cut – it cuts or pick up a given number of character or fields of the file.


Syntax: $ cut <option> <filename>
Eg: $ cut –c filename
$ cut –c 1 -10 emp
$ cut –f 3,6 emp
$ cut –f 3-6 emp
OUTPUT:

h)head – displays 10 lines from the head (top) of a given file


Syntax: $ head filename
eg: $ head student
To display the top two lines:
$ head -2 student

6 717822Y135-MYTHRA E
DEPARTMENT OF CYBER SECURITY 21YD03-OPERATING SYSTEMS

OUTPUT:

i)tail – displays last 10 lines of the file


Syntax: $ tail filename
eg: $ tail student
To display the bottom two lines;
$ tail -2 student
OUTPUT:

k)wc – it counts the number of lines, words, character in a specified file(s) with the
options as – l, -w, -c
Syntax: $wc –l filename
$wc –w filename
$wc –c filename

7 717822Y135-MYTHRA E
DEPARTMENT OF CYBER SECURITY 21YD03-OPERATING SYSTEMS

OUTPUT:

3.DIRECTORY COMMANDS
a)mkdir – used for creating a directory.
Syntax: $ mkdir <directory name>
OUTPUT:

b)rmdir – it is an utility for deleting empty directories.


Syntax: $ rmdir directory name
OUTPUT:

c)cd – changes the current directory of the shell.


Syn: $ cd ~
(stores the path to your home directory)
$ cd..
(changes to parent directory)
$ cd
OUTPUT:

d)pwd – (PrintWorking Directory) shows the current directory. Syntax: $ pwd


OUTPUT:

4.PROCESS COMMANDS
a)exit – terminates a process
Syntax: $ exit
b)kill – terminates or send a signal to process
Syntax: $ kill

8 717822Y135-MYTHRA E
DEPARTMENT OF CYBER SECURITY 21YD03-OPERATING SYSTEMS

OUTPUT:

c)passwd – create or change a password


Syntax: $ passwd
OUTPUT:

d)telnet – connect to remote machine using the telnet protocol


Syntax: $ telnet
5.GROUPING COMMANDS
OUTPUT:

a)The semicolon (;) - used ot execute more than one command at a time
eg: $ who ; date ; ls
OUTPUT:

b)The && operator – signifies the logical AND operation. It means that only if first command
is successfully executed, then the nest command will be executed.
OUTPUT:

c)The || operator – signifies the logical OR operation. It means the first command will
happen to be unsuccessful, it will continue to execute next command.
Eg: $ ls marks || date
OUTPUT:

9 717822Y135-MYTHRA E
DEPARTMENT OF CYBER SECURITY 21YD03-OPERATING SYSTEMS

RESULT:
Thus the program was executed successfully.

10 717822Y135-MYTHRA E

You might also like