Commands Exercises
Commands Exercises
Linux Commands
--------------
# Notes
* Commands preceded with "$" imply that you should execute the
command as
a general user - not as root.
* Commands preceded with "#" imply that you should be working as
root with
"sudo"
* Commands with more specific command lines (e.g. "RTR-GW>" or
"mysql>")
imply that you are executing commands on remote equipment, or
within
another program.
username: sysadm
password: <given in class>
$ sudo -s
Now that you are root the command prompt will change. We indicate
this using the “#”
symbol.
# exit
$
$ cat /etc/network/interfaces
4. List files:
$ ls -lah
$ cat .profile
$ less .profile
$ clear
If you don't understand what cat, clear or less do, then type:
$ man cat
$ man clear
$ man less
You can recall previous commands by using the up-arrow and down-
arrow keys. Give this a try now.
$ history
If you wish to execute one of the commands in the list you saw type:
$ !nn
Where “nn” is the number of the command in the history list. This is
useful if you want to run a past command that was long and/or
complicated.
Command completion:
With the bash shell you can auto-complete commands using the tab
key. This means, if you type part of a command, once you have a
unique string if you press the TAB key the command will complete. If
you press the TAB key twice you'll see all your available options.
Your instructor will demonstrate this, but give it a try by doing:
$ hist<TAB>
$ del<TAB><TAB>
$ rm <TAB><TAB> [Include the space after the “rm”]
$ cd
$ ls /sbin | sort > sbin.txt
$ less sbin.txt
sysadm:x:1000:1000:System Administrator,,,:/home/sysadm:/bin/bash
userid:passwd:uid:gid:Name,extrastuff,,:HomeDir:LoginShell
grep is often used with a pipe to FILTER the output of commands. For
instance:
$ history | grep ls
<CTRL>-R, type “ntpdate”, then press left arrow. Edit the previous
command (which you should now have) and change “/usr/lib/” to “/usr/
sbin/”. Use the left+right arrow key to move, and backspace to
erase. You should now have:
With your cursor just past the “/” in “/sbin/”, press <ENTER> to
execute the command.