Unit 2 Using the System
Course code LX13
Linux Basics
Objectives
After completing this unit, students should be able to:
Log in and out of the system
State the structure of Linux commands
Execute basic Linux commands
Use Linux commands to communicate with other users
Logging In and Out
To log in
host1 login: tux1
Password: (the password does not appear)
Last Login: Fri Feb 26 17:35:14 on tty1
[tux1@host1 tux1]$
To log out
$ <ctrl-d>
or
$ exit
or
$ logout
Passwords
Creating or Changing
$ passwd
Changing password for tux1
(current) UNIX password:
New UNIX password:
Retype new UNIX password:
$
Command Format
Linux commands have the following format:
$ command option(s) argument(s)
For example:
$ ls
$ ls -l
$ ls /dev
$ ls -l /dev
Command Format Examples
RIGHT WRONG
1. Separation
$ mail -f personal $ mail - f personal
$ who -u $ who-u
2. Order
$ mail -f personal $ mail personal -f
$ who -u $ -u who
3. Multiple options
$ who -m -u $ who -m-u
$ who -mu $ who -m u
The date and cal Commands
Checking the date
$ date
Fri Mar 5 11:15:10 CET 1999
Looking at a month
$ cal 3 1999
March 1999
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Looking at a year
$ cal 1999
Who Is on the System
Finding who is on the system
$ who
root tty1 Mar 5 11:10
peter tty2 Mar 5 11:04
$ finger
Login Name Tty Idle Login Time
peter 2 Mar 5 11:04
root root *1 7 Mar 5 11:10
Finding Information about Users
Finding who you are
$ who am i
host!peter tty2 Mar 5 11:04
or
$ whoami
peter
The finger command
$ finger peter
Login: peter Name:
Directory: /home/peter Shell: /bin/bash
On since Fri Mar 5 11:04 (CET) on tty2
No mail.
No plan.
The clear and echo Commands
The clear command
The clear command clears the terminal screen
$ clear
The echo command
The echo command writes the arguments to the screen
$ echo Hopefully, lunch is at 12:00
Hopefully, lunch is at 12:00
The wc Command
The wc command counts the number of lines, words and
bytes in a named file.
$ wc [-l][-w][-c] filename
-l counts the number of lines
-w counts the number of words
-c counts the number of bytes (characters)
$ wc .bash_profile
15 31 230 .bash_profile
Sending Mail
$ mail allet
Subject: Meeting
There will be a brief announcement meeting today.
<ctrl-d>
Cc: <enter>
$ mail team02@host1
Subject: Don't forget!
Don't forget this Linux course!!!
<ctrl-d>
Cc: <enter>
Receiving Mail
You have mail in /var/spool/mail/allet
$ mail
Mail version 8.1 6/6/93 Type ? for help
"/var/spool/mail/allet": 2 messages 1 new 2 unread
U 1 peter@host Thu Mar 4 16:10 35/1185 "Status"
>N 2 peter@host Fri Mar 5 11:34 13/350 "Meeting"
& 2
Message 2:
From peter Fri Mar 5 11:34:10 199
Date: Fri, 5 Mar 1999 11:34:09 +0100
To: allet@host
Subject: Meeting
There will be a brief announcement meeting today.
& q
Write and Wall
Use write to display a text message on a user's terminal
$ write team02
Message
<ctrl-d>
Use wall to place a message on all logged in user's
displays
$ wall
I'm back
<ctrl-d>
Talk with Another User
If John wants to talk with Fred, John enters:
$ talk fred
If Fred also wants to talk with John, Fred enters:
$ talk john
JOHN FRED
The mesg Command
The mesg command controls whether other users can
send messages to you with the write, wall or talk
command or through output redirection.
$ mesg [y|n]
The root user can override the default permission
settings.
Keyboard Tips
Corrects mistakes
<backspace>
Terminates the current
command and returns to the
<ctrl-c>
shell
End of transmission or
end of line
<ctrl-d>
Temporarily stops output to
the screen
Resumes output
<ctrl-s>
Erase the entire line
<ctrl-q>
<ctrl-u>
Keyboard Tips (2)
Previous
<arrow up>
command
<arrow down>
<arrow left>
<arrow right>
One character
<shift page-up>to the left
<shift page-down>
One character to the right
Look at the output of
previous commands
Go back to your prompt
Command History
Command history can be viewed with history command
To retrieve commands, use !
$ wc .bash_profile Type command
16 33 238 .bash_profile
$ !-1 Redo previous
wc .bash_profile
16 33 238 .bash_profile
$ !!
wc .bash_profile
Redo previous, same as !-1
16 33 238 .bash_profile
$ history 5
998 clear Show history
999 wc .bash_profile
1000 wc .bash_profile
1001 wc .bash_profile
1002 history
$ !999
wc .bash_profile Redo command 999
16 33 238 .bash_profile
$ !wc:s/bash_profile/bashrc/
wc .bashrc
12 30 176 .bashrc Redo last wc command, substitute
"bash_profile" with "bashrc"
Checkpoint
1. What is the correct command syntax in Linux?
a. $ mail newmail -f
b. $ mail f newmail
c. $ newmail -f mail
d. $ mail -f newmail
2. What commands can be used to communicate with other
users?
Checkpoint (2)
3. Which commands would you use to find out when a
particular user logged in?
a. $ who am i
b. $ whoami
c. $ who
d. $ finger
4. What key sequence would you use to recall a command
from history?
Unit Summary
Linux commands can use multiple options and
arguments and must follow proper syntax rules.
There are many simple, yet powerful commands such as:
date
cal
who, who am i, whoami
finger
echo
clear
wc
Communicate with other Linux users using commands
such as mail, write, wall and talk.