by Donald Daniel, 2010, revised Apr 2024

up one level

If the lines of text are too long you can fix the problem with these instructions.


This article teaches linux for beginners. This is based on Ubuntu linux, but will mostly apply to any version of linux. 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

These instructions emphasize features of linux that are different from Windows. You must first login then you will see the gnome desktop screen. Log in to ubuntu linux. In the top left corner of the gnome desktop screen you will see "activities". If you click on that, below it will be some icons to select some of the more popular software. If you click on these items they will work in a way that will be familiar to windows users, though not identical to windows. In the upper right corner of the screen will be an array of symbols. If you click on it, a black window will open below it. At the bottom of the black window will be three symbols. If you click the symbol on the right, a new window will appear that will give you the choice to "power off" that you will use to shut down the computer.

Click on "activities". One of the icons, a three by three array of 9 dots, will let you see application icons when you click on it. To the right of the array of application icons will be a vertical column of four small circle icons. Click on each circle icon to see a different set of application icons. The terminal icon is a gray rectangle, but so is the system monitor icon. Do not get them confused. You want the terminal icon. Right click on the terminal icon and click "add to favorites". 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. To do this, with the cursor in the first terminal, right click, a pop up window will appear, scroll down to "New Window" and left click on it, and another terminal will open. If your screen is so small the two terminals overlap, you can prevent this by resizing the terminals. Move the cursor to the right edge of a terminal until two arrows pointing in opposite directions appear. Then hold down the left mouse button and drag the edge to the left to reduce the size of the terminal. This works for the bottom edge too. This works for the right edge and the bottom edge of a browser also. On a small laptop with a screen only 10 inches (25.4cm) wide I can have two terminals and a browser open with no overlap.

Graphical user interface is referred to as GUI. This article is to enlighten the GUI generation to see that what they can accomplish on a computer is not limited to what can be accomplished with a GUI.

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". 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.

Some commands cannot be done as yourself, an ordinary user, but must be done as root or superuser. To do this preceed the command with the word "sudo", which will temporarily make you root or superuser until the command finishes executing. But never do that unless you are sure you know what you are doing, or you could damage your linux system.

Now, let us enter some more commands as ordinary user. 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 in the machinery part of a ship, where the engine, electrical, air conditioning, water and sewage machinery is. Most of the stuff you see is the machinery of the operating system. The directory "home" is like the passenger section of a ship. Now enter "cd", then enter "pwd" and you will see that you are back in your home directory. The command "cd xyz" will move you to a directory named xyz, if it exists, that is contained in the directory where you are currently located. By contrast the command "cd /xyz" will move you to a directory that is located in the "/" 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". "mv" can also be used to rename a file without moving it. "mv xyz uvw" changes the name from "xyz" to "uvw". 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 -bhs *". Similarly, to find the size of file xyz enter "du -bhs xyz". If you install the program "inxi", you can see all of your hardware described when you enter "inxi -Fxzd | more". If you want to see the type of filesystem use "df -T".

If you have a new installation of ubuntu linux, you will want to configure the thunderbird email program to work with your email service. In order to configure the ubuntu system to work with your printer you may have to search the net for how to do it for your particular brand of printer.


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 space bar 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 space bar 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.


If you cannot find software on your computer to do what you want, you can probably add the software free of charge. If you add free software available from ubuntu, you will be sure that it is compatible with your operating system. When you find an ubuntu package you want to download and automatically install, issue the command "sudo apt install` xxx" to get package named xxx. Another way to find appropriate software is to install the "synaptic" program and use it to search for and install what you want.

To get the google chrome browser search the web for a site where you can download it. It will ask if you want a "deb" version. You do. It will download to your "Download" directory. It will have a long file name ending in "deb". In the download directory enter "sudo apt install ./*deb". This will install it. You can find it by clicking on the nine dot pattern. When you find it if you right click on it you will be offered the choice to add it to your favorites so it will be displayed on your home page.

Your interests may be totally different than mine. Other packages I download are: g++, make, libtool, libgc-dev, gimp, ispell, script, dcraw, mmv, xfig, xfig-doc, tidy, gv, exfat-fuse, exfat-utils, vorbis-tools, cdrskin, geomview, texlive-latex-base, remind, sox, xorriso, wodim, cdparanoia, unhtml, pstoedit, cdrskin, handbrake and devede. Before any of this was installed, the command "df -h" showed that the hard disk, /dev/sda2, had 12G of linux on it. After all this stuff and a copy of this website were added, df -h showed 13G on the hard disk.

When adding many packages you do not need to type the whole command for each package. After you add one package, press the up arrow key and you will see the command you just entered. Use the backspace key to erase the end of the command where the name of the last package is, Type the next package you wish to install and press the enter key.

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.

If you use your computer regularly, from time to time, linux will automatically add updates to your existing software. If you have a laptop that you only use on trips, it will not be updated when you need it for a trip. If you would like to force an update to make sure you are up to date, here is how. Open a terminal. Enter "sudo apt-get update". After that your machine now knows what packages need to be updated. Next, enter "sudo apt-get upgrade", and the packages will be brought up to date.

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 ubuntu packages. Software obtained from other sources will not be included.


If the program is located in one of the "bin" directories just typing the name of the program in an active terminal 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 apt install 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. If you want to install an executable program by hand yourself, put it in /usr/local/bin, which is for use by all users. You must use "sudo mv xxx /usr/local/bin to move executable program xxx from where it is in your home directory to /usr/local/bin.

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. If you are in a directory below your home directory, but wish to execute a program or script that is located in your home directory, "~/xyz" will do that.

Bash comes ready to use with linux. You can write simple programs in bash and execute them in a terminal window. Bash programs are usually called scripts, not programs. If you create a bash script with the vi editor, you must use the chmod command to make it executable. In your scratch directory enter "vi scr" to create a text file named scr. In scr create the following text which is a bash script:

# this is a demo script
echo dog
echo $1
echo cat
echo $2 

The "$1" means the first thing after the name of the script that is on the same line as the name of the script when you execute the script. After creating this script enter "chmod +x scr". That makes the script executable. Then to test it enter "./scr elephant hippo ". The following results:


While the above example of a script is of no practical use, later in the "tools" section of this web page you will see other examples of scripts that are of practical use. Hopefully after seeing several scripts you will have the confidence to try making a script yourself if you feel you need one.

In the above example "$1" meant the first found. "$*" would be used in a script that you wanted to apply to one or all of the files in a directory.

There are books on bash, or you can enter "man bash" to find out more. I only do simple stuff with it, but some people do very complicated things with it. It is much more difficult to learn to program in bash than in my favorite language, oberon-2. The above example could have been programmed in oberon-2, but it would have been more time consuming to do. But it is very straightforward to write complicated programs in oberon-2. It is a nightmare to write complicated programs in bash. Bash is best for simple things.

If you start a program running, and it keeps running longer than you want, you can usually stop it by holding down the "ctrl" key and at the same time hitting the "c" key. This is usually described as "control-c" or "ctrl-c".


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. You do not need to be superuser to do this. 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/sdb1 on /media/(yourname/2365-21A3 type vfat ...". Minor details may be different on your computer. In fact the number may be different on your computer each time you insert a USB stick. This tells us the the USB stick is /media/(yourname)/2365-21A3. Now "cd /media/(yourname)/23*". Here the "*" is a wildcard so you do not have to type the whole thing. 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. For small files, you might get a complete copy without using sync. But for large files you probably will not get a complete copy unless you use sync. 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.

You will sometimes want to re-format a USB stick. One time I wrote a file on a USB stick and took it to be read by another computer. The person used commercial application software to read the file off the stick. But the application software corrupted the stick so I could no longer write to it. So it needed to be re-formatted. Here is how. Do not put the stick in the computer yet. Open a terminal window. Enter "mount". Write down the first few words of the last line. Put the USB stick in the computer. Enter "mount" again. Notice that a new line has been added after the last line. It might be something like "/dev/sdb1 on /media/yourname/23...". If you enter "cd /media/yourname/23*" you will be in the USB stick. "ls" will show what is on the stick. But you must not be on the stick to re-format it, so "cd" to get back to your home directory. Enter "sudo umount /dev/sdb1" so that the stick is no longer mounted but it is still in the computer. Enter "sudo mkfs.vfat /dev/sdb1" to re-format the stick with a new vfat file system. Now "mount" will not show the stick. Remove the stick and re-insert it into the computer. Now "mount" will show the stick. "cd" to the stick at "/media/..." and "ls" to see that it is now a blank re-formatted stick. To see how much space is on the stick and what kind of file system the stick has enter the command "df -hT ." . The period "." after "-hT" means the current file system, not the current directory as it would with other commands.

The vfat format works fine for USB sticks greater than 4GB, provided no file or directory is greater than 4GB. If you must store a file or directory that is greater than 4GB then enter "mkfs.exfat /dev/sdb1". But while every device can read vfat, many cannot read exfat. So it is very unlikely that you will want to use exfat, except for downloading pictures off of your camera SD chip. Camera SD chips are typically formatted with exfat. Ubuntu cannot read exfat unless you install the appropriate software. If you install "exfat-fuse" and "exfat-utils" you will be able to get pictures from your SD chip.

File size is not the only size limitation of vfat. Suppose you have downloaded a file with a very long filename. If you try to copy it to a USB stick it will not copy. You will need to use the "mv" or "cp" command to change the filename to a short name before you will be able to copy it to a USB stick.

You may wish you could plug an SD memory device from a digital camera into your computer, but your computer does not have an SD port. No problem. You can purchase an inexpensive adapter a little larger than the average USB stick. The adapter has large and small SD ports in it, and a USB plug that you can plug into the USB port on your computer.

Your computer may not have an internal optical drive for reading and writing to CD's and DVD's. You can purchase an inexpensive external optical drive that you can plug into your USB port. Linux will support this so it will work exactly like an internal optical drive.

You may want to make a bootable USB stick so you can install linux on a friend's windows computer. You would want to put the ubuntu iso file on the stick to boot into the ubuntu install program. But this must be done in a special way or it will not be bootable. If you plug the USB stick into your computer and enter the command "mount", the last line of the display will be something like this:

/dev/sdb1 on /media/(yourname)/(stick ID)

If you tried to copy the iso file to /media... it would not be bootable. If you tried to copy the iso file to /dev/sdb1 it would not be bootable. But if you leave off the "1" and copy the iso file to /dev/sdb it will be bootable. The command will be "sudo cp *iso /dev/sdb". It will take a long time. But remember you may have to change settings in the BIOS of your friend's computer, and repeatedly tap a special key during boot up in order to boot into the ubuntu install program.

Finally, one last caution. Suppose you wish to copy a USB stick with a vfat file system on it to another stick. The safe way to do that is to copy from the first stick to a directory on the computer, then from that directory to the second stick. If you attempt to copy directly from one stick to the other, it will result in an endless loop until the stick is full. Afterwards if you enter the "df" command you will see that you have a new batch of "/dev/loop" filesystems on your hard drive. To get rid of them enter "sudo apt-get purge snapd".


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.

The command lpr probably originally stood for "line printer". The original computer printers were either mechanical line printers or mechanical accounting machines that could also print. Originally they took data from punched cards, later directly from the computer from commands such as "lpr". In 1963 I used an IBM 407 mechanical accounting machine that read cards. It was about 51 inches high, 73 inches wide, and 31 inches deep from front to back. It weighed 2620 pounds or 1.3 tons. It rocked back and forth as it printed a line of text at a time on a long stream of fanfold paper.


Some things about linux must be configured to make it more useful.

If you have a laptop with a touchpad there is one thing you should do. If you are only going to use the laptop for something short and quick when away from home, you can get by with the built in touchpad. But if you are going to use the laptop at your desk or table for writing a report or other extended use, you will not find the touchpad satisfactory and will prefer to use a separate mouse plugged into one of the USB ports on the left side of the laptop. Any wireless mouse should work. If you click on "activities" a search window will appear at the top of the screen. If you enter "mouse" a window will pop up where you can adjust the speed of the mouse and the touchpad. You can turn the touchpad off. But remember to turn it on again before you shut the computer down if you will be using the computer with the touchpad and no mouse the next time you turn it on.

If you want to read files that are on your computer, use the files icon on the desktop. If you want to print a file with proper margins and page numbers, click on the office writer icon on the desktop. Import the file you want to print and set margins and format in office writer.

If you want to download and read e-books, then sudo apt-get install fbreader. Create a directory ~/Books to hold e-books.

If you have an hp printer or a printer that uses the hp printer language, run "sudo hp-setup -i" and accept the option to download the driver. If you later upgrade to a new version of ubuntu, the priner may stop working and you may have to run hp-setup again to get the printer working again.

For more about using the browser and the printer see this link: here.

If you would like to add the Chrome browser it can be added as described under adding software.

You may want to be able to play dvd's on your optical drive, if you have one. Many still cameras have a video mode where they can create video files in one of the following formats: MPEG4, MP4, M4V, MOV. If you have multiple short files that you wish to combine into one long file you can do that with ffmpeg. If you transfer these files to your computer, then with the program Devede you can burn them onto blank DVD-R disks to save your videos. You must do some configuration to your linux computer before you can play these dvd's using your optical drive. If you have an optical drive that plugs into a USB port, plug it in before doing these steps. The steps are: "sudo add-apt-repository multiverse", "sudo apt install libdvd-pkg", and "sudo dpkg-reconfigure libdvd-pkg".

Next, install the program "mpv". Then "mpv /dev/sr0" should play your dvd. If you want a wide 16:9 picture instead of the old 4:3 picture, enter "mpv --video-aspect-override=1.777 /dev/sr0". This is a lot to type. To avoid the problem create a bash script which we will arbitrarily name "playwide". It looks like this:

#play iso wide
mpv --video-aspect-override=1.777 $1

Then "chmod +x playwide" to activate it, "sudo mv playwide /usr/local/bin". Then you can enter "playwide /dev/sr0" to play a home made dvd in your optical drive. But it will be a bit more complex to play a commercial dvd in your optical drive.

A new optical drive probably does not have its region code set. If it is set correctly for your region, you will be able to play commercial dvd's. To set the region code in your optical drive "sudo apt-get update -y", "sudo apt-get install -y regionset". Then with your optical drive plugged in to your computer, run the program regionset and set the region code for your optical drive that matches the region where you live and purchase commercial dvd's. You will not be able to play commercial dvd's with "mpv /dev/sr0". Make sure the commerical dvd is in the drive. Enter the command "mount" and see the last line of the listing looks something like this:

/dev/sr0 on /media/myname/MOVIENAME type udf 

To play the commercial dvd you will not have to use playwide to get a wide screen display, it will happen automatically. Enter "mpv /media/myname/*" and it will play properly.

Suppose you want a still picture of a scene in a movie. If you are playing the movie with mpv, press "p" to pause the movie at the scene you want a picture of. If the movie is playing with a small picture within a window, move the cursor to the upper left corner of the window and click on the square icon to expand the window to full screen. Hold down the shift key and press the "PrtSc" button. A png version of the picture will be saved in ~/Pictures/Screenshot.


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.

There are many ways in linux to make hard jobs easy. All of the tools mentioned here are free software. Finally, you should get yourself a bound composition book of lined paper from the school supply section of your local grocery store. 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.

The most basic tool is to copy and paste. If you have text in a terminal window that you wish to copy to a window in a web page, here is how. Move the cursor to the beginning of the text in the terminal. Hold down the left mouse button and drag to the end of the text you wish to copy. Release the left mouse button. Move the cursor to the window in the webpage where you want the text. Click on the middle mouse button and the text will be copied into the window. Perhaps the most important use of this is to compose emails. Use the vi editor to compose an email in a terminal window. In your email program enter address and subject of a new email. Then copy the text from the terminal window and paste it into your email. Then send the email. This also works to post a message in a website that has a message window.

Suppose you want to find all occurrences of the word "glue" in every file in every directory at and below where you are. "grep -r glue *" will do this. But be careful, searching for "glue" will not find "Glue" or "GLUE". To solve this problem use "grep -ir glue *". "grep -c glue *" will count the number of times the word "glue" appears in every file in the directory where you are. If you want a file named "temp" that contains all the lines in "myfile" containing the phrase "I want this line" then "grep 'I want this line' myfile > temp" will do it. Then the command "wc -l temp" will tell the number of lines in the file temp. Grep is a powerful tool for analyzing the use of your website that is recorded in a logfile of hits. You can find how often one part of your website is found by linking from another part of your website. Or, consider the command grep -E -c -v windows\|mac\|android temp. This will find the number of lines in the file temp that do NOT contain the words windows or mac or android. If you want to find a file name, and not the contents of the file, then "find -name xyz" will find file named xyz.

Suppose you have downloaded a suspicious file and you want to find out what kind of file it is. The command "file *" will list every file in the directory where you are and tell what kind of file it is.

You will probably want to install the "zip" program so you can use zip files. If you want to create fancy pdf documents you will want "texlive-latex-base". If you want to convert an html document to pdf format, "htmldoc" works well, but skips graphics in the html document.

The best way to download a copy of an article from a website is to use "wget" to download it, instead of a browser. If a file you downloaded "file.html" has the source code of a program in it, the source code will be messed up in places by the process of converting it to html. Fix this with the command "unhtml file.html > file.text". The source code in the text version will be perfect.

For hearing some types of audio files you will need the "vorbis-tools" package. For some video work you will need "cdrskin".

For drawing things, you could use the openoffice draw program which comes with your ubuntu installation, which I have never tried. I use the older program "xfig".

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 and postscript files. But if you want to print pdf files, "lpr" will not work, "gv" will not work. To open local files with the firefox browser you may have to customize it to add an icon for opening local files. You can print it with the firefox browser, but the size will not be correct. If you print it with the chrome browser the size will be correct. To get the file in the chrome browser enter ctrl-o, which means hold down control key and type "o". A window will pop up that gives you access to local files.

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 bash 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.

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 is a program written in bash that will do this all at once:

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

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 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.

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 ubuntu, and must be installed without the help of apt. It is very easy to install following the instructions in the above link. 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.

"gimp" performs most of the functions of Photoshop. There are video editing programs but I am not familiar with them.

I have a collection of music CD's that I have bought over the years. But my car will not play CD's, it only plays music recorded on a USB stick. It will only play mp3 format, not the wav format on the CD. So I must read the music from the CD into the computer, convert it to mp3, then write it to a USB stick to play the music in the car.

I put the music CD in the optical drive in the computer. I need to use the program cdparanoia to copy the music files off the CD. Cdparanoia will work if you are not root, but it will not work correctly: an extra file or two will be added. In an empty directory I issue the command "sudo cdparanoia -B". This will read the music files to my directory as wav files. "ls -l" will show that root owns the files, not me. "sudo chown myname:myname *" will change ownership to me. But the file names will be too long. Use "mmv" to convert the names to shorter names. You can play a wav file with the command "play file.wav". If you need to truncate or otherwize alter one of the wav files use the program audacity. Next, use the following script called "wv2mp" to make mp3 files from the wav files:

# convert wav to mp3
namechange () 
echo "$newname"
ffmpeg -i "$oldname" "$newname" 
for filename in "$@" ; do
namechange "$filename"

The command "./wv2mp *wav" will convert all the files, leaving the original wav files intact. You can play each mp3 file on your computer with the command "mpg321 file.mp3". Then move the mp3 files to an empty directory. Then make a directory on the USB stick you will use in the car. The directory should have a name that will remind you of the type of music. Suppose the name of the directory on your computer is "dir". Go into the directory on the USB stick and copy with "cp mycomputer/dir/* .". That way the files will be copied in the order of their filenames. If on the other hand you did "cp -r mycomputer/dir ." the files would be copied in the order they were put into the directory, which might not be the order of their filenames. This is important because some music players that play USB sticks play music in the order that it was put in the directory, not the order of the filenames.

A friend of mine has a car that accepts CD but not USB. The program "wodim" can write wav files to CD and the program "xorriso" can write mp3 files to CD. Her car CD player can play both. The next two paragraphs will give detailed examples.

To burn audio CD of wav files, be in the directory on your computer that contains the wav files. Put a blank CD-R into the drive. Enter "sudo wodim -v dev=/dev/sr0 -eject -pad -audio *wav". This will burn the audio file and eject the CD.

Burn mp3 files the way you would burn any kind of data to a CD or DVD. Remember a CD holds only about 0.6 GB, but a DVD holds 4.7 GB of data. Be in the parent directory above the directory that contains the data or the mp3 files that you wish to burn. Suppose that directory is called "mydir". Then put a blank CD-R or DVD-R in the drive. Enter "xorriso -outdev /dev/sr0 -map mydir". The directory will be burned to the blank disk.

Most digital single lens reflex (DSLR) cameras can be set to produce either of two raw formats. A format that is proprietary to your brand of camera or DNG format, which most cameras can also produce. Unfortunately the DNG format does not include the camera settings used to take the picture. Most proprietary formats do. If you use your DSLR camera to take a picture in automatic mode, you may not remember what aperture and shutter speed was automatically selected. The program "exiftool" will handle most proprietary formats. If you used the proprietary format, and you have installed the program "exiftool", the following script will display the settings your camera used to take the picture. I named the script "camset".

# camera settings from raw files
echo f# speed iso
see ()
echo "$filename"
exiftool -T -aperture -shutterspeed -iso $1
for filename in "$@" ; do
see "$filename"

My camera is a Pentax camera, so the raw format it uses the PEF format. Following is an example of the use of the script to get information from my picture file named "IMGP0480.PEF".

./camset *480.PEF
f# speed iso
10.0    1/50    400

If I put camset into /usr/local/bin I would not need the "./". If I wanted it to list the parameters for every PEF file in the directory, I would invoke it as "camset *PEF".

I have a new digital camera body that I use with old film camera lenses. The camera settings are recorded in the raw picture file even when the camera is set to the manual mode, if done properly. The lens aperture is not set on the lens. The lens is set to automatic. Then the aperture is set by the camera controls. When done this way, aperture, speed and iso are recorded in the picture file.

A DSLR camera can produce image files in jpeg format or raw format. You can install the program "dcraw", which converts raw still camera formats to ppm format, which can then be converted to jpeg with "pnmtojpeg". Dcraw works on DNG files and most proprietary raw formats. 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 if you follow the instructions in the dcraw man page.

If you want to convert full frame DSLR pictures to display on the screen, the following scripts will do the job. First you must take the pictures raw, then use dcraw to convert them to ppm format. The height to width ratio of a typical desktop computer screen does not match the ratio of the camera frame. The first script makes the height of the picture match the height of the screen. The second script makes the width of the picture match the width of the screen. Both scripts assume the computer screen is 1920 by 1080 pixels, and the camera frame is 7360 by 4912 pixels.

The first script is "hgt2scr":

#convert dslr ppm to jpg to fit screen height 
namechange ()
echo "$newname"
pnmscale 0.2 "$oldname" \
| pnmtojpeg > "$newname"
for filename in "$@" ; do
namechange "$filename"

The second script is "wdth2scr":

#convert dslr ppm to jpg to fit screen width
namechange ()
echo "$newname"
pnmscale 0.25 "$oldname" \
| pnmcut -top 120 -bottom 1162 \
| pnmtojpeg > "$newname"
for filename in "$@" ; do
namechange "$filename"

Much of the software that will print "png" file format on a printer will automatically reduce the image to fit the printed page. If the image is text surrounded by white border, the whole image, including the border, will be automatically shrunk to fit the page. This makes png format attractive for making print copies of documents that are photographed with a digital camera.

Suppose you want to create "png" files representing only the ink on the stained and yellowed pages of an old manuscript or book. You can use a DSLR camera to photograph the pages. It is best to use a copy stand to mount the camera. If you must shoot the pictures with a hand held camera, use a shutter speed of 1/125 second or faster so the image is not blurred by motion of the camera. You set the camera to save the images in raw DNG format or a proprietary format. Transfer the DNG files to your computer. Use dcraw to convert a typical page to ppm format. Use gimp to view the ppm version of the picture to see the coordinate numbers of the area you want to use as a color reference to make the pages white. Use dcraw to get the numbers needed to make the yellowed pages appear white. See the "man" page for dcraw to understand what you are doing. An example might be:

dcraw -v -A 1000 1000 5000 3000 page1.DNG
Write down the numbers that are needed to whiten the pages. Then use the numbers to convert all the DNG files of yellowed pages to ppm files of white pages:
dcraw -v -r 1.0 1.0327 2.293 1.037 *DNG
Then use gimp to see the left, top, right and bottom coordinates in the image that are beyond the page of the book and that you want to cut out of the image. But do not cut the image with gimp, use the script below for that. Use the following script to change all of the ppm files one at a time to png files:
# use netpbm to convert book page photo to png
# convert dng to ppm with dcraw
# eliminate lines between ppmtopgm and pnmtopng  
# add lines one at a time and view results with gimp
# divide text width by 6 to get pixels per inch
# cut between text and dark borders of image 
# pad way beyond what you need 
# cut for 1.5 inch left border, 8.5 inch page width
# 1 inch top border, 11 inch page height
# convert ppm to png one page at a time
# png file will print from gimp, not lpr
echo "$newname"
ppmtopgm "$oldname" \
| pnmflip -cw \
| pnmrotate 0.6 \
| pnmnorm -bvalue 200 -wvalue 201 \
| pnmcut -left 500 -right 4500 -top 1100 -bottom 6300 \
| pnmpad -white -left=1000 -right=1000 -top=1000 -bottom=3000 \
| pnmcut -left 594 -width 4471 -top 822 -height 5851 \
| pnmtopng > "$newname"

You will need to consult the "man" pages for each of the commands in this script to understand how it works. You will need to use the early parts of this script to view the ppm files in gimp to see how to adjust the numbers. When the numbers are adjusted right then add the later parts of the script.

Note that we have not used pnmscale to reduce the size of the images. The whole images can be seen in gimp. But if you use the display command to see the image it will be too large to fit on the screen. But that does not matter if you want to print the files onto paper. If the images were reduced in size to display on the screen the resolution would be reduced. The large image has full resolution and will print beautifully. Most print software will automatically reduce the image to fit on a page. The resulting png file can be printed to fit on a page from gimp or from the linux file viewer. It can also be printed from file viewers in Windows and in the Apple operating system. You can email it or post it on your website and others can print it.

Some people will want to have their own personal website on the web. I only have experience with the simplest form of websites that do not even use CSS. You will contract with a hosting service and learn how to upload your html files. You can create your html files with the vi editor. Use "tidy" to check for html errors before uploading. You will need to create a configuration file for tidy called ".tidyrc". The leading "." makes it an invisible file which will not show with "ls" but it will show with "ls -aF". It will go in your home directory "~". I recommend the following .tidyrc:

wrap: 63 

Indent has to be "no" for the "!fmt" function in the vi editor to work when you edit the file. "xml" has to be "no" for source code in the html file to work. If you have program source code in your html file put "< p >" before the source code and "< /p >" after the source code. This will prevent automatic line wrap from affecting the source code. But the space characters in these two terms must be omitted for them to work properly for tidy and for html rendering in a browser. They are invisible in the browser. They had to be included here to appear in the text as intended. In the source code the characters "<" and ">" must have space characters on both sides or tidy will mess up the source code.

If you want someone to be able to download your html file and be able to compile and run your source code, they should use "wget", not a browser to save the file to disk. This will avoid unintended changes to the file. Then in linux they use "unhtml file.html > file.text" then the source code in file.text will be in a form that should compile and run.

If you have a text file that you suspect has troublesome non-printing characters in it, you can see them with the command "hexdump -c file.txt". But the hexdump takes up too much space in the terminal window to make it practical to dump the whole file. So extract only two lines that you suspect have the character into a small file. Then hexdump the small file. To interpret what you are seening in the dump, in a separate window do "man ascii". When you see the problem, the "tr -d" command can be used to remove such characters everywhere in the file.


While presentations do not involve the terminal, there is no where else in this site appropriate for the subject.

If you have a laptop computer running Ubuntu, you may wish to connect it to a TV screen or a TV projector to give a presentation to others. Your presentation will consist of jpeg, png or ppm still pictures, and possibly videos in MP4 or M4V format.

If your laptop has an HDMI port and the TV also has an HTMI port, connect the laptop with the TV using a long HDMI cable. I have used a 25 foot long cable satisfactorily.

To make your computer deliver picture and sound to the TV, you will have to change software settings in your computer. At least one of the things you need to change will not even appear in your computer until you are connected to a TV that is turned on.

First, the picture. Click on "activities". In the search window that appears enter "display". If and only if the TV is turned on, the popup window will have a section "display mode". That section will have three modes to choose from: "join displays", "mirror", and "single display". Click on "mirror", then your computer display will appear on the TV. You could use the command "display" in a terminal to display still pictures. But that would have the disadvantage that large pictures would appear too large for the screen. Instead Click on the "files" icon under "activities". That application will display large pictures reduced in size to fit the screen. If you click on an icon at the top of the screen you can expand small pictures. It will also play videos in the MP4 or M4V formats.

To get sound sent to the TV when you are displaying a video, click on "activities", enter "sound" in the search window. Set "output volume" to ON, adjust volume slider, in "output" section under "choose a device for sound output", select "HDMI". Now the TV should play the sound of your video.


A minor disaster you may want to recover from is if you start a long printout, and realize something is wrong and want to stop the printout. Enter "lpq" to see the job number of the printout, which might be 87. Then enter "cancel 87". Then enter "lpq" again and the print job should be removed from the list. This will stop sending any more pages to the printer. But the printer memory may already be full of pages that it has not yet printed. You may have to temporarily remove the power plug from the printer to erase the printer memory. One time the printing quit working because of an unknown software glitch. "Restart" would not fix it. I had to shut down completely and turn the computer back on. If you have a bunch of print jobs you wish to cancel enter "sudo cancel -a".

Another disaster is when the screen freezes and nothing you do has any effect. Hold down the "ctrl" and "alt" keys, and tap the "F2" key. This should switch you to a black screen. Enter the user name "root", then the root password, then the command "shutdown -h now". This will shutdown the computer. Alternatively, you could enter "shutdown -r now", and the computer will shutdown and reboot.

Hard drives do not last forever. If boot up fails with a black screen requiring you to run "fsck", or if your personal files mysteriously become "read only" so you cannot write to them, your hard drive may be starting to wear out. Of course, a new hard drive will be blank, requiring new software installation. You need to back up personal files first. It is easy to replace a hard drive on a desktop machine with a full sized tower, not so easy on smaller machines. On a full sized tower you typically remove the side panel of the cabinet, unplug two connectors from the back of the hard drive, unscrew two screws holding in the hard drive, slide out the old hard drive and slide in the new one. Hard drives are a very small fraction of the cost of a new computer. Before you remove the old hard drive you may want to zero it out to protect private files. In the directory /dev see if sda or hda is listed. If so that is the name of your hard drive device. The command "sudo dd if=/dev/zero of=/dev/sda" will zero your hard drive after a few minutes.

You will use the "ls" command to list the files in a directory. Suppose you have a file named "file" and want to remove it. "rm file" should work. But if it does not, The filename may have an invisible non-printing character in the name. "rm file" will say there is no such file. But "rm -v file" will say there is such a file and ask you if you really do want to delete it. "rm -rf" will also force deletion of files and directories. If you have a directory full of such files "rm -- *\ *" will delete them all.

up one level