Review of Linux Commands
Goals
By the end of this lab, you should:
- Recall the basic commands to navigate the shell.
- Be able to create directories and files.
- Know about a few useful command line utilities.
Introduction
Graphical interfaces are a relatively new addition to computing.
Before the graphical interface the command shell was how a user
would interface with a computer. As computer technology emerged, the
shell became a very powerful tool. Even though today you
can perform almost any task by using the graphical interface of
Linux, the shell remains on of the most powerful tools that you have
at your disposal.
If you are completely new to the Linux environment, you may want to
take a look at Matt Fast's
emacs/Linux
tutorial. It's a step by step ( screenshots included ) guide to getting
started in Linux.
1. Navigation
The "cd" command allows you to navigate through the
directory structure of Linux. Here are some uses of the cd command
and how the command relates to familiar gui interface icons and buttons.
- cd
-
Action -- change to you home directory.
Gui Equivalent -- The "Home" or "My
Documents" icon.
- cd ..
-
Action -- change up one directory.
Gui Equivalent -- The "Back" button on a file
browser.
- cd <dir_name>
-
Action -- change to the directory named
<filename>.
Gui Equivalent -- Clicking on a folder in a file
browser.
2. Viewing Files
To date myself and quote Ferris Bueller, "Life moves pretty fast.
If you don't stop and look around once in a while, you could miss it."
Here are some commands to help you look around while you're
programming.
- ls
-
See the names of files and folders in the current directory.
- ls -a
-
See the names of files and folders in the current directory, including
hidden files. ( files that start with a '.'
character.
- ls -l
-
See the names of files and folders in the current directory, in a
detailed list view.
- less <file_name>
-
Open the file <file_name>for reading within the shell.
The spacebar scrolls down a page and the 'q' key
quits.
3. Directories
Directories can be both created and deleted. The commands
"mkdir" and "rmdir" can be used as follows:
- mkdir <dir_name>
-
Create a directory in the current directory named
dir_name.
- rmdir <dir_name>
-
Remove the directory in the current directory named
dir_name.
4. Creating and Editing Files
Your likely familiar with either emacs or vi at this point, but here's a
little reminder.
- touch <file_name>
-
If <filename> doesn't exist, create it. Otherwise,
update the timestamp on the file.
- emacs <file_name>
-
Open the file <file_name> for editing with the emacs
editor.
- emacs -nw <file_name>
-
Open the file <file_name> for editing with the emacs
editor within the shell. Make sure you know the emacs shortcut keys
before trying this one.
- vi <file_name>
-
Open the file <file_name> for editing with the vim
editor.
5. Moving, Copying and Deleting Files
The following commands are handy when you need to do a little housekeeping
in your home directory:
- mv <src> <dst>
-
Move the file <src> to the location <dst>.
This is also how you rename files and folders.
- cp <src> <dst>
-
Move the file <src> to the location <dst>.
You need to specify an option to the command in order to copy folders.
Do you know what it is?
- rm <file_name>
-
Delete the file <file_name>.
6. Advanced Commands
There are litterally hundreds of Linux commands that you can type at the
command shell. The following commands are a few that tend to come in
handy. I'll leave it as an exercise for the reader to find out what they
do.
- tar xzvf
- tar czvf
- pwd
- cat
- grep
- echo
- source
- kill
- chmod
- alias
7. Getting More Information
Your TA is not the only, nor the best source for information on the
many command line utilities. Here are a few places that you can go
searching for more information.
- google
-
Google for it. If it's not on google, it doesn't exist.
- info <command_name>
-
The info command will give you information about a particular
<command_name>.
- man <command_name>
-
The man command will also give you information about how to use a
specific command and tends to be a bit more complete than info. The
man pages also have information about some standard functions.
- man -k <partial_command>
-
If you're unsure about the name of a particular command or
funcion you might try throwing man the "-k" option with the
part of the command that you remember or a particular hunch you have
about what the command or function would be called.