Running Commands
Notes:
Entering commands:
Commands must be entered in lowercase. For example:
type: cal and press [return]
This displays a calendar for the current month
Correcting mistakes:
Unix is an old operating system designed to be run on many different types
of terminals, some without backspace or delete keys. When you are logging
in to a remote system, you may find that the backspace key does not correct
your typing mistakes. The following control keys should work on any Unix
system:
-
[Ctrl-h] is the equivalent of the backspace key.
-
[Ctrl-u] erases the entire line.
-
[Ctrl-d] signals end-of-input or end-of-file. Usually when you enter a command,
the operating system will execute the command and then display the command
prompt again. If the command prompt doesn't re-appear, the system may be
waiting for keyboard input; try pressing [ctrl-d] to signal end-of-file.
-
[Ctrl-c] interrupts and cancels the current process. If [ctrl-d] doesn't
bring back the prompt, try [ctrl-c].
Command arguments:
Many commands are used with one or more arguments. For example:
-
cal (no arguments) prints a calendar for the current month.
-
cal 2000 (one argument) prints a calendar for the year 2000.
-
cal 10 2000 (10 and 2000 are both arguments) prints a calendar for
October, 2000.
Command options:
You can also specify options which modify the behaviour of a command. Options
appear immediately after the command, they are usually entered as a - followed
by a single letter. For example:
-
cal -j 2000 (j is an option) produces a julian calendar for the
year 2000.
-
cal -y (y is an option) prints a calendar for the current year.
-
cal -yj (2 options) prints a julian calendar for the current
year.
Getting help:
The traditional unix help system is the man command. To get help
about the cal command, type: man cal.
Once a man page is displayed, the following commands navigate the document:
-
[SpaceBar] - display the next screen
-
[Enter] - advance 1 line
-
b - go backwards
-
/xyz - search for the string xyz
-
q - quit
Note: on floppix, the man command is only simulated, so the help is often
terse and none of the options for the man command are available.
Command history:
The bash shell saves all of the commands you've entered (up to some pre-defined
limit). When you logout, these commands are saved in a file in your own home
directory called .bash_history so that the command history is even
preserved between login sessions. The command history can be used in a number
of ways, but the simplest is to use the up-arrow key to recall previous commands.
Once the command is displayed, you can execute it immediately by pressing
[enter] or modify the command and then press [enter].
Command completion:
If you are entering long commands or filenames, you seldom have to type the
entire string; type enough letters for bash to recognize the text and then
press the [tab] key. Bash will fill in the remaining letters for you. If
there is more than one option, the shell will beep. Pressing the [tab] key
a second time will produce a list of possible matches for the text you have
entered.
Exercises:
-
Load Floppix and login using your initials.
-
Try a few commands:
-
cal (a calendar)
-
date (the date and time)
-
who (a list of everyone who is logged in)
-
cat readme (displays the contents of the readme file)
-
Try entering a command in upper case. For example: CAL
What error message is displayed? _________________________
Why? ___________________________________
-
Try the following experiment in using [Ctrl-d] and [Ctrl-c].
-
What happens if you enter "cat" without specifying a filename?
__________
-
Does [Ctrl-d] take you back to the command prompt? _____
-
Enter the "cat" again.
-
Does [Ctrl-c] take you back to the command prompt? _____
-
Now, enter the command "sleep 60". This command pauses for 60 seconds.
-
Does [Ctrl-d] take you back to the command prompt? _____
-
Does [Ctrl-c] take you back to the command prompt? _____
-
Look at the man page for the who command.
-
what are 3 options for the who command?
-
The who command can accept 2 random arguments. What is output when you enter
the command: who am i __________
-
switch to console 2 and login as alterego.
-
as alterego, what is output when you enter the command: who am i
__________
-
as alterego, what is output when you enter the command: who likes
linux __________
-
logout on console 2 and switch back to console 1
-
what is output when you enter the command: who likes linux
__________
-
Experiment with command history.
-
Press the [up-arrow] key until you recall the command: who likes linux
-
Do NOT retype the command; modify it to be: who likes linux?
Press [Enter] to run the command.
-
Press the [up-arrow] key until you recall the command: who likes
linux? Modify it to be: who -H likes linux?
Press [Enter] to run the command.
-
Press the [up-arrow] key to recall the command: who -H likes linux?
Press [Ctrl-h] What happens? _________________________
-
Press [Ctrl-w] What happens? _________________________
-
Press [Ctrl-u] What happens? _________________________
-
Press [Ctrl-d] What happens? _________________________
-
Try this experiment:
-
Login again.
-
Enter the command: date
-
Logout and login again.
-
View the command history file.
-
Do you start with an empty command history file every time you login or is
the history file preserved between sessions?
-
Try using the command completion feature.
-
Enter the command: ls /h[tab]
-
What directory name starts with h? _______________
-
Enter the command: ls /usr/bin/s[tab][tab]
-
Which filenames in /usr/bin start with s? ____________________
-
Logout on all consoles and shutdown.
Questions & Answers:
-
If you make a mistake while you are entering a line, what combination of
keys can you press to erase the entire line and start over?
Answer: [Ctrl-u]
-
What key(s) do you press to recall the previous command?
Answer: Press the [up-arrow] key
-
Does the key conbination [Ctrl-d] always logout?
Answer: [Ctrl-d] signals end-of-input or end-of-file. If you are sitting
at the bash prompt, then [Ctrl-d] will cause a logout (although bash can
be configured to ignore it). If you are running a command, then the [Ctrl-d]
key conbination is passed to the command not the shell and will not be
interpreted as logout.
-
What command do you use to get help about the cal command?
Answer: man cal
-
Identify the command, options and arguments in the following:
ls -al /etc
Answer:
The command is: ls
There are two options: a and l
The argument is: /etc
-
Can commands be entered in uppercase?
Answer: No, unix is case sensitive and commands are usually
lowercase.
-
What error message do you get when you try to run a command that does not
exist on floppix?
Answer: command not found
-
How would you get help on the -j option of the cal command?
Answer: man cal
The manpage for a command will list all of the options for that command with
a description of the purpose of each option. You can get help for a command,
not an option.
-
The syntax for the cal command is:
cal [-jy] [[month] year]
How do you interpret this?
Answer: entries in [ ] are optional. For this command, there are:
-
two options (-jy) which are optional
-
one or two optional arguments - if only one argument is specified, it is
interpreted as the year; if two arguments are specified, the first one is
the month and the second one is the year.
-
The syntax for the who command is:
who [OPTION]... [ FILE | ARG1 ARG2 ]
How do you interpret this?
Answer:
... indicates that an item can be repeated one or more times;
| should be interpreted as "or"
For this command:
-
you can specify 0 or more options
-
you can optionally specify either a filename or 2 arguments
Copyright © L.
M. MacEwan