Practical No. 1: Username@machinename, Followed by The Current Workingdirectory (More About That in A Little
Practical No. 1: Username@machinename, Followed by The Current Workingdirectory (More About That in A Little
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>
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
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
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
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: