0% found this document useful (0 votes)
43 views

Practical No. 1: Username@machinename, Followed by The Current Workingdirectory (More About That in A Little

The document provides an overview of basic Linux commands like date, cal, who and w, explaining how to use each command to display or set the date/time, view calendars, and get information on logged in users and monitor user activity. Examples are given for common arguments and options for each command to display output in different formats or restrict the output.

Uploaded by

kakur
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Practical No. 1: Username@machinename, Followed by The Current Workingdirectory (More About That in A Little

The document provides an overview of basic Linux commands like date, cal, who and w, explaining how to use each command to display or set the date/time, view calendars, and get information on logged in users and monitor user activity. Examples are given for common arguments and options for each command to display output in different formats or restrict the output.

Uploaded by

kakur
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

PRACTICAL NO.

OBJECTIVE: To connect to the Linux Server and understand the basic commands in Linux

Theory: Ubuntu is a complete desktop Linux operating system, freely available with both
community and professional support. The Ubuntu community, backed by Canonical, is built on
the ideas enshrined in the Ubuntu Manifesto: that software should be available free of charge,
that software tools should be usable by people in their local language and despite any disabilities,
and that people should have the freedom to customise and alter their software in whatever way
they see fit. "Ubuntu" is an ancient African word, meaning "humanity to others"
Launch the terminal emulator! Once it comes up, we should see something like this:
[me@linuxbox~]$
This is called a shell prompt and it will appear whenever the shell is ready to acceptinput. While
it may vary in appearance somewhat depending on the distribution, it willusually include your
username@machinename, followed by the current workingdirectory (more about that in a little
bit) and a dollar sign. If the last character of the prompt is a pound sign (“#”) rather than a dollar
sign, the terminal session has superuserprivileges. This means either we are logged in as the root
user or we selected a terminal emulator that provides superuserpriviledges.

The objective of this exercise is to give you experience in using telnet to connect to the Linux
host, login using the user id and password provided, and then to logout.
1. Begin the telnet client by typing telnet 172.16.1.114
2. When prompted provide your user id and password

Basic Commands:
1. Date command is helpful to display date in several formats. It also allows you to set systems
date and time.
This article explains few examples on how to use date command with practical examples.

When you execute date command without any option, it will display the current date and time as
shown below.
The date command displays the current date and time. It can also be used to display a date in a
format you specify. The super-user (root) can use it to set the system clock.
Usage

With no options, the date command displays the current system date and time, including day-of-
week, month, time, timezone, and year. For example:
1. $ date
Wed Aug 18 16:24:44 EDT 2010

To operate on a specific date, you can provide one with the -d flag. For example:

2. $ date -d "1974-01-04"
Fri Jan 4 00:00:00 EST 1974
date has many display formatting options. Provide date with the formatting string by prefixing it
with a plus sign as follows:
3. $ date +"Week number: %V Year: %y"
Week number: 33 Year: 10
The format string is then outputted with each formatting token substituted by its value. %V is the
formatting option to display the current week number, and %y represents the last two digits of
the year.
Display Universal Time using -u option
You can display date in UTC format using -u, or –utc, or –universal option as shown below.
4. $ date
Mon May 20 22:07:53 PDT 2013
5. $ date -u
Tue May 21 05:07:55 UTC 2013
Various Date Command Formats
You can use formatting option to display date command in various formats using the following
syntax:
6. $ date +%<format-option>

Format options Purpose of Option Output


Displays Weekday name in
date +%a Thu
short (like Mon, Tue, Wed)
Displays Weekday name in
date +%A full short (like Monday, Thursday
Tuesday)
Displays Month name in short
date +%b Feb
(like Jan, Feb, Mar )
Displays Month name in full
date +%B February
short (like January, February)
Displays Day of month (e.g.,
date +%d 07
01)
Displays Current Date; shown
date +%D 02/07/13
in MM/DD/YY
Displays Date; shown in
date +%F 2013-02-07
YYYY-MM-DD
Displays hour in (00..23)
date +%H 23
format
date +%I Displays hour (01..12) format 11
Displays day of year
date +%j 038
(001..366)
date +%m Displays month (01..12) 02
date +%M Displays minute (00..59) 44
date +%S Displays second (00..60) 17

7. $ date -d now
Wed Aug 18 16:47:31 EDT 2010
8. $ date -d today
Wed Aug 18 16:47:32 EDT 2010
9. $ date -d yesterday
Tue Aug 17 16:47:33 EDT 2010

10. $ date -d tomorrow


Thu Aug 19 16:46:34 EDT 2010
11. $ date -d sunday
Sun Aug 22 00:00:00 EDT 2010
12. $ date -d last-sunday
Sun Aug 15 00:00:00 EDT 2010
If you have a static date or time value in a string, you can use -d or –date option to convert the
input string into date format as shown below.Please note that this doesn’t use the current date and
time value. Instead is uses the date and time value that you pass as string.The following
examples takes an input date only string, and displays the output in date format. If you don’t
specify time, it uses 00:00:00 for time.
13. $ date --date="12/2/2014"
Tue Dec 2 00:00:00 PST 2014
14. $ date --date="2 Feb 2014"
Sun Feb 2 00:00:00 PST 2014
15. $ date --date="Feb 2 2014"
Sun Feb 2 00:00:00 PST 2014

Set Date and Time using –set option


You can set date and time of your system using –set option as shown below..
Setting the Date
date --set="09/09/2016"

Linux also has cal command to display calendar. As its name, cal just show you the calendar in
many ways.
1. $ cal
Display calender in full year view
To display it in full year view, put the year you want to view after cal command or use -y year
parameter. Let say you want to view 2013 calendar.

2. $ cal 2013
or
3. $ cal -y 2013
Show specific month
To fulfill this, we can use -m month_name parameter. Here’s a sample:
4. $ cal -m Feb
Display 3 monthscalendar
You can display calendar in 3 month format. One for previous, current and next month. Use -3
parameter to do it.
5. $ cal -3
Display the number of month after the current month
If you need to do it, use -A number parameter.
6. $ cal -A 2
Display the number of month before the current month
If you need to do it, use -B number parameter.
7. $ cal -B 2

On Linux system, we can use who command to see who is on the system.
What is who command?
who command is a tool print information about users who are currently logged in. who command
only see a real user who logged in. It won’t see a user that doing su command (switch user).
How to use who command?
On most Linux distribution, who command is already installed. To use it, just type who on your
console. Running it without options will print a default output.
1. $ who

Who default view

Here’s how to read the output :


1st column show the user name
2nd column show how the user connected. Tty means the user is connected directly to the
computer, while pts means the user is connected from remote
3rd and 4th columns show the date and time
5th column show the IP Address where the users are connected
Count how many user that currently logged in
If you have many users logged in at the same time, this -q option will help you to count them.
2. $ who–q
Print only information about current terminal
We can use -m option to do this.
3. $ who–m
Indicate the time and date of the last reboot
To do this, use -b options
4. $ who -b

We can see that system was boot the computer on December 21st , 2013 at 3:52 PM
Indicate the current run-level of the init process
With -r option, who will print a current run-level of the init process.
5. $ who–r
Add idle time and PID information
By default, who will not print Idle Time and PID information. To add those information, use -u
option. Don’t forget to use -H option to make it easier to read.
6. $ who -u -H
The idle time contains the number of hours and minutes since last activity occurred. So 00:13
means that user leni has been idle for 13 minutes. The dot (.) sign tell us that the terminal has
seen activity on the last minute. During that time, we can call it “current”. The PID is a process
ID of the user’s shell.
Show login process
To show it, we can use -l option.
7. $ who -l

The 1st column only show Login name which refer to System. The number 967, 971 etc on the
screenshot above tell us the PID.
Display all the information
Using -a option will showing us all information. Here’s a sample.
8. $ who -a

Conclusion
You will found that who command is similar with w command in some ways. Don’t be confused
about why Linux has some similar command in term its functionality. You can use what you
think the best for you and suit the situation you are facing. Please consult to who manual page by
typing man who from your console to explore it more detail.

As system Administrator, you must manage the users who logged in into your system. Allow
them to do something, and restrict them do the rest. It’s a normal procedure for system
Administrator. But you should not trust them 100% . People changed. Sometimes leak comes
from inside, not from outside.
To prevent that thing, you need a tool to monitor the user activity. Linux has w command for that
job.
What is W?
Run w
You can just type w on you console to run w command. Take a look below :
1. $ w

Here’s how to read that information:


1. User: the user who is logged in
2. Tty: how they are logged in
3. From: from where they are coming from
4. Login@: when they are logged in
5. Idle: how long they are idle
6. JCPU: Total CPU time used by the user since login
7. PCPU: CPU time of the currently running process
8. What: process that they are currently doing

Use the short format


-s parameter let you more focus only to User, Tty, From, Idle and What fields. Here’s a sample
output:
2. $ w -s

Print specific user


When you investigate your w activity, you may want to focus only to specific user. To do this,
put the username after w command.
3. $ w username

Don’t print the header


You may only want to focus on the w output. If yes, you can remove the header information. Use
-h parameter to do it
4. $ w -h
Generally, on your console you will find a username is printed on the command prompt. But in
some shell such as csh, by default you will not see your username there. So this command
particularly is used with the shell which don’t print the username on their shell.
How do I run whoami?
To run this command, just type whoami. For this sample we are using chs shell.
1. $whoami
Whoami options
This command only have two options. --help and --version.
2. $ whoami --help

This options will output the same information with man whoami
3. $ whoami --version

While --version will show you the version of whoami in your system

Whoami command is also used when you are doing su activity (switch user). This command can
confirm you that you are logged in using a correct user. Whoami is different with who command.
Who command display all logged in user while whoami not. When you are switching user,
whoami will reports the current user which the owner of the session, while who command will
report you the original user before you are switching user.

LAB ASSIGNMENT:

1. Explain Linux kernel in detail


2. Explain different approaches to kernel construction.

You might also like