HOW TO USE LINUX

by Donald Daniel, 2010, revised Feb 2012

up one level

INTRODUCTION

This is based on Debian linux, but will mostly apply to any version of linux. It assumes that the linux installation included "gnome desktop" and "standard system". If you have not yet added linux to your windows computer instructions are provided here.

This introduction to linux is designed to get you started quickly. If you need a much more lengthy and detailed article see http://tldp.org/LDP/intro-linux/html/.

These instructions emphasize features of linux that are different from Windows. You must first login then you will see the gnome desktop screen. Make sure that you log in as an ordinary user, not as superuser. In the top left corner of the gnome desktop screen you will see "applications", "places", "system", a blue disk which is your browser, and an envelope which is your e-mail program. Below this you will see "computer" and "trash". If you click on these items they will work in a way that will be familiar to windows users, though not identical to windows. I will leave you to explore these on your own, except for "system" "shutdown", which you will need to shut down your computer.

Click on "applications", "accessories", "terminal" to open a terminal window. The real power of linux will be accessed from a terminal window, and that will be the focus of this course. You can open more than one terminal window at a time.

Click the mouse anywhere in a terminal window to activate the terminal. Anytime you are instructed to type a command, hit the "enter" key afterward, since no command takes effect in linux until you hit "enter". Then enter "pwd", which means "print working directory". Directory in linux means the same as folder in windows. You will see something like "/home/yourname" where "yourname" is whatever user name you picked when you installed linux. Next, enter "cd /", then enter "ls". "ls means "list". You will next see the following list of directories and files: bin boot cdrom dev etc home initrd.img lib lost+found media mnt opt proc root sbin selinux srv sys tmp usr var vmlinuz.

You are now at the root directory of the file system, "/". This is like being at the bottom of a ship below all the machinery. Most of the stuff you see is the machinery of the operating system. The directory "home" is like the passenger decks on the ship. Now enter "cd", then enter "pwd" and you will see that you are back in your home directory.

In your home directory enter "mkdir wkspc". "mkdir" means "make directory". Then enter "ls". You will see the new directory "wkspc" that you have just created with the command "mkdir". Now "cd wkspc". Now you are in the directory "wkspc". Now enter "mkdir back ltr photo scratch". Now enter "ls" and you will see the directories you have created to hold your backup files which will be saved to a USB stick to save valuable personal data in case of a hard drive failure, letters or emails that you have written, photographs you have loaded onto your computer, and a scratch directory where you can do messy work that you only want to retain temporarily.

Enter "cd scratch" to get into your scratch directory. Next you should learn the vi editor, and in your scratch directory create some little unimportant file of nonsense called "xyz" that you can experiment with.

Now enter "cp xyz abc". "cp" means "copy". Then "ls". You will see that you now have two files, "xyz" and "abc". Look at them with the vi editor and see that they are the same. Now enter "rm abc", then "ls" and you will see that you have removed "abc".

There is an easy way to refer to certain directories. Your home directory is "~". The directory where you are at any given time is ".". The parent directory of where you are is "..". If you are in your scratch directory, enter "pwd" then "ls", then enter "cp xyz ~". You have now made a copy of xyz in your home directory. Enter "cd .." then "pwd" and "ls". You are now in your wkspc directory. Again "cd ..", "pwd" and "ls". You are now in your home directory and can see the copy of the file xyz that you just made. Now "cd wkspc/scratch", "pwd" and "ls", and you see that you are back in your scratch directory. Now in your scratch directory and enter "rm ~/xyz" and you have removed the copy of xyz in your home directory.

Now in your scratch directory enter "cp xyz t1", "cp xyz t2", "cp xyz t3", then "ls". You now have xyz, t1, t2, and t3 in your scratch directory. Now we use the wildcard character *. Enter "rm t*" then "ls", and you will see only xyz remains, the others have been removed. By saying "t*" we referred to everything starting with "t". If we had said simply "*" we would have removed everything. "rm" just removes files. "rm -rf" removes both files and directories. You are doing this as an ordinary user, not a superuser, or root, as superuser is also called. As an ordinary user you cannot remove any of the stuff you saw in the directory "/". But as superuser you could. This is VERY DANGEROUS!!! Be very careful what you do as superuser. If at "/" as superuser you did "rm -rf *" you would remove your whole linux system!

If you want to move a file from one place to another, you could "cp" to create the new version then "rm" to delete the old version, but it is simpler to just "mv" which means "move". To copy a whole directory and not just a file, use "cp -r" and the name of the directory. "ls" will list directories and files, but you may not know which is a directory and which is a file. There are also hidden files with names having "." as the first character. To list all directories and files, including the hidden ones, use "ls -aF". In your home directory you will see some hidden files. Directories names will end in "/" to distinguish them from files. To see the size of files and other information about the files do "ls -l".

To see how much of your filesystem is used enter "df". The entry "/dev/hda2" or similar which is mounted on "/" is the important one. To see how much space is used by each directory enter "du -s *".

FINDING INSTRUCTIONS

There are several sources of information contained in your linux system, and if these fail, you can google your question and probably find and answer.

To find out how to move things we would enter "apropos move". A list of commands related to moving will be shown. If the list ran off the screen we could contain it with "apropos move | more". The "more" command limits the size of lists to one screen at a time, with the spacebar being used to see the next screen full of a long list. If we want to find out more about a command in the list, such as "mv", we would enter "man mv". "man" means "manual" or "handbook". Most commands have a "man page". An exception is "cd". This is because cd is not really a stand alone command, but is part of bash, so "man bash" will contain an explanation of cd. Bash is a program that starts running automatically when you open a terminal window. Its purpose is to create a user friendly environment.

There other places containing instructions, most notably in /usr/share/doc. If you do "ls" the list will scroll off the screen, so to "ls | more", then hit the spacebar to see each screen of the list. These are all directories. Most of the files in these directories end in ".gz". The vi editor will not read these. Instead, to read "file.gz" enter "zless file.gz". This will unzip the file into the vi editor.

ADDING SOFTWARE

If you cannot find software on your computer to do what you want, you can probably add the software free of charge. Go to http://packages.debian.org /stable and look for what you want. Make a list of the packages you want. Then enter "su" and your superuser password, then enter "synaptic", and then click on "search" and enter the name of the package you want. When you click on search a "find" window will pop up. In the find window is a "look in" bar with different options. Sometimes one option will find what you want and another option will not. You will see an alphabetical list containing the package you want. Scroll down the list until you see the package you want. Click on it to see a description. If it is really what you want click on the tiny square to the left of the package name to select it for installation. The package you selected may depend on additional packages, which will automatically be selected also. When you have found and selected all the packages you want, click on "apply". When the process is all finished, exit the synaptic program and be sure to enter "exit" to quit being superuser and go back to being an ordinary user.

If you are not sure whether you have a certain piece of software on your computer, use the "whereis" command. Thus "whereis vi" will yield "vi: /usr/bin/vi /usr/share/man/man1/vi.1.gz" which shows where the various parts of vi are stored. But "whereis dog" will simply show "dog:" meaning that you have no such program.

To see a list of the software packages that are already installed, enter "dpkg --get-selections > temp" then use the vi editor to look at the list in the file temp. This procedure will only list debian packages. Software obtained from other sources will not be included.

If you add non-debian software to your computer, it will have to be invoked from within a terminal window, not from an icon. Thus, if you install the google chrome browser, to invoke it open a terminal window and enter "google-chrome".

BACKUP PERSONAL FILES

About once a month you should backup your personal files, saving them on two USB sticks, so that if your hard drive fails you will not lose your work. First, copy all the files you must save to your backup directory, wkspc/back. Then enter "mount". Notice the last line of the listing. Insert a USB stick into a USB port on your computer. A large rectangular window may pop up, get rid of it, we will not use it. Enter "mount" again. Notice a new line added to the end of the listing, something like "/dev/sda1 on /media/disk type vfat ...". Minor details may be different on your computer. This tells us the the USB stick is /media/disk. Now "cd /media/disk" then "ls" to see what is on the USB stick. Do "rm -rf *" to erase the USB stick. Then "cp -r ~/wkspc/back .", where the final "." means put the copy in the directory where you presently are, the USB stick. If there is a lot of stuff, this may take a while before the cursor re-appears. Do not be deceived, the copy is not finished at this point. Enter "sync" and wait until the cursor re-appears. Now the copy is finished. To make sure the copy is a good one, enter "diff -r back ~/wkspc/back". If no errors appear the copy is a good one. First "cd" to your home directory, then you can remove the USB stick. It is best to make backup copies on two USB sticks just in case one of them should fail for some reason, and keep them stored in separate places.

EXECUTING PROGRAMS

If the program is located in one of the "bin" directories just typing the name of the program will execute it no matter what directory you are in. The main bin directory is "/bin". You can see it listed if you type "ls /". When you use the synaptic package manager to install programs they will be put in that bin directory or a bin directory at a lower level. You should never tamper with these directories yourself, let synaptic do it. If you want to install a program by hand yourself, put it in /usr/local/bin, which is for use by all users. You must be superuser to do this.

If the program "xyz" is not in one of the bin directories, but is in the directory where you are, typing "xyz" will do nothing. Instead, type "./xyz" which will execute it. Notice the period before the slash.

STANDARD OUTPUT

Some programs put their output to "standard output", which is the screen. Thus the command "ls" will list the files in the current directory on the screen. But suppose you want the list in a file. "ls > temp" will put the list in the file "temp". The ">" redirects standard output to a file. If you wanted to print the file you could enter "lpr temp". But you could use a pipe, "|", instead. Thus "ls | lpr" will pipe the output of the "ls" command to the "lpr" command and the list will be printed.

PRINTING FROM THE BROWSER

This subject should not be needed here, but it is. The browser operation is not as obvious as it should be. The default way to print is with ridiculously small margins. To set the margins, click on "file", "page setup", "paper size", select "manage custom sizes". "custom size 1" will be the default. Select one inch margins, close. Make sure "paper size" is set to "custom size 1", then click "apply". Now you can print with decent margins. If embedded pictures are not too large they will print within the margins.

LINUX TOOLS

You could spend a lifetime mastering all the tools in linux. Here is a sample to familiarize yourself with the sorts of tools that are available.

Suppose you have a list of old movies in the form title, year, comments in a file named "list" like this:

show people, 1928, m
the battle of the sexes, 1928, dw griffith
the patsy, 1928, documentary following movie

You can sort this list by year, and within each year alphabetically with this command script:

sort -t , -b -k 2,2 -k 1,1 list > temp
mv temp list

When you first use the vi editor to create this script in a file arbitrarily called "srt", "ls -l srt" will show that it is not executable. Make it executable with the command "chmod +x srt". Now "ls -l srt" will produce different results showing that it is executable. Then to sort your list enter "./srt". Each field title, year, comment is separated by a comma. In the script we have chosen the comma as a separator. So if a title had a comma in the title, the comma would have to be left out for the sort to work properly.

Suppose you want to find all occurences of the word "glue" in every file in every directory at and below where you are. "grep -r glue *" will do this. "grep -c glue *" will count the number of times the word "glue" appears in every file in the directory where you are.

There are many linux commands that change a file from one format to another format. This includes text files, graphics files, audio files, etc. Suppose you want to change a large number of files in one format with one suffix to another format with another suffix. File suffixes matter to the windows operating system, but they do not matter to the linux operating system. Suffixes do matter to some programs in linux. Take a trivial example of files like "t1.txt" that are lower case with "txt" suffix. You want to make them upper case with "caps" suffix. The command "tr 'a-z' 'A-Z' < t1.txt > t1.caps" would do this. But it would be a lot of work to do this for t2.txt, t3.txt, ...t100.txt. The following script will do this all at once:

#  make caps files from txt files
namechange ()
{
oldname=$1
newname=${oldname%.txt}.caps
echo "$newname"
tr 'a-z' 'A-Z' < $oldname > $newname
}
for filename in "$@" ; do
namechange "$filename"
done

If we arbitrarily choose to call the script "proc", then "chmod +x proc" will make it executable. "./proc t1.txt" will perform the operation for t1.txt. But "./proc *.txt" will perform the operation for all of the files in the directory with "txt" suffix. For some other format changing command and other suffixes, you could change the suffixes in this script and change the command line. If your line is too long, end it with "\" and continue on the next line, but you must be careful that the "\" is the last character on the line, and there is no invisible space character " " following it. The line starting with "#" is just a comment, and has no effect.

The previous example is instructive but not very useful. Now for a more useful version of the kind of script in the previous example. Suppose you want to create "png" files representing only the ink on the stained and yellowed pages of an old manuscript or book. You use a digital SLR camera and incandescent light to photograph the pages. You set the camera to save the images in raw DNG format. Transfer the DNG files to your computer. If the numbers are adjusted properly for your conditions, the following script will convert the DNG files to png files showing only the ink on the pages:

# convert dng to png 
namechange ()
{
oldname=$1
newname=${oldname%.DNG}.png
echo "$newname"
dcraw -c -r 1.0 1.0327 2.293 1.0379 "$oldname" \
| ppmtopgm | pnmflip -cw \
| pnmscale 0.35 \
| pgmenhance -5 \
| pnmnorm -bvalue 150 -wvalue 200 \
| pnmtopng >  "$newname"
}
for filename in "$@" ; do
namechange "$filename"
done

You will need to consult the "man" pages for each of the commands in this script to understand how it works. The numbers used in the dcraw command were obtained by using the gimp command to find a region of the image that contains only paper and ink, then using dcraw with the "-v -A" options to find the numbers to balance the paper color to white.

The command "mv" for moving and renaming files comes with linux. But you might want to install the more powerful command "mmv". Suppose you have a list of files like "access_110606.log", "access_110613.log", etc. representing log files for the month of may. The command [mmv "*1106*.log" "may-#2"] would change the names to the simpler form "may-06", "may-13", etc. Here the brackets [] are not part of the command, but are used because the double quotes " are part of the command.

To see graphics files or pdf files click on "applications" "system tools", "file browser", then click to find the directory where the file is. But if you are in a terminal window where the file is, it would be quicker to use a command to display what you want to see. If the imagemagick package is installed, "display xyz" will display the graphics file xyz for most formats. If "gv" is installed, "gv xyz" will display pdf files.

For photography, there is "dcraw", which converts raw still camera formats to jpeg. If there is a gray card in the scene, or a separate gray card shot taken at the same time, perfect color balance can be achieved. "Gimp" performs most of the functions of Photoshop. "Kino" does video editing on video from standard definition digital video, but not yet high definition video.

My favorite linux tool is oo2c, which I use to program the computer when I want to accomplish something for which there is no built in function. It is not available from debian, and must be installed without the help of synaptic. It automatically installs in /usr/local/bin.

If you want to save an example of a detailed procedure so that you can email it to someone or remember how you did it, the "script" command is useful. Before you start your procedure type "script". Then after completing your procedure hold down the "ctrl" key and type the letter "d". This will write everything that has just happened into a file called "typescript". In the vi editor you can see that the file will be in windows format with carriage returns at the end of each line. You can remove these if you wish as explained in the article on how to use the vi editor.

There are many more ways in linux to make hard jobs easy. All of the tools mentioned here are free software. Finally, you should get yourself a bound book of lined notebook paper and title it "howto". Every time you figure out how to do something in linux, enter it in your "howto" book. This will save you the frustration of having to figure out the same thing twice.

up one level

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.