The Command-line
Getting started
Using ssh
See OS-specific guides in the syllabus.
Logging in to eustis
ssh NID@eustis.eecs.ucf.eduThen enter your password
You can create an ssh key and add it to eustis’s .ssh/authorized_keys to login without a password.
# if you haven't already generated a key, run ssh-keygen
ssh-keygen
# accept the default location (as long as you haven't already generated
# now let's tell eustis about your public key (be sure to use .pub!)
# linux/mac
cat ~/.ssh/id_rsa.pub | ssh NID@eustis.cecs.ucf.edu 'cat >> .ssh/authorized_keys'
# windows (https://superuser.com/questions/1747549/alternative-to-ssh-copy-id-on-windows)
type %USERPROFILE%\.ssh\id_rsa.pub | ssh NID@eustis.cecs.ucf.edu "cat >> .ssh/authorized_keys"
# windows alternative (rsa_id.pub instad of id_rsa.pub)
type %USERPROFILE%\.ssh\rsa_id.pub | ssh NID@eustis.cecs.ucf.edu "cat >> .ssh/authorized_keys"The command prompt
You should see a command prompt, something like this:
NID@net1547:~$With a blinking cursor after the prompt (depending on your terminal program)
This is the bash shell program running and waiting for you to type commands.
Typing commands
Use the keyboard to type out the names of programs and other commands, e.g.,
NID@net1547:~$ lsNotice that the prompt now has ls at the end.
Then hit the Enter key. The shell will run the named
program (if it exists).
bash will only run programs found in directories listed
in the $PATH environment variable or when given a path to the
program.
This is why you need to type ./ before C programs after
you compile them, e.g., ./a.out, because you are giving a
path to a program to bash.
Getting help for commands
Use the man program to get help for shell commands.
NID@net1547:~$ man lsCtrl-L to clear your screen
To quickly clear your screen, and put the prompt at the top of the screen, use Ctrl-L (or type the clear command). You can also use Ctrl-Alt-L to remove previous screen output as well.
Comments in bash
ls # Runs ls, everything after # is ignored.You can use Alt-Shift-3 (i.e., Alt-#) to insert a comment at the start of the current line, and then enter it.
File system hierarchy
Conventions
- The root directory is called
/(forward slash) - We also separate nested directories with
/ - All directories contain a
.(dot) directory that points to itself - All directories contain a
..(double dot) directory that points to its parent - The home directory is aliased to
~(tilde)
Example file system hierarchy
(Diagram)
- /home/net/bro095187 (alias to tilde
~) - ~/cop3402fal2026
Let’s look at an example hierarchy and see how bash commands move us around the file system.
bash (and every process) are associated with a /current working
directory/, which affects how we reference the locations of files; any
/relative/ paths will start from the current working directory. Relative
paths are any paths not starting with the root of the file system
/.
Paths
A string that contains the sequence of directory names along the file tree to the directory that contains the file and the file name itself. Allows you to uniquely identify files, even those with the same name.
- Absolute paths
Absolute paths start with a /, i.e., the root of the
file system.
- Example:
/usr/include/is an absolute path that refers to the directory/usr/include/.
- Relative paths
Relative paths do not start with a /.
Instead, they are relative to the current working
directory.
- Example: If the current working directory is
/usr, then the directorybin/(notice the lack of a leading slash) refers to the directory with the absolute path/usr/bin.
Consider these commands
./hello
cd ..Where are the “.” and “..” in our file tree?
In order to answer this, we need to introduce a new concept, the working directory.
The current working directory
- Example: If the current working directory is
/home/bpappas/, then the relative path./Documents/refers to the directory with absolute path/home/bpappas/Documents/. - Example: If the current working directory is
/home/bpappas/, then the absolute path/usr/include/refers to the directory with absolute path/usr/include(the current working directory is ignored for absolute paths).
Parent directory
- Example: If the current working directory is
/home/bpappas/Documents/, then the relative path../Desktop/refers to the directory with absolute path/home/bpappas/Desktop/. - Example: If the current working directory is
/home/bpappas/Documents/, then the absolute path/etc/refers to the directory with absolute path/etc/(the current working directory is ignored for absolute paths).
Navigating the File System
Running commands
Type its name and hit Enter
Where am I?
Print Working Directory: pwd
What’s here?
LiSt the directory: ls
Running commands with arguments
Type its name, a space, then the argument.
Arguments are separate by spaces.
What if the argument has a space in it? - escape the space with a
backslash \ - Use double-quotes (evaluates the contents,
e.g., for bash variables and escape sequences) - Use single-quotes (does
not evaluate contents or escape sequences)
Go to a new directory
Change (working) directory: cd path
cd /usr/includeWhat kind of path is this, relative or absolute?
Use eustis’s /usr/include as an example file
hierarchy
These are where system-wide C header files are installed
Go the parent directory
cd ..What is the .. directory? Show this in the diagram.
Where are we now? How do we find out?
Get used to running pwd and ls to orient
yourself
Go to a subdirectory
cd includeWhat kind of path is this, relative or absolute?
What if we had done cd ./include instead? What’s the
difference? Why do we have the . folder?
Programs versus shell builtins
We’ve used cd a few times now.
But what happens if we try to use man to learn more
about cd?
man cd
No manual entry for cdWhat’s going on?
Programs versus shell builtins
cd is actually what’s known as a a shell builtin.
It is implemented as a part of Bash (the shell we have been using).
Getting help for shell builtins
To get help for shell builtins, instead of man, use
help
help cdChecking a command’s type
To check if a command is a program, shell builtin, or some other kind
of command, use type.
type cdUse the -a flag to print all types.
type -a echoThe first one shown is what Bash defaults to using.
Can override default to use the program version (if one is present)
by prefixing the command with the command builtin.
Can override default to use the builtin version (if one is present)
by prefixing the command with the builtin builtin.
Making the command-line fast
At this point, you are typing a lot, and retyping some of the same paths over and over again.
Tab-completion
Autocomplete for the command-line
One of these most useful features for speed on the command-line
Works for files and directories, command-line arguments, and commands themselves.
You can even create completions for your own software.
Impatience
Don’t spend time typing when you can use tab completion
Laziness
Don’t try to remember yourself file names, let the shell do it
Example
Be sure we are in /usr/include
Type the following, but don’t hit Enter:
ls gnumHit Tab
The shell completes the file name for you!:
ls gnumake.hMultiple completions
Type the following, but don’t hit Enter:
ls gnuHit Tab. Nothing seems to happen!
Hit Tab again to see all completions.
/usr/include$ ls gnu
gnu/ gnumake.h gnu-versions.h
/usr/include$ ls gnuAdd the hyphen and hit Tab to complete.
ls gnu-Completion happens only when there is a unique option. But hitting
Tab again will show all possibilities with the prefix
written so far. Continue typing until you have a unique prefix, then hit
Tab again to complete the unique possibility.
Make it a habit to hit tab
Confirming existence of a file
Avoiding long typing
Narrowing down results
Press Tab twice
Editing commands
| Keyboard | Description | Mnemonic |
|---|---|---|
Home or Ctrl-a |
Beginning of command (home) | a is beginning of the alphabet |
End or Ctrl-e |
End of command | e for end |
Backspace |
Delete a character behind you | It’s the Backspace key |
Alt-Backspace |
Delete a whole word behind you | Alt for alternative version |
Alt-b |
Go back a word | b for back, Alt for alternate |
Alt-f |
Go forward a word | f forward, Alt for alternate |
https://www.gnu.html/software/bash/manual/bash.html#Commands-For-Moving
Bash has Emacs-like commands.
Additional commands
| Keyboard | Description | Mnemonic |
|---|---|---|
Ctrl-d |
Delete character in front | d for delete |
Ctrl-b |
Move back | b for back |
Ctrl-f |
Go forward | f for forward |
Alt-d |
Delete a word in front | d for delete, alt for alternative version |
Kill (cut) and yank (paste)
| Keyboard | Description | Mnemonic |
|---|---|---|
Ctrl-u |
Kill (cut) until the start | u for kill |
Ctrl-k |
Kill (cut) until the end | k for kill |
Alt-Backspace |
Kill (cut) a word to back | Alt for alternative version |
Alt-d |
Kill (cut) a word in front | d for delete, Alt for alternative |
Ctrl-y |
Yank (paste) | y for yank |
Rerunning commands
- History saves all commands your run
historywill print them all- Last command added to bottom of the list
Navigating the command history
| Keyboard | Mnemonic | Description |
|---|---|---|
Ctrl-p or Up |
p for previous |
Previous command |
Ctrl-n or Down |
n for next |
Next command |
Searching for a previous command
Ctrl-r(rfor reverse lookup)- CAREFUL: hitting
Enterwill immediately run- Use
ctrl-aorctrl-eto start editing the command
- Use
Ctrl-gto cancel search
“Save” commands by commenting them out
Ctrl-a, #,
Enter
Adds “saved” command to last one in history
Viewing files
| Command | Mnemonic | Description |
|---|---|---|
cat |
Concatenate | Write file(s) to terminal (stdout) |
more |
Ask user to show more | Write file out, pausing after each screenful |
less |
“Less is more” | Interactive terminal file viewer, q to quit |
cat command
cat /usr/include/stdio.hless command
less /usr/include/stdio.hq to quit
Navigating less
qto quit (tryEscthenqif not working, you might have hit other keys)Pg-up,Pg-down,Up,Down,Left,RightCtrl-v,Alt-v,j,k,h,l/type pattern, then enternfor nextNfor previous
- Type a number then
Gto go to line Ctrl-gto show current command-line
The less command has vim-like commands.
Editing files with
vim or emacs
Everyone should have completed the Emacs or vim tutorial as part of the reading for lecture 1.
Quick review
Keeping your editor running
Use
Ctrl-zto “pause” your editor, returning to the command prompt.Then use
fgto resume it.
Warning: avoid opening multiple instances of the editor on the same file, or you may accidentally overwrite unsaved changes.
Note: eustis is configured to prohibit background processes from running after quitting and will kill them.
Downloading and untarring files
| Command | Description |
|---|---|
wget 'URL' |
Download a file |
tar -xvf file.tar |
Unpack a tarball (expand; verbose,
filename) |
cd ~/
wget 'https://www.cs.ucf.edu/~pappas/teaching/cop3402/fal2026/files/hw2.tar'
tar -xvf hw2.tar
cd hw2You’ll need this for hw2 and later for projects.
Editing the file tree
| Command | Description |
|---|---|
touch |
Create a file |
rm |
Remove a file |
mv |
Move a file |
cp |
Copy a file |
mkdir |
Make a directory |
rmdir |
Remove (an empty) Directory |
Removing non-empty directories?
- Remove contents of the directory first, then use rmdir
- What’s an algorithm to remove a whole directory tree?
You can ask rm to remove non-empty directories and their
contents recursively, but it’s a bit dangerous.
Review
Orienting yourself
pwd # Print the working directory
ls # List current directory contentsMoving around
cd /usr/include # Change working directory
cd ../ # Move to /usr
cd ~ # Go to home directory
cd - # Go to last directory
cd # Also to go to home directoryTab completion
- Hit tab to auto-complete file and directory names
- Hit tab again to show all files with a matching prefix
- Use tab to quickly find paths
History
- Hit
Up(orCtrl-p) to repeat the prior command - Go
UpandDown(orCtrl-n) to step through the command history - Hit
Enteron a command to rerun it - Use
!<prefix>to re-run the most-recent command beginning with<prefix> - Use
fcto open the last entered command in your default text editor- You can set your default editor by assigning its name to the
variable EDITOR, e.g.,
EDITOR=vim.
- You can set your default editor by assigning its name to the
variable EDITOR, e.g.,
Modifying the file tree
touch filename # to create an empty regular file
rm filename # to remove a (non-directory) file
mv filename newname # to rename a file
mkdir subdir # to make a new directory
mv filename subdir/ # to move a file
cp subdir/filename copiedname # to copy a file
rm subdir/filename # to remove a file
rmdir subdir # to remove an empty directory