Command line Mini Howto for linux. (I am using ubuntu 7.04 and kde 3.5.6) Back to Main Page
This i a very short version, and if you want to know more, go to the
Internet etc.
This howto is without any guarantee, and you may use it on your own responsibility only.
There may be errors, but I do not want to use too much time to write this howto.
My idea is to make documentation, so you can at least start using the system.
I (66 years old) have abstracted what I find most important, from lots and lots of documentation.
To check specific words you may click here to open wikipedia (use search box, left side middle).
It's easiest to print this howto out, to use it, by your side !
Index:
Open a Konsole - the command line
apropos - to find a man page
The Bash shell
Cat: To concatenate (join) files - or view contents of a text file
cd: Change working directory
chmod: To change file permissions
chown: Change file owner and group
cp: Copy a file
df: sizes of your mounted partitions
dmesg: to print out the bootup messages
mogrify: convert image files
locate: to find a certain file
ln: To make links between files
ls: Lists directory contents
mkdir: Make a directory
Back to Index
mount: To mount a filesystem
mv: Rename file
ps: Report a snapshot of the current processes (to see which programs are running)
pwd: Present working directory
rm: Remove files
rmdir: Remove empty directory
split: Splits a file into pieces
sudo: Execute a command as "superuser"
tar: The tar archive command
top: Display Linux tasks (to see which programs are running -and their PID's (Process ID)
whereis: locate the binary (file to start a program)
In order to use the command line open a Konsole.
Choose K-menu - System - Konsole:
Back to Index

There are other Terminal programs to use (Terminal, xterm, yakuake
etc.).
Back to Index
Below is shown how the Konsole looks with the "ls" command
inserted on the command line, and the result of this command is also
shown:

Bash is the default shell program used in most Linux distributions, e.g. Debian and Ubuntu etc.
For each Bash command, and a lot other linux commands, you can also
give the "man" command followed by the very command name, like "man ls"
for the "ls"
command, in order to see the documentation for the "ls" command - all man pages are organized in the same way.
You could take a quick look at: "man bash" and "man man".
Click here to get an alphabetically list of linux commands
I will following give a short explanation of some of the linux commands
I use most:
Back to Index
apropos: Search in the "man" pages "Names" and "Description" sections for a keyword - see "man apropos".
Example: "apropos ls"
bash: Gives an explanation of the Bash shell - see "man bash"
Example: "man bash"
cat: To see content of a text file, or to concatenate (join together) files - see "man cat"
Example 1: "cat file.txt | less" - will show you the contents on the
screen of the text file "file.txt" (one page at a time - shift page
with the "Page Down/Page Up" button).
Example 2: If you have a lot of text files you want joined together to one big text file:
First copy all the files to an empty directory.
Then cd to that directory.
Then run: "cat * > bigfile.txt" - and all the files will be joined together into one file by the name "bigfile.txt".
Sometimes you might download a video file, split up into several files,
called something like file.avi.000, file.avi.001 .... file.avi.98 etc.
from a newsgroup server -
in this case copy all the files into an empty directory and run: "cat *
> file.avi", and you have a complete video file called
"file.avi" ready to play.
Back to Index
cd: Change working directory
Example: cd /home/user4/howto - will bring you to the "/home/user4/howto" directory
pwd: Present working directory - see "man pwd" - will show you where you are:

chmod: To change file permissions - see "man chmod"
Example: "sudo chmod -R 644 /home" - change the permissions of the
"/home" directory and all its subdirectories -and files to "rw-r--r--"
Example 2: "sudo chmod -R 777 /home" - change the permissions of the
"/home" directory and all its subdirectories -and files to "rwxrwxrwx"
The permissions - r=read, w=write, x=execute - the letters
are: "rwx rwx rwx" - the equivalent numbers are:
"421 421 421"
Explanation:
"6" means "4+2+0" equals "rw" - "4" means "4+0+0" equals "r" - "4"
means "4+0+0" equals "r" - result = "644" equals "rw- r-- r--"
"7" means "4+2+1" equals "rwx" - "7" means "4+2+1" equals "rwx" - "7"
means "4+2+1" equals "7" - result = "777" equals "rwx rwx rwx"
chown: Change file owner and group - see "man chown"
example: "sudo chown -R root:root /home" - Changes the ownership to
user="root", group="root" for the "/home" directory with all
subdirectories -and folders.
cp: Copy a file - see "man cp"
Example: "cp file.txt /home/user/a_directory/file2.txt" - This will
copy the file "file.txt" from the directory where you are, to into the
directory "/home/user/a_directory" and
give it the name "file2.txt"
cp: Copy several files with same extension ".txt"
Back to Index
Example: cp *.txt /home/user/a_directory - This will copy all files
with the extension ".txt" (like file1.txt, file2.txt and file3.txt)
from the directory you are in, into the
directory "/home/user/a_directroy", and the files will keep their names in the new directory "a_directory".
df: Will show you the sizes of your mounted partitions - see "man df"
Example: "df -h" shows you the mounted partitions, their names -and sizes in a human readable size (the "-h" option):

Above you can see following:
Back to Index
Partition "/dev/sda3" - size of 28 GB - mounted on "/" (Kubuntu on my system)
Partition "/dev/sda1" - size of 37 GB - mounted on "/media/sda1" (Ubuntu on my system)
Partition "/dev/sdc1" - size of 294 GB - mounted on "/media/disk" (An external harddisk on my system)
The rest of the output is a little more complicated to an average linux newbie.
As you can see, I have both Kubuntu -and Ubuntu installed on my harddisk.
dmesg: Helps users to print out their bootup messages - see "man dmesg"
Example: "dmesg | less" - Prints the output of the bootup messages to
the screen, one page at a time (shift page with the "Page Down/Page Up"
buttons).
Example 2: "dmesg > boot.messages" - Prints the output to a file "boot.messages" in the directory where you are.
mogrify: Can convert image files - see "man mogrify" - (is part of the "Imagemagick" package).
Example: mogrify -resize 50%x50% *.jpg - will convert all the jpg
images in the directory where you are, into a smaller size 50% x 50%,
and overwrite the images.
mogrify can do a lot more.
locate: To quickly search through all files on your system, to find a certain file
- see "man locate"
Back to Index
In order to use this command, you must first update the locate
database, by issuing following command: "sudo updatedb" - then wait
some minutes.
Example: "locate fstab | less" - to find where the "fstab" file is
located - it can sometimes give many suggestions, so you have go
through the listed suggestions.
Note, that all suggestions are given with full pathnames to the file, like "/etc/fstab" etc.
ln: To make links between files - see "man ln". (A link is a small file, leading to a real file, when clicked).
Example: "ln -s real_file link_file" (The "real_file" is the real file
[placed first], and the "link_file" is the link [which is placed last]
).
ls: Lists directory contents, lists both subdirectory -and file names of a directory - see "man ls".
Example: "ls" - lists the contenst of the directory you are in.
Example 2: "ls -al" - lists the contents of the directory you are in, with more information.
Example 3: "ls -al | less - lists the contents of the directory you are
in, one page at a time (use "Page Down/Page Up" to move down/up one
page at a time).
Example 4: "ls -al /home/user" - lists the contents of the "/home/user" directory.
mkdir: Make a directory - see "man mkdir"
Example: "mkdir /home/user/another_directory" - creates a new empty
directory of the name "another_directory" in the "/home/user" directory.
mount: To mount a filesystem
(e.g. an external harddisk formatted with an ext3 file system) - see
"man mount"
Back to Index
Example: "sudo mount /dev/sdc1 /media/disk" - means mount the external
harddisk "/dev/sdc1" on the "/media/disk" directory - (this is normally
done automatic).
mv: Renames files - see "man mv"
Example: "mv file.txt file2.txt" - renames the file "file.txt" to "file2.txt".
ps: Report a snapshot of the current processes (programs) - see "man ps"
Example: "ps -A | grep firefox" - to find the PID (process ID) number of "Firefox"
To find the PID of "Firefox", and then to "kill" the program (thought
situation, where the "Firefox" program has stopped working and we want
to "kill" it (below):

rm: Remove files - see "man rm"
Example: "rm file.txt" - removes the file "file.txt" from the directory you are in.
Example 2: "rm *.txt" - removes all the files with the ".txt" extension from the directory you are in.
Example 3: "rm /home/user/*.txt" - removes all the files with the
extension ".txt" from the "/home/user" directory.
Back to Index
rmdir: Removes empty directories - see "man rmdir"
Example: "rmdir /home/user/a_directory" - removes the "a_directory" directory, which must be empty.
split: Splits a file into pieces - see "man split"
Example: split -b 20k bigfile smallfile - splits the big file "bigfile"
into small files ("smallfileaa", "smallfileab", "smallfileac" etc) of
20 kb each.
To concatenate (join) the small files into one big file, put all the small files into an empty directory.
cd to that directory.
Then run from the command line: "cat smallfile* bigfile", and the files are again joined into one big file "bigfile".
sudo: Execute a command as "superuser" - see "man sudo" (The superuser can execute commands, which a normal user cannot do - a safety measure).
Example: "sudo konqueror" - opens the konqueror webbrowser as
superuser, which allows you to copy, move or edit files etc., owned by
user "root".
When you exexute a sudo command you must insert your user password, when asked for it.
tar: The tar command,
used to archive (create and compress) a big file from several
directories and files, or unarchive (extract and uncompress) the
contents of a tar file - see "man tar".
Back to Index
Example 1 (to create a tar archive):
Place all the directories and files you want to make into an archive file, into an empty directory.
cd into that directory.
Then execute: "tar cvzf archive.tgz *" - and the whole contents of the
directory you are in is archived and compressed into the archive file
"archive.tgz", and this file is
placed in the same directory.
Example 2 (to extract a tar archive):
Place the archive file "archive.tgz" in an empty directory.
(Please note: The ".tgz" extension is the same as the ".tar.gz
extension").
cd into that directory.
Then execute: "tar zxvf archive.tgz" - which unpacks -and uncompresses
the archive file "archive.tgz" into the directory you are in.
top: Display Linux tasks - see "man top"
Example: "top" - starts the top program, and you can see which programs
are running, how much processor power they use (%) and their "PID's"
and more.
whereis: locate the binary (file to start a program) - see "man whereis"
Example: "whereis gimp" - will give the path to the file "gimp" that starts gimp: "/usr/bin/gimp"
Note: Most binaries are placed in: /usr/local/sbin - /usr/local/bin - /usr/sbin - /usr/bin - /sbin - /bin
Most programs can be started from the command line, by just inserting
its name (gimp, firefox, kate, kmail etc.) and then press "enter".
Back to Index
9/2007