You are on page 1of 4

Lab02: Linux Commands

Objectives
1. To learn the basic commands of linux
2. To get the help from the system

Shell commands
Ls
Date
Man
Hostname

ls command :
It is used to list all the contents in the current working directory.
Syntax : $ ls – options <arguments>
If the command does not contain any argument means it is working in the Current directory.
Options :
a– used to list all the files including the hidden files.
c– list all the files columnwise.
d- list all the directories.
m- list the files separated by commas.
p- list files include „/‟ to all the directories.
r- list the files in reverse alphabetical order.
f- list the files based on the list modification date.
x-list in column wise sorted order.
Examples:
$ ls // Show list of all files and directories
$ ls *.txt // list all .txt files
$ ls –R *.jpg // list all jpg files in the current directory and all associated subdirectories
$ ls –Sl // list all files sorted by size
date Command :
This command is used to display the current data and time.
Syntax :
$date
$date +%ch
Options : -
a = Abbrevated weekday.
A = Full weekday.
b = Abbrevated month.
B = Full month.
c = Current day and time.
C = Display the century as a decimal number.
d = Day of the month.
D = Day in „mm/dd/yy‟ format
h = Abbrevated month day.
H = Display the hour.
L = Day of the year.
m = Month of the year.
M = Minute.
P = Display AM or PM
S = Seconds
BU,CS DEPARTMENT LAB-02

T = HH:MM:SS format
u = Week of the year.
y = Display the year in 2 digit.
Y = Display the full year.
Z = Time zone .
Examples:
$ date // Show the system date
$ date -u // utc time
$ date -r file.txt //shows the last modified date

man Command :
This command is used to display text-only manual pages.
Syntax :
$man –<options>

Options : -
a = List all the manual pages.
d = Display debugging info.
h = list all options.
K string = Find and display all pages containing the specified string.
Exapmles
$ man -du // Show disk usage page
$ man –a less // all pages that match the tile less
$ man 1 –l fil1.txt // show pages from section 1

hostname Command :
This command is used to get information about the hostname.
Syntax :
$hostname –<options><host name>

Options : -
a = Displays the hostname alias.
d = Displays the domain of the host.
h = help.
i = Displays the ip address.
Examples :
$ hostname –i
$ hostname -a
BU,CS DEPARTMENT LAB-02

Exercises

Exercises

COMMAND Syntax PURPOSE


Ls Ls show files in current position
Cd cd directory name change directory
Cp cp [option] [source] [destination] copy file or directory
Tty tty Show Number of terminal devices
Rm rm name remove file or directory
Pwd pwd show current position
Mkdir mkdir directory create directory
Rmdir rmdir directory name remove directory
whoami whoami display user name
Less less filename display file contents pagewise
uptime uptime Usage time information
who who Displays list of users currently logged on.
Who –H
uname unme[options] System information
uname –m, uname -a
id id [option][username] Displays user, group and owner id
groups groups [username] Shows all groups
apropos appropos [string] Searches the man pages containg the string
cal cal [option][month][year] Displays calendar
Cal ,Cal –y, cal 06 2005
finger finger show data about the user
shutdown shutdown reboot or turn off machine
BU,CS DEPARTMENT LAB-02

1. Run and execute following linux commands and observe the output.

You might also like