| typical extension | file type | application(s) |
| txt | text or ascii file | cat, less (view) |
| nedit, emacs (edit) | ||
| Adobe PDF | acroread, xpdf, gv (view) | |
| ps, eps | postscript | gv (view) |
| pstops (rearrange) | ||
| ps2pdf (convert) | ||
| html, htm | web page | links, konqueror, mozilla (view) |
| soffice (create) | ||
| png, jpg, gif... | graphic files | display (view) |
| import (snapshot) | ||
| convert (convert) | ||
| gimp (manipulate) | ||
| doc, xls, ppt | Office document | soffice |
| sxc, sxi, sxw | OpenOffice document | soffice |
| tex | TeX and LaTeX documentz | tex, latex, pdflatex (process) |
| dvi | Dvi documents | xdvi (view) |
| dvips, dvipdf (convert to ps or pdf) | ||
| gz, Z | Compressed file | gunzip, zip, bunzip2, bzip2 |
| tar | tar archive | tar tf (view) |
| tar xf (extract) | ||
| tar cf (create) | ||
| tar.gz | compressed archive | tar xzf (extract) |
| tar.bz2 | Compressed tar archive | tar xjf |
| zip | zip archive | unzip -l (view) |
| unzip (extract) | ||
| zip (create) |
Most linux applications can generate postscript files, which usually have the extension '.ps'.
Postscript is a language that describe how things should be drawn on pages; this language is understood by postscript printers. Non-postscript printers needs special drivers that convert from postscript onto their own format.
You can preview a postscript file on the screen;
gv file.ps
To put 'file.ps' into the printing queue of the printer known as 'printername':
lpr -P printername file.ps
The printers can be attached to the local system via a parallel, serial, or USB port, or available over the network. To get a list of available printers:
lpstat -p -d
To check the status of all printers:
lpstat -a
To remove a printing job:
lprm job-id
(job-id is the number reported by the lpr or lpstat commands).
If your system uses the priting system 'CUPS', you can access its documentation by opening the following address in a browser:
http://localhost:631/documentation.html
Images are stored in bitmap files which have extensions .gif, .jpg, .png, .tiff...
To display an image, e.g. file.gif, use:
display file.gif
To convert from one format to another:
convert file.jpg file.eps
Note: I advise against using jpeg format because it loses quality: for bitmaps, use the 'png' format instead; for vector graphics, use eps (encapuslated postscript).
To take a snapshot, i.e. copy the screen or part of the screen into an image file, e.g., 'file.png', type
import file.png
The 'display', 'convert' and 'import' commands are part of the package ImageMagick, which provides other commands to manipulate bitmap graphic files. To know more, type:
man ImageMagick
To manipulate an image, e.g. file.jpg, use
gimp file.jpg
I personnaly use 'xfig' to construct complex graphics. Yet the ergonomy of xfig is very different from what users expect nowadays.
You can try 'sketch', 'dia' or openoffice impress.
To know how many files with extension img are in the current directory:
ls *.img | wc
To copy a file in the same directory, giving it name2:
cp file1 file2
To copy a file from the current directory to directory `dir':
cp file1 dir
To rename a file:
mv file1 file2
To move a file to the directory `dir':
mv file1 dir
To delete a file:
rm file
To copy the directory 'dir' in the destination directory 'destdir':
cp -a dir destdir
(Note: the '-a' option does a recursive copy - that is includes the subdirectories - and preserves the attributes of files)
To move the whole directory 'dir' into 'destdir':
mv dir1 destdir
To rename directory 'dir' as 'dir2':
mv dir dir2
To delete the directory 'dir' and all its content:
rm -rf dir
To locate the file 'filename', searching all the subdirectories of the current directory:
find . -name 'filename'
You can use a pattern in place of 'filename', e.g.:
find . -name '*.doc'
The 'find' command can do much more: consult 'info find' for more information.
du -h dirname
It may be useful to sort the subdirs by size:
du -k | sort -rn
To list files accroding to their size:
ls -Sl
To see the space available on the mounted partitions:
df
If there are quota that limit the amount of space you can use on your account:
quota
To avoid copying a file in several places on the same disk, it is a better idea to use a link:
ln existingname newname
Thus the same file can have several names (and be in several directories at the same time).
Amovible media (cd, floppies...) must be 'mounted' to make their content accessible, and 'unmounted' before ejection (see the man pagfes of mount and umount). The precise parameters depend on the configuration of your system. On some systems, 'mouting' and 'unmouting' are performed automatically thanks to the 'supermount' system.
On my system, I enter the command:
mount -t iso9660 /dev/cdrom /mnt/cdrom
/mnt/cdrom then points to the content of the CD. When you are finished, do not eject the CD manually. Rather, type:
umount /mnt/cdrom eject
The same goes for floppies:
mount /mnt/floppy # the content of the floppy should now be accessible under /mnt/floppy # IMPORTANT: before ejecting the floppy, type: umount /mnt/floppy
In some systems, normal users are not allowed to mount a floppy. Ask the system administrator to grant this right in /etc/fstab.
In some systems, the 'mdir' and 'mcopy' functions allow to list and copy to or from a floppy without mounting it (see 'man mtools').
To rip an entire audio CD:
cdparanoia -B
To just rip one track:
cdparanoia -w track_number file.wav
If you prefer programs with graphical interface, you may use 'grip'. One nice feature of 'grip' is that it will interrogate Free-DB to try and determine the songs' titles.
I use lame:
lame file.wav file.mp3
But it is a better idea to use the open format 'ogg vorbis' rather than mp3:
I use oggenc:
oggenc file.wav -o file.ogg
mkisofs -o cd.iso -J -R /tmp/mycd
cdrecord -scanbusTo determine the x,y,z scsi coordinates of your cd writer. If it does not appear listed, it may be because the ide-scsi parameter was no passed to the Linux kernel (See the HOWTO about CD Writing).
To record, do:
cdrecord dev=x,y,z -multi speed=0 -data cd.iso
To record all the *.wav files in the current directory:
cdrecord dev=x,y,z -pad speed=0 -audio *.wav
(x,y,z must be replaced by the numbers returned by cdrecord -scanbus)
You can backup on CD-RW using the method described in section 17.
If you have a network connection, you can backup on a remote computer, provided it has enough free space on its disk.
I use unison, which keeps two directories synchronized, transfering only new or modified files:
unison localdir ssh://remotehost/remotedir
diff file1 file2
See also 'wdiff'
perl -pi.bak -e 's/OLDSTING/NEWSTRING/g' FILELIST # attention: to match words only, use s/\bOLDSTRING\b/NEWSTRING/g
It is sometime useful to run a command on many files. For example, to convert a series of eps files into jpg format:
for f in *.eps; do convert $f ${f/%.eps/.jpg}; done
Note that this is only valid if you are interacting with the shell 'Bash'.
If you use another shell (you can check the shell with the commadn 'echo $SHELL'), then you must type 'bash' first.
uname -a
When you enter commands on the command line in a terminal, the text you type is interpreted by a program called the 'shell'. There are different shells that speak different dialects. To determine the shell you are communicating with, type:
echo $SHELL
Commands that you type on the shell command line are searched in the directories listed in the PATH variable:
echo $PATH
When several directories contain a command with the same name (a bad situation), the first directory encountered in the PATH has priority. To find out the directory that contains the command that will be executed:
which command
To add a new directory 'newdir' to the PATH:
If the shell is sh or bash (check with echo $SHELL):
export PATH=thepath:$PATH
Place these lines in the file '.bashrc' in your home directory to have the correct PATH the next time you open a shell.
If the SHELL is tsch or csh:
set path = (newdir $path) rehash
Place these lines in the file '.cshrc' in your home directory, to have the correct PATH the next time you open a shell.
To compressing a single file:
gzip file
To decompress it:
gunzip file.gz
To compress a directory:
tar czf aga.tar.gz directory # compressing tar tzf aga.tar.gz # listing tar xf aga.tar directory # uncompressing
.zip files:
zip -r archivename directories files unzip -l archivename unzip archivename
A secure method to connect to a remote computer:
ssh computername
Note that the remote computer must be running a 'sshd' server. If you cannot connect using ssh, you can try the insecure commands:
rlogin computername telnet computername
Note that the login and password are sent in clear over the network.
ssh computername command rlogin computername command
See the documentations of ssh-keygen and ssh-agent.
In brief, on the local computer, run:
ssh-keygen -t rsa1
This generates, among other things, a public key (in a file .ssh/identity.pub) that you have to copy in the authorized_keys file in the .ssh directory of the remote computer.
To avoid typing the passphrase each time you log to the remote computer, copy the following lines in your .bash_profile:
eval `ssh-agent` ssh-add < /dev/null
You will be prompted for the passphrase only once: when you login on the local computer.
scp -r misc remotelogin@computername:
wget
ncftp
ypcat hosts
Cutting & pasting under linux is not always straigtfoward. This is due to the fact that there are various systems of cut'n paste cohabitating.
To copy text, the following works with most applications:
Note that this is very convenient: there no need to explicitly 'copy' the text.
If you use the window manager 'kde', there is a useful applet called 'klipper' located on the panel. Klipper keeps copies of the most recent clipboard contents. If a cut'n paste operation does not work, you may open klipper, select the relevant line, and retry to paste. It usually works.
If it does not work, then you can try the Cut/Copy/Paste functions from the applications' menus. Sometimes, it is necessary to save the region as a file in the first application, and insert this file in the second application.
You need to know IP, MASK, GATEWAY, DNS, HOSTNAME and DOMAIN:
ifconfig eth0 IP netmask MASK up route add -net default gw GATEWAY netmask 0.0.0.0 eth0 hostname HOSTNAME echo ``domain DOMAIN'' >/etc/resolv.conf echo "nameserver DNS" >>/etc/resolv.conf
mii-tool ethtool iperf
To run, some programs need to access functions in dynamic libraries. Dynamic libraries have the extension .so. They are located in /lib, /usr/lib, /usr/local/lib...
To list the libraries needed by a program:
ldd program
After adding new a new dynamic library, e.g. in /usr/local/lib, you must run, as superuser:
ldconfig -n /usr/local/lib
It is possible, as a user, to tell linux to search libraries in a particular place, using the LD_LIBRARY_PATH variable. For more information about how dynamic libraries are accessed, consult the manual of ld.so:
man ld.so
If it come as a .tar.gz and contain a configure script
tar xzf package.tar.gz cd package ./configure --prefix=$HOME & make & make install
This install the software in your home directory.
Linux tutorials for absolute beginner