Sections:: Command Command Command,, and and Commands Editor
Sections:: Command Command Command,, and and Commands Editor
Directories:
Moving around the file system:
Listing directory contents:
Changing file permissions and attributes
Moving, renaming, and copying files:
Viewing and editing files:
Shells
Environment variables
Interactive History
Filename Completion
Bash is the way cool shell.
Redirection:
Pipes:
Command Substitution
Searching for strings in files: The grep
command
vi editor
Directories:
File and directory paths in UNIX use the forward slash "/"
to separate directory names in a path.
examples:
"root" directory
/usr
/usr/STRIM100
pwd
cd
cd /usr/STRIM100
cd INIT
the current
directory.
cd ..
Change current directory to the parent directory of the
current directory.
cd $STRMWORK
environment
variable 'STRMWORK'.
cd ~bob
Change the current directory to the user bob's home
directory (if you have permission).
ls
list a directory
ls -l
for example:
$ ls -l
drwxr-xr-x
4 cliff
user
-rw-r--r--
1 cliff
user
^ ^
| |
| |
| owner
group
size
date
time
| |
| |
| |
767392 Jun
6 14:28 scanlib.tar.gz
name
ls -a
start
with "."
ls -ld *
using
List all the file and directory names in the current directory
long format. Without the "d" option, ls would list the contents
of any sub-directory of the current. With the "d" option, ls
just lists them like regular files.
101 binary)
You must be the owner of the file/directory or be root before you can do any
of these things.
cp file1 file2
copy a file
mv file1 newname
mv file1 ~/AAA/
directory.
rm -r dir1 [dir2...]
CAREFUL!
create directories
mkdir -p dirpath
create the directory dirpath, including all implied
directories in the path.
rmdir dir1 [dir2...]
cat filename
more filename
down
q=quit
less filename
Like more, but you can use Page-Up too. Not on all systems.
vi filename
vi in some form.
Edit a file using the vi editor. All UNIX systems will have
emacs filename
have emacs.
Edit a file using the emacs editor. Not all systems will
head filename
head -n
tail filename
tail -n filename
Shells
The behavior of the command line interface will differ slightly depending on
the shell program that is being used.Depending on the shell used, some extra
behaviors can be quite nifty.You can find out what shell you are using by the
command:
echo $SHELL
Of course you can create a file with a list of shell commands and execute it
like
a program to perform a task. This is called a shell script. This is in fact
the
primary purpose of most shells, not the interactive command line behavior.
Environment variables
You can teach your shell to remember things for later using environment
variables.
For example under the bash shell:
export CASROOT=/usr/local/CAS3.0
with the value
/usr/local/CAS3.0.
export LD_LIBRARY_PATH=$CASROOT/Linux/lib
LD_LIBRARY_PATH with
cd $CASROOT
CASROOT
echo $CASROOT
printenv CASROOT
Interactive History
A feature of bash and tcsh (and sometimes others) you can use
the up-arrow keys to access your previous commands, edit
them, and re-execute them.
Filename Completion
A feature of bash and tcsh (and possibly others) you can use the
TAB key to complete a partially typed filename. For example if you
have a file called constantine-monks-and-willy-wonka.txt in your
directory and want to edit it you can type 'vi const', hit the TAB key,
and the shell will fill in the rest of the name for you (provided the
completion is unique).
Bash will even complete the name of commands and environment variables.
And if there are multiple completions, if you hit TAB twice bash will show
you all the completions. Bash is the default user shell for most Linux
systems.
Redirection:
The redirection directives, > and >> can be used on the output of most
commands
to direct their output to a file.
Pipes:
The pipe symbol "|" is used to direct the output of one command to the input
of another.
For example:
ls -l | more
list command
filter).
a time.
"ls -l" and pipes it through the more command (also known as a
Command Substitution
You can use the output of one command as an input to another command in
another way
called command substitution. Command substitution is invoked when by enclosing
the
substituted command in backwards single quotes. For example:
which will cat ( dump to the screen ) all the files named aaa.txt that exist
in the current
directory or in any subdirectory tree.
command
which
Reading and writing tapes, backups, and archives: The tar command
The tar command stands for "tape archive". It is the "standard" way to read
and write archives (collections of files and whole directory trees).
Often you will find archives of stuff with names like stuff.tar, or
stuff.tar.gz. This
is stuff in a tar archive, and stuff in a tar archive which has been
compressed using the
gzip compression program respectivly.
Chances are that if someone gives you a tape written on a UNIX system, it will
be in tar format,
and you will use tar (and your tape drive) to read it.
Likewise, if you want to write a tape to give to someone else, you should
probably use
tar as well.
Tar examples:
tar xv
verbose)
Extracts (x) files from the default tape drive while listing (v =
Lists the files from the default tape device without extracting
directory
The standard UNIX compression commands are compress and uncompress. Compressed
files have
a suffix .Z added to their name. For example:
compress part.igs
uncompress part.igs
part.igs.Z.
Another common compression utility is gzip (and gunzip). These are the GNU
compress and
uncompress utilities.
compress,
gzip part.igs
gunzip part.igs
The bzip2 utility has (in general) even better compression than gzip, but at
the cost of longer
times to compress and uncompress the files. It is not as common a utility as
gzip, but is
becoming more generally available.
bzip2 part.igs
Most of the commands have a manual page which give sometimes useful, often
more or less
detailed, sometimes cryptic and unfathomable discriptions of their usage. Some
say they
are called man pages because they are only for real men.
Example:
man ls
Example:
apropos build
the word "build"
Basics of the
vi editor
Opening a file
vi filename
Creating text
Edit modes: These keys enter editing modes and type in the text
of your document.
Replace 1 character
Replace mode
Deletion of text
dd
ndd
J
Attaches the next line to the end of the current line (deletes carriage
return).
Oops
nyy
cursor positioning
^d
Page down
^u
Page up
:n
:$
^g
h,j,k,l Left,Down,Up, and Right respectivly. Your arrow keys should also work
if
if your keyboard mappings are anywhere near sane.
string substitution
:n1,n2:s/string1/string2/[g]
global),
all instances of string1 on each line
are substituted. If g is not included,
only the first instance per matching line
is
substituted.
These and other "special characters" (like the forward slash) can be "escaped"
with \
i.e to match the string "/usr/STRIM100/SOFT" say "\/usr\/STRIM100\/SOFT"
Examples:
:1,$:s/dog/cat/g
file)
:23,25:/frog/bird/
These commands are all prefixed by pressing colon (:) and then entered in the
lower
left corner of the window. They are called "ex" commands because they are
commands
of the ex text editor - the precursor line editor to the screen editor
vi.
You cannot enter an "ex" command when you are in an edit mode (typing
text onto the screen)
Press <ESC> to exit from an editing mode.
:w
:w new.file
:w! existing.file Overwrite an existing file with the file currently being
edited.
:wq
:q
Quit.
:q!
:e filename
:set number
:set nonumber