1. Introducing theIntroducing the
Command LineCommand Line
CMSC 121 Introduction to UNIXCMSC 121 Introduction to UNIX
Much of the material in these slides was taken fromMuch of the material in these slides was taken from
Dan Hood’s CMSC 121 Lecture Notes.Dan Hood’s CMSC 121 Lecture Notes.
2. Format of UNIX CommandsFormat of UNIX Commands
UNIX commands can be very simple one word commands, or they can take aUNIX commands can be very simple one word commands, or they can take a
number of additional arguments (parameters) as part of the command. Innumber of additional arguments (parameters) as part of the command. In
general, a UNIX command has the following form:general, a UNIX command has the following form:
command options(s) filename(s)command options(s) filename(s)
TheThe commandcommand is the name of the utility or program that we are going tois the name of the utility or program that we are going to
execute.execute.
TheThe optionsoptions modify the way the command works. It is typical for these optionsmodify the way the command works. It is typical for these options
to have be a hyphen followed by a single character, such asto have be a hyphen followed by a single character, such as -a-a. It is also a. It is also a
common convention under Linux to have options that are in the form of 2common convention under Linux to have options that are in the form of 2
hyphens followed by a word or hyphenated words, such ashyphens followed by a word or hyphenated words, such as --color--color oror
--pretty-print--pretty-print..
TheThe filenamefilename is the last argument for a lot of UNIX commands. It is simply theis the last argument for a lot of UNIX commands. It is simply the
file or files that you want the command to work on. Not all commands workfile or files that you want the command to work on. Not all commands work
on files, such ason files, such as sshssh, which takes the name of a host as its argument., which takes the name of a host as its argument.
3. Common UNIX ConventionsCommon UNIX Conventions
In UNIX, the command is almost alwaysIn UNIX, the command is almost always
entered in allentered in all lowercaselowercase characters.characters.
Typically any options come before filenames.Typically any options come before filenames.
Many times, individual options may need a wordMany times, individual options may need a word
after them to designate some additional meaningafter them to designate some additional meaning
to the command.to the command.
4. Familiar Commands:Familiar Commands:
scp (Secure CoPy)scp (Secure CoPy)
TheThe scpscp command is a way to copy files backcommand is a way to copy files back
and forth between multiple computers.and forth between multiple computers.
Formats for this command:Formats for this command:
scp path/local_name username@hostname:path/remote_namescp path/local_name username@hostname:path/remote_name
scp username@hostname:path/remote_name path/local_namescp username@hostname:path/remote_name path/local_name
Demo with renaming and copying files.Demo with renaming and copying files.
5. Familiar Commands:Familiar Commands:
ssh (Secure SHell)ssh (Secure SHell)
TheThe sshssh command is a way to securely connect to a remote computer.command is a way to securely connect to a remote computer.
Formats for this command:Formats for this command:
ssh hostnamessh hostname
ssh username@hostnamessh username@hostname
ssh hostname -l usernamessh hostname -l username
If you do not specify the username, it will assume that you want to connectIf you do not specify the username, it will assume that you want to connect
with the same username that you have on this local computer.with the same username that you have on this local computer.
Since you have a single username for all computers on the OIT network, youSince you have a single username for all computers on the OIT network, you
don’t need to explicitly enter a username.don’t need to explicitly enter a username.
But you can give a username, and will need to if your local username is differentBut you can give a username, and will need to if your local username is different
that your GL username. This might be the case if you are logging on from homethat your GL username. This might be the case if you are logging on from home
and set up your username to be different from what it is on GL.and set up your username to be different from what it is on GL.
Demo with connecting with different usernames.Demo with connecting with different usernames.
6. Familiar Commands:Familiar Commands:
ssh (Secure SHell)ssh (Secure SHell)
You can save a couple of keystrokes if you are on oneYou can save a couple of keystrokes if you are on one
of the Linux PCs in the labs:of the Linux PCs in the labs:
You really only need to specify enough of a hostname as youYou really only need to specify enough of a hostname as you
may need.may need.
Linux will automatically attempt to fill out the hostname withLinux will automatically attempt to fill out the hostname with
“umbc.edu” for you.“umbc.edu” for you.
So if you want to log onto the lightest loaded linux server onSo if you want to log onto the lightest loaded linux server on
gl, you only need to issue the following command...gl, you only need to issue the following command...
ssh linux.glssh linux.gl
Or, if you don't care the flavor of UNIX, you can simplyOr, if you don't care the flavor of UNIX, you can simply
type...type...
ssh glssh gl
7. Familiar Commands:Familiar Commands:
passwd (change PASSWorD)passwd (change PASSWorD)
TheThe passwdpasswd command changes your UNIXcommand changes your UNIX
password.password.
This command is an example of a “noThis command is an example of a “no
argument” command. Thus, the format of thisargument” command. Thus, the format of this
command is just the command name itself.command is just the command name itself.
passwdpasswd
passwd is an interactive command, as once wepasswd is an interactive command, as once we
have typed it, we need to interact with it.have typed it, we need to interact with it.
8. Familiar Commands:Familiar Commands:
quota (account QUOTA)quota (account QUOTA)
TheThe quotaquota command shows you how muchcommand shows you how much
storage space you have left in your account.storage space you have left in your account.
When we use this command, we have to specifyWhen we use this command, we have to specify
the -v option to get the information forthe -v option to get the information for ourour
account.account.
The format of this command is:The format of this command is:
quota -vquota -v
9. Familiar Commands:Familiar Commands:
oitcleaner (account cleaning tool)oitcleaner (account cleaning tool)
TheThe oitcleaneroitcleaner account cleaning tool wasaccount cleaning tool was
developed by the UMBC OIT department.developed by the UMBC OIT department.
This command is specific to the UMBC GL systems.This command is specific to the UMBC GL systems.
This command takes no options and noThis command takes no options and no
filenames, so its format is:filenames, so its format is:
oitcleaneroitcleaner
10. Man PagesMan Pages
TheThe manman command allows you to access thecommand allows you to access the
MANual pages for a UNIX command.MANual pages for a UNIX command.
To get additional help on any of the commandsTo get additional help on any of the commands
listed below, you can always typelisted below, you can always type manman
name_of_commandname_of_command at the command prompt.at the command prompt.
Examples:Examples:
man sshman ssh
man passwdman passwd
11. CommandsCommands
ls :ls : lists the contents of a directorylists the contents of a directory
l : long directory listingl : long directory listing
a : lists all files, including files which are normally hiddena : lists all files, including files which are normally hidden
F : distinguishes between directories and regular filesF : distinguishes between directories and regular files
h : ? Look it up usingh : ? Look it up using manman
pwdpwd : prints the current working directory: prints the current working directory
cdcd : changes directories: changes directories
The difference between relative and absolute paths.The difference between relative and absolute paths.
Special charactersSpecial characters ..,, ...., and, and ~~..
mkdirmkdir : creates a directory: creates a directory
rmdirrmdir : removes a directory (assuming it is empty): removes a directory (assuming it is empty)
If you get an error that the directory isn’t empty even though it looksIf you get an error that the directory isn’t empty even though it looks
empty, check for hidden files.empty, check for hidden files.
12. CommandsCommands
touchtouch : creates an empty file with the specified name,: creates an empty file with the specified name,
or if the file already exists it modifies the timestamp.or if the file already exists it modifies the timestamp.
rmrm : removes a file.: removes a file.
f : force deletionf : force deletion
r : recursive deletionr : recursive deletion
mvmv - moves a file, or renames a file- moves a file, or renames a file
f : forces overwrite, if the destination file existsf : forces overwrite, if the destination file exists
cpcp - copies a file, leaving the original intact- copies a file, leaving the original intact
f : forces overwrite, if the destination file existsf : forces overwrite, if the destination file exists
r : recursive copying of directoriesr : recursive copying of directories
13. CommandsCommands
catcat : shows the contents of a file, all at once: shows the contents of a file, all at once
moremore : shows the contents of a file, screen by: shows the contents of a file, screen by
screenscreen
lessless : also shows the contents of a file, screen by: also shows the contents of a file, screen by
screenscreen
headhead : used to show so many lines form the top: used to show so many lines form the top
of a fileof a file
tailtail : used to show so many lines form the: used to show so many lines form the
bottom of a filebottom of a file
14. CommandsCommands
lprlpr : prints a file: prints a file
aliasalias :: creates an alias for a command.creates an alias for a command.
Aliases can be placed in yourAliases can be placed in your .cshrc.cshrc login script.login script.
Example: alias rm ‘rm –i’.Example: alias rm ‘rm –i’.
datedate : shows the date and time on the current system: shows the date and time on the current system
whowho : used to print out a list of users on the current: used to print out a list of users on the current
systemsystem
hostnamehostname : prints the hostname of the current: prints the hostname of the current
computercomputer
whoamiwhoami : prints your current username: prints your current username
15. The UNIX Pipe (|)The UNIX Pipe (|)
The pipe (|) creates a channel from one command to another.The pipe (|) creates a channel from one command to another.
Think of the pipe as a way of connecting the output from oneThink of the pipe as a way of connecting the output from one
command to the input of another command.command to the input of another command.
The pipe can be used to link commands together to performThe pipe can be used to link commands together to perform
more complex tasks that would otherwise take multiple stepsmore complex tasks that would otherwise take multiple steps
(and possibly writing information to disk).(and possibly writing information to disk).
Examples:Examples:
Count the number of users logged onto the current system.Count the number of users logged onto the current system.
TheThe whowho command will give us line by line output of all the current users.command will give us line by line output of all the current users.
We could then use theWe could then use the wc -lwc -l to count the number of lines...to count the number of lines...
who | wc –lwho | wc –l
Display long listings in a scrollable page.Display long listings in a scrollable page.
TheThe lpqlpq command will give us a list of the waiting print jobs.command will give us a list of the waiting print jobs.
lpq | lesslpq | less
16.
17. CommandsCommands
psps : lists the processes running on the machine.: lists the processes running on the machine.
ps -ups -u usernameusername lists only your processes.lists only your processes.
ps -aps -a : lists all processes running on the machine.: lists all processes running on the machine.
The PID column of the listing, provides the informationThe PID column of the listing, provides the information
required by the kill command.required by the kill command.
killkill : terminates a process: terminates a process
killkill process_idprocess_id : sends a terminate signal to the process: sends a terminate signal to the process
specified by thespecified by the process_idprocess_id (PID).(PID).
In cases where the terminate signal does not work, theIn cases where the terminate signal does not work, the
command "command "killkill -9-9 process_idprocess_id" sends a kill signal to the process." sends a kill signal to the process.
nicenice : runs a process with a lower priority.: runs a process with a lower priority.