Basic Unix & Linux Commands
If you are unfamiliar with UNIX or Linux, an excellent online UNIX tutorial can be found in the "User's Guide to UNIX" from the Department of Electronic Engineering, University of Surrey, United Kingdom . Although that link is to a UNIX tutorial, the commands, at the user level, are essentially identical to those of Linux.
While other text editors exist, vi may be the most powerful text editor under UNIX/Linux. There are two modes in vi: input and control mode. Actually vi has three modes -- editing, command, and last-line mode. We are not going to confuse the readers with information that is hardly ever used. Here we only present them in two main categories to make it clear for the beginner.
When we start vi, we are in control mode. When we add or change text, we need to shift to input mode. Pressing the ESC (Escape) key at any time, we will return to the control mode.
For the next several sections, we will begin with the basic knowledge of vi. Until section 6.5.4 we will only cover the control mode. In section 6.5.4 we discuss how to input and edit text in vi. For more information for vi, the user could reference vi man page or other resource.
To create a new file or edit an existing file, type
"vim" followed by the filename at the shell prompt:
$> vim ''filename''
In the vim control mode, type
- To save current file:
ESC : w
- Or to save the current file and exit from vim.
ESC : wq
Moving the cursor
The arrow keys work in
vi, but not all terminals support them. The movement keys could be used to move the cursor around. The
"h" key and
"l" key move the cursor left and right; the
"k" move down and up.
Here is the illustration of the cursor keys on the keyboard,
x command deletes the current character.
dw command deletes the current word.
dd delete the current line.
The undo command
u restores the text deleted or changed by mistake. The undo command can only restore the most recently deleted or changed text.
In a vi session, user must shift to the Input Mode before entering text. Press the ESC and i to invoke the Input Mode
tar and gzip/bzip2
On both UNIX and Linux, tar may be the most common used archive tool. The synopsis of tar is:
tar [option] [file...]
The most import options in tar are,
–c, –x, –v, –f and
–c option is used to create archive and
-x to extract an archive.
–v will allow tar to print important information during the archive/extract process.
–z is a new feature in tar which means compress/uncompress the archive.
For example, we are planning to archive and compress the text file “water” to water.tar.gz
tar cvf water.tar.gz water
To extract the text file “water” from the compressed (gzip format) archive file
tar xvfz water.tar.gz
To extract the text file "water" from the compressed (bzip format) archive file
tar xvfj water.tar.bz2
There are several compression tools under Unix/Linux, such as compress. While gzip (GNU zip) is a compression utility designed to be a replacement for compress, its main advantage over compress is better compression. It has been adopted by the GNU project and is now relatively popular.
The synopsis for gzip is:
gzip [option] [file …]
The options include,
-l (list compress file content) and
–v (verbose). There is no compress option for gzip. The default option in gzip is compress.
Similar to gzip, bzip2 is a newer algorithm for compressing data. bzip2 is a freely available, high-quality data compressor. It typically compresses files to within 10% to 15% of the best available techniques, while being around twice as fast at compression and six times faster at decompression. Bzip2 is available at:
The synopsis for bzip is:
bzip [option] [file …]
The generally used options are