Help File Library: Basic Console Commands
Frederik Holljen
frederik.holljen@hig.no
v1.01 3 May 1999 (13.00)
Table of Contents
About this Document
Navigate Through the File System
Manipulating Files
Utilities
System Commands
Internet Utilities
Basic Command Separation
This document is meant as a guide to essential command
line programs for Linux users and as a reference guide
for other Help Files. The first time I installed Linux and I
no clue on what input to give my pc. Step by step I
found some useful commands. I remember thinking "Someone
should have a document with some basic commands listed that
I could use as a start to learn Linux". I have now
used Linux since December 98 and I haven't seen such a document
on the net, so I made on myself, and here it is.
This document is in NOT a complete reference on the commands
in it, and there are allot of other useful utilities in
Linux. If you want any additional information about a command
use the man utility. If you find
any errors in this document or you think that I should add a command, let me know. This document is
here for you!!
Have a lot of fun with Linux!!
Frederik Holljen
Thanx to all the guys who have given me support with this document, you
know who you are!
Format
cd [directory]
Summary
When you call cd and give it a directory it will make the
specified directory the working directory. If you don't
specify a target your home directory will become the working
directory.
MS USERS: When you want to descend a directory you have
to write cd .. with a space between the "d" and
the first dot.
Format
pwd
Summary
This command prints out the current working directory. This
means the full path of the directory that you are currently
in.
Format
ls [options] [file-list]
Summary
Lists information about one or more files. Lists alphabetically
unless you specify something else.
[file-list] could be any directory path or files
you specify. ls lists the working directory if you don't
give it this argument.
You can use wildcards * and ?.
Options
-a All files, includes invisible files (those
that start with a period)
-l Long, displays extra information about
the files.
-F Appends a "/" at the end
of a directory listing and a "*"
at the end of an executable listing. Makes the output
of ls much more readable. Combine with --color.
--color Color, this command adds colors
to the output of ls. A very useful option, make an alias
for it!!
Format
cp [options] source-file destination-file
cp [options] source-file-list destination-directory
Summary
The program has two modes. You can copy one file into another.
Or copy a file from one place to another.
You can use wildcards * and ?.
Options
-r Copies directories recursively. With
this i mean that all files including subdirectories and
their content given by source-file-list will be copied to
the destination directory.
Format
df [options] [filesystem-list]
Summary
If you don't specify the filesystem-list, df will list the
amount of available disk space on all mounted filesystems
Options
-t type, causes df to display information about the type
of the filesystems of the specifies type.
Format
du [directory-list]
Summary
Lists the diskspace used by the directory and its contents
specified by the directory-list argument
Format
find directory expression
Summary
directory specifies the directory where you want the search
to start. Find will search all directories recursively.
expression is the search argument. These are the most common
used:
Search arguments
-name filename, searches for the
given filename
-user name, list all files who are
owned by the given users
-size +/-n, lists all files with
size smaller/greater than n
Format
ln [option] existing-file new-link
Summary
Creates a hard link to the file specified by existing-file
with the name given by the new-link argument. A hard link
to a file is indistinguishable from the original. A hard
link has to be on the same filesystem as the original file.
A symbolic link may be across filesystems and existing file
and new-link may be directories as well as files.
Options
-s creates a symbolic link instead
Format
locate pattern
Summary
Lists all files in filedatabase that match the given pattern.
This utility depends on a database file with al list of
all files on your filesystem. Use the updatedb utility to
update your database (caution, this takes a while)
Example
#locate hepp
This search would find all files on you system that contain
hepp. It would find heppgr, tghepp and tyheppl.
Format
mkdir [options] directory-list
Summary
Creates a new directory. If you write #mkdir test, mkdir
creates a new directory with the name "test" in
the current directory.
If you want mkdir to make a directory in another directory,
you must specify the whole directory path.
Options
-p parent, if the parent directory of the directory you
are creating does not exist, mkdir will create it for you.
Format
mv [options] source-path destination-path
Summary
Copies the the files specified in source-path to destination
path and then deletes the original files.
You can use wildcards * and ?.
Format
rm [options] file-list
Summary
This utility removes files from your system. You can use
wildcards * and ?.
Note: when you delete a file it is not possible to recover
it.
Options
-r recursive, this option makes
rm remove the specified directory and all of its contents.
(MS USERS: Just like deltree) BE CAREFUL WITH THIS COMMAND!!
-f force, this option makes rm delete
files without asking you if you really want to. Nice if
you want to delete directories.
Format
rmdir directory-list
Summary
Removes all directories specified by directory-list.
Note: The directories you want to delete must be empty.
If they are not, mkdir will fail. If you want to delete
a directory together with its contents use rm.
Format
cat [options] [file-list]
Summary
cat lists all the files specified by file-list to your screen
end to end.
Options
-n number, causes cat to display line numbers at the beginning
of each line.
Format
echo [option] message
Summary
Very useful in scripting, lets you write messages to the
terminal and can be used to display shell variables
Options
-n newline, prevents echo from displaying the newline at
the end of the message
Example
#echo 'Hi!'
Hi!
#echo -n 'Hi!'
Hi!#
#echo $TERM <-- this is a shell variable
vt100
#
Format
grep [options] pattern [file-list]
Summary
This utility searches one or more files for a pattern. The
grep utility performs actions, specified by options every
time
it finds a line that contains a match for the pattern.
If you use tabs or spaces
in the pattern you must quote it.
Options
if you don't specify any options grep displays the line
that contained a match for pattern.
-c count, causes grep to display the number
of times it found a match for pattern
-i ignore case, ignores case when
finding a match for pattern
-l file list, causes grep to display
only the filename in which it found a match for pattern
-v reverse test, causes lines not containing
a match to satisfy the search
Format
head [-number] [file-list]
Summary
The head utility displays ,without arguments, the ten first
lines of the files given by file-list. If you want
to display more or less than 10 lines specify this with
the -number option.
If you don't specify any file-list head will read
from it's standard input. This means that you can pipe
to it.
Summary
Similar to more but you can scroll backwards in the document
too!
Format
man [options] page
Summary
Man is the built in manual pager in Linux. It offers allot
of flexibility, and I must admit that I don't know the man
utillity as good as I should. The parameter page tells man
what you want help for. Normally it is a command but you
can also specify a utility, function or some config file
you need help with. Use the interactive commands to navigate
inside the document.
Options
There are ALLOT... use "man man" to find the apropriate
one..
Interactive commands
/"argument" Higlights all words
that contain "argument".
q quit, quits man.
Format
more [options] [file-list]
Summary
Allows you to view a text file at the terminal. Almost the
same as cat, but it pauses each time it fills the screen.
On pause, you can press ENTER to make more display one more
line. If you press space more fills another screen. More
will display all the files given in the file-list argument.
If you don't give it the file-list argument, more will read
from it's standard input.
Options
-n number of lines, specifies the
number of lines in a screenfull.
-d display, makes more display a explanatory
message after each screenful
+n line number, makes more start at line
number n.
Interactive commands
More has a lot of interesting commands that can be used
whenever more pauses here is a list of the most commonly
used
d shows half a screenful
q exits from more
v starts up the vi editor with the current document at the
current line (very useful)
tail - display
the last part (tail) of a file
Format
tail [options] [file]
Summary
This utility displays the last part of the file specified
by file. If you don't specify a file it read's
from it's standard input, this means that you can pipe to it.
Options
-n lines, the number of lines from the
en of the file you want tail to display.
Format
tar key[options] [file-list]
Summary
The tar utlility can extract, add to, list, and
create tar volumes. It can also extract tar.gz/tgz archives.You
can only have one key mode, but you can have multiple options.
The tar utility has tons of options check them out in the
manual (man tar)
Key
t table of contents, displays
all the files in the archive.
A append, adds the files specified by
file-list the archive.
c create, creates a new archive
x extract, extracts files from the archives
given by file-list
Options
v verbose, causes tar to display
each line as it reads/writes them.
-V name Create a volume with volumename
NAME. Use this together with the key A
z filter the archive through gzip. Use
this when you have a tgz/tar.gz file.
-f file input file, Unpack from archive "file"
instead of the standard input which is /dev/rtm0 (tape streamer)
Format
finger [options] [user-list]
Summary
With no arguments finger gives you a list of all users logged
on to the system together with their full names, terminal
device numbers the number of times they logged in and other
information. If specify a user on the command line, finger
gives you detailed information on that user and displays
his/her .plan, .project and .forward file. The really cool
thing with finger is that you can finger users on other
hosts.
User list options
[user] gives you information on that user on your local
system
[user]@[host] gives you information on that particular user
on that particular host
@[host] lists all the users currently logged on on that
host
Options
-l long, gives you detailed information
on about every user currently logged on
Format
kill [option] PID-list
Summary
Terminates all jobs with PID number=PID-list
You can determine what signal to send to terminate the process.
These are the possibilities
Options
-0 sh(1) only, signals all members of process group
-9 non-catchable, non-ignorable kill (this is the one to
use if you process if doesn't want to get killed)
-15 software termination signal (default)
-HUP A very useful option. This causes
kill to terminate the process and to restart it afterwards.
Format
ps [options]
Summary
Lists active processes. If you run ps without any options,
it displays all processes that you control. If you run ps
without any options you will see five columns
PID process ID, The process ID of the process on that line
TTY terminal, the terminal that controls the process
TIME The number of minutes and seconds the process has been
running
COMMAND The command name with which the process was started.
If you use the w option you will see the entire command
line.
a all, lists all processes controlled
by any terminal
e environment, Prints the environment
of the process
l long, a complete status
report (13 columns)
u user, causes ps to display a userorientated
status information. Extra columns (CPU and MEM usage)
Format
talk [user] [tty]
Summary
Allows you to real-time chat with any user given by [user].
If you want to talk with someone on the local system [user]
is just the username of that person. If you want to talk
to a user on a different host [user] is [user@host]. If
a user is logged in more than once, you may want to specify
the appropriate terminal. Do this with using the [tty] option.
It's on the form 'ttyXX'. To find out what tty's the user
you want to chat with uses, use the finger command.
When someone sends you a chat request you must reply with
"talk [user]@[host] or just [user] if the person is
on the same system. Use ^c to quit from the chat.
Format
top [-] [options]
Summary
Gives you a list of existing processes and their activity
in real time. Defaults to sort processes by CPU activity,
but can also sort by MEM usage. It has both command line
parameters and interactive commands.
Options
d [number] delay, the number of
seconds between each update.
i idle, causes top to ignore idle
or zombie processes.
Interactive commands
SPACE causes top to update the screen immediately.
h help, gives you the help screen
with a list of commands (very useful)
k kill, Terminate a process. You
will be prompted for the PID to kill, and the signal to
send.
q quit
s change the delay between each
update. You will be prompted for the time in seconds.
Format
who [am i]
Summary
Who is a strip down of finger. With no arguments it displays
the users currently logged on, their terminal device number
and the time they logged on to the system.
Given the [am i] option who displays information about the
current user (you).
Format
ftp remote-computer
Summary
ftp is the standard ftp client that comes with Linux. I
recommend installing something better (like ncftp). But
I'll include it here because it's a standard.. It's always
there.. Ftp is interactive once it's connected to a host.
Interactive commands
!
escape to a shell on you local system. Use ^D to return
to ftp.
binary set the file transfer type
to binary (you must do this if the files you want to download
are non ASCII)
cd, change
directory
close, close the connection but
not ftp
dir/ls, list the files in
the current directory
get
remote-file [local-file], download remote-file into local
if specified.
mget remote-file-list,
Allows you to get multiple files (and directories) from
the host. You can use wildcards
put
local-file, puts local-file to the current directory on
the host
mput local-file-list,
Same as mget only the other way.
help, display a list
of available commands
Summary
Use this to write multiple lines command (if your
terminal screen isn't long enough).
Example
#mount /dev/hdc \
/mnt/cdrom
#
Summary
Normally, when you enter a command, the task runs in the
foreground and you don't get the prompt back until
the program is finished. Sometimes you don't want this behavior.
Especially if your task takes a lot of time
and doesn't have any interaction with the user (example:
updatedb). The answer is to run the program in the
background. By placing a "&" last in your
command you achieve this effect.
Example
#sleep 10
<Wait ten seconds>
#
#sleep 10 &
[1] 13533 <-- this is the PID (ProcessID) of the process
you just put in the background.
# Your prompt returns immediately
#sleep 10 & sleep 15 &
[1] 13534 <- starts both commands simultaneously in the
background in order.
[2] 13535 <- this is the sleep 15 commands PID
#
Summary
A really useful separator. It directs the output of one
command to the next. This is very useful when you want one
program to work on the output of another one.
Example
# ps aux | grep ps
larson 1344 0.0 0.4 1188 584 p2 R 15:04 0:00 ps aux
larson 1345 0.0 0.3 1180 464 p2 S 15:04 0:00 grep ps
#
The example first lists all processes on the system and
directs this output to the grep utility which sorts
out and displays all lines with ps in them. PS: you may
not get the same output that I did, because the "grep
ps" command may or may not have been started at the
time you ask for the process list.
Summary
If you want to execute more than one command in a row you
can separate them with a semicolon (;)
Example
#cp /tmp/hello ; cat hello
Copies the file "hello" to the current directory
and then displays it.