Sie sind auf Seite 1von 40

Highly useful Linux commands & configurations

Oh, you're gonna love this article! Even though there are many websites hawking similar
content, with varying degree of clarity and quality, I want to offer a short, easy-to-use guide to
some of the most common yet highly useful commands that could help make your Linux
experience more joyful.
Now that you have read some of my installation guides, you have probably setup your system
and configured the basic settings. However, I'm positive that some of you must have encountered
certain difficulties - a missing package, a missing driver. The initial effort required of a Linux
novice can appear daunting, especially after many years of Windows discipline.
Therefore, this article was born, in order to offer simple solutions to some of the more
widespread problems that one might face during and immediately after a Linux installation. It is
intended for the beginner and intermediate users, who still feel slightly uncomfortable with
meddling in command line, scripts or configuration files.
This article will refer to Ubuntu Linux distribution as the demonstration platform. However, all
of these commands will work well with many other Linux distributions, with only small changes
in syntax, at most. I have personally tested and used all of the commands and configurations in
both Debian-based and RedHat-based distributions with success.

What am I going to write about?


Here are the topics. If you want to skip through some of the paragraphs, you can use the table of
contents further below, but I recommend you read everything.

Basic tips - avoiding classic mistakes.

Commands - an introduction to the command line.

Installation of software - including extraction of archives and compilation of sources.

Installation of drivers - including compilation, loading, configuration, and addition of


drivers to the bootup chain, writing of scripts and addition to the bootup chain.

Mounting of drives - including NTFS and FAT32 filesystems and read/write permissions.

Installation of graphic card drivers - including troubleshooting of stubborn common


problems.

Network sharing - how to access shared folders in Windows and Linux from one another.

Printer sharing - how to share printers in Windows and Linux from one another.

Some other useful commands.

Table of contents

1. Basic tips
2. Commands
1. Asking for help
3. Installation of software
1. What should you choose?
2. Discipline
3. Unpacking an archive
4. Zipped archives
5. Installation
6. Compilation (from sources)
7. Summary of installation procedures
4. Installation of drivers
1. Installation
2. Loading drivers
3. Configuration of drivers
4. Scripts
2

5. Mounting a drive
1. Other options
6. Installation of graphic card drivers
7. Network sharing
1. Windows > Linux
2. Linux > Windows
8. Printer sharing
9. Other useful commands
1. Switching between runlevels
2. Backing up the X Windows configuration file (useful before graphic drivers
update)
3. Display system environment information
4. Listing information about files and folders
5. Kill a process

Basic tips
There are some things you need to know before heading into the deep waters of the Command
Line:

Linux commands are cAse-sensitive (dedoimedo and Dedoimedo are two different files).

It is best to create folders and files in Linux WITHOUT spaces. For example: Red
Gemini.doc is a valid Windows filename, but you might have problems accessing it from
the command line in Linux; you should rename the file to RedGemini.doc. Users of the
DOS command line are also familiar with this problem - commands will fail on folders
and files with more than a single word, unless explicitly declared with double quotation
marks ("like this").

Pressing TAB when typing a command will auto-complete the command. For example: if
you have a single file in a certain folder that begins with the letter p, typing p then TAB
will automatically complete the name regardless of its length; if you have more than one
file, the command will complete the maximum available part of the string that matches
all relevant filenames (s + TAB for smirk and smile will auto-complete to smi).

Before copying, moving, deleting, or tweaking any file, especially scripts and
configuration files, it is best to back them up first.

Do NOT stop the commands while they are running (by pressing Ctrl + C). Even though
you may not see the HDD light blinking and the execution takes a very long time, do not
assume the system is frozen. Unlike Windows, Linux almost never gets stuck. Let the
command complete, be it 5 seconds or 5 hours. Just for reference, compilation of certain
programs can take a few days to complete.

Commands
To be able to use the command line, you need to be familiar with some rudimentary Linux
commands. Former users of DOS will find the transition very simple. Below you can find links
to some of the basic Linux commands:
Alphabetic Directory of Linux Commands
An A-Z Index of the Linux BASH command line
LinuxCommand.org
Some Useful Linux Commands

Asking for help

First, anything and everything you could ever probably think of has already been answered at
least once in a Linux forum; use the forums to find solutions to ... everything. Copy & paste your
error code / message into a search engine of your choosing (e.g. Google) and you will find links
to answers in 99.9996532% of cases.
Locally, help is one of the most useful features available to the command line user. If, for some
reason, you cannot figure out the syntax required to use the file, you can ask for help. There are
two ways of doing it:
man some_command
The above usage will display a full help file for the command in question in Vi text editor. You
can learn more about Vi from An Extremely Quick and Simple Introduction to the Vi Text Editor.
some_command --help
The above usage will display a summary of available options for the command in question,
inside the command line terminal. You will most likely prefer to use this second way.

Installation of software
Although most Linux distributions offer a wealth of useful programs, you will probably be
compelled to try new products. Some programs will be available for download via package
managers, like Synaptic. Others will only be found on the developer's site, most likely packaged
inside an archive.
You probably ask yourself: What now? The answer is very simple. There are three versions to
your downloads, from the easiest to hardest:
1. Compiled packages, usually with .rpm or .deb extension. These packages are identical to
Windows .exe installers and will unpack and install automatically. The upside of the
packages is the relative use of their deployment; the downside is that the user has no
control over the installation script.
2. Compiled archives, called tarballs, with .tar extension. These archives will contain all of
the necessary files required to make a program run, but the user will have to install them
manually, from the command line, after unpacking the archive. These archives will also
most likely be compressed and bear a double extension like tar.gz or tar.bz2. This option
offers more control during the installation.
3. Sources, usually archived. The user will have to unpack the archives and then compile the
sources before being able to actually install the program. In addition to better control of
the installation, the user will also benefit from software optimized to his hardware
configuration.

What should you choose?


5

The logical choice for the novice user should be 1 > 2 > 3. Intermediate users will probably try 2
> 3. Geeks will most likely ever only compile from sources.

Discipline
This may sound harsh or strict, but certain unspoken rules are followed, which simplifies the use
of software downloads.

The program itself will almost always be accompanied with a how-to, usually in a form
of a text file that explains what a user should do, prior, during and after the installation.
The how-tos are most often found on the site you download the software from, either as a
standalone file, an explanatory text on the download page or bundled with the download.

You should read this how-to FIRST before downloading / manipulating the software.

A secondary how-to will most often be packed with the program, explaining the
installation process itself.

You should read this how-to FIRST before installing the software.

Unpacking an archive
The exact syntax will differ from one package to another. But the general idea is the same for all.
The only difference will be in the arguments used for unpacking. Here are a few common
examples:
tar zxf some_software.tar.gz
tar -xjf some_software.tar.bz2
You can read in detail about the handling of tarballs on the Wikipedia site.

Zipped archives
Some archives will be zipped rather than tarred. This might put you off. But the problem is easily
solvable. If you recall, we have the ability to "ask" for help for each unknown command. In our
case, we need to know how to unzip an archive.
unzip --help
Here's a screenshot I took, depicting the very dilemma we are facing - and its solution:

A possible usage will then be:


unzip some_software.zip -d /tmp
Reading from the help screen above, we want to unpack our archive into a folder. The argument
-d tells us that the contents of the archive will be extracted into a destination directory (folder), in
our case a temporary folder called /tmp.

Installation
After unpacking the archive, you will now have to install the software. Usually, the installation is
invoked by using a script. The exact name of the script will vary from one program to another, as
well as its extension, depending on the language used to write it.
For example, the following command will invoke the script named install.pl (written in Perl).
Dot and trailing slash indicate that the script will be executed within the current directory.
./install.pl
7

Compilation (from sources)


Sometimes, the programs will not be compiled and ready to install. The archives will contain lots
of files with curious extensions like .c, .h and .o. If you are not a programmer, you should not
bother understanding what they are and what they do. Likewise, you need not understand how
the compilation of sources is made. You just need to remember three simple commands:
This first command will generates files required to build the software and setup system-wide
parameters.
./configure
This second command will build the libraries and applications.
make
This third command will install the libraries and applications.
make install
For homework, you could use some reading:
Compiling and installing software from source in Linux
There is no guarantee that the compilation will succeed. Some sources are broken! In that case,
you should make note of the errors and post them in relevant forums, where you are most likely
to find an answer rather quickly.

Summary of installation procedures


To make things easier to understand, below are two examples showing the list of necessary
commands required to run to successfully install a downloaded application (please note these are
ONLY examples!). Most likely, you will need root privileges (su or sudo) to be able to install
software. An archive containing compiled program:
tar zxf some_software.tar.gz
OR
tar -xjf some_software.tar.bz2
cd some_software_directory
./install_script
An archive containing sources:

tar zxf some_software.tar.gz


OR
tar -xjf some_software.tar.bz2
cd some_software_directory
./configure
make
make install

Installation of drivers
Drivers are programs, like any software. The only difference is - you do not actively use them.
They serve the purpose of making your hardware components understand each other. As simple
as that. You need them to enhance your usage of the operating system.
Most often, the necessary drivers will be included with the distribution and installed during the
setup. Sometimes, you might not be so lucky and will reach a newly installed desktop without
sound, network or video drivers.
I will not go into details explaining how specific drivers are installed. You should contact your
vendors for that information. I will explain how to install the drivers, how to load them, and then
how to add them to startup, so they will load automatically every time your machine starts.

Installation
Just like any software, drivers may be compiled or not. Most often, they will not be. Drivers will
usually be distributed as sources, in order to achieve maximal possible compatibility with the
hardware on the installation platform. This means you will have to compile from sources. Piece
of cake. We already know how to do that.
If the vendor is benevolent, it is possible that the driver will be accompanied with a selfinstallation script. In other words, you will need to run only one command, which will in turn
extract the archive, compile, install, and load it. But this might not be the case - or might not
even work. I have personally witnessed a driver self-installation script go wrong. Therefore, for
all practical purposes, you should probably manually install the driver.
After successfully extracting the archive and compiling the sources (./configure, make, make
install), you will most likely be faced with three choices:

The driver will be fully configured and copied to default directories and the system paths
updated. You will not need do anything special to use the driver.

The driver will be auto-configured and the system paths updated. This means you will
only have to add the driver name to the list of drivers loaded during the boot to enable it
every time the machine starts.
9

The driver will be ready to use, but will not be configured nor system paths updated. You
will have to manually load the driver and then update the list of drivers loaded during the
boot to enable it every time the machine starts.

The second option will make the installation process probably look like this:
tar zxf some_driver.tar.gz
OR
tar -xjf some_driver.tar.bz2
cd some_driver_directory
./configure
make
make install
Optional
./setup_driver_script
All that remains is to add this driver to the list of drivers loaded at bootup. In Linux, the drivers
are often referred to as modules.
You need to open the configuration file containing the list of modules. You should refer to your
specific distribution for exact name and location of this file. In Ubuntu, the file is called
modules.conf and is found in /etc directory (/etc/modules.conf). We will update this file, but first
we will back it up! Please remember that you need root privileges to meddle with the
configuration files.
This is what our procedure would look like:
cp /etc/modules.conf /etc/modules.conf.bak
gedit /etc/modules.conf
The above commands will open the file modules.conf inside the gedit text editor. Simply add
your driver in an empty line below the existing drivers, save the file, exit the text editor, and
reboot for the change to take effect. That's all!
Here's an example of a modules.conf file for a Kubuntu Linux, installed as a virtual machine. To
add a new driver, we would simply write its name below the existing entries. Of course, you
need to know the EXACT name of the driver in question.

10

The third option is a bit more complex.

Loading drivers
You have successfully compiled the driver, but nothing has happened yet. This is because the
driver is not yet enabled. Looking inside the directory, you will notice a file with .ko extension.
This is your driver and you need to manually load it.
We need to install the driver into the kernel. This can be done using the insmod command.
cd driver_directory
insmod driver.ko
After the driver is loaded, it can be configured. To verify that the driver is indeed present, you
can list all the available modules:
lsmod
If by some chance you have made a terrible mistake and you wish to remove the driver, you can
use the rmmod command:
rmmod
11

Configuration of drivers
Configuring the driver requires a bit of knowledge into its functionality. Most often, instructions
will be included in the how-to text files.
Below, the example demonstrates how the network card is configured after the network driver is
loaded. The network card is assigned an identifier and an IP address. In this particular case, eth0
was the selected device name, although it could be also eth1, eth2 or any the name. The assigned
IP address tells us the machine will be part of a LAN network.
ifconfig eth0 192.168.0.9
After a reboot, you will realize that you no longer enjoy a network connection. This is because
your driver has not been created in a common default directory and the system does not know
where to look for it. You will have to repeat the entire procedure again:
cd driver_directory
insmod driver.ko
ifconfig eth0 192.168.0.9
You now realize that an automated script would be an excellent idea for solving this problem.
This is exactly what we're going to do - write a script and add it to bootup.

Scripts
Like in DOS and Windows, scripts can be written in any text editor. However, special changes
are needed to separate between text files and scripts. In the Windows department, simply
renaming the .txt extension to .bat will convert the file to a script. In Linux, things are a bit
different.
Linux command line lives inside a shell - or more precisely Shell. There are several Shells, each
with a unique set of commands. The most common (and default) Linux Shell is the BASH. We
need to add this information to our script, if we wish to make it communicate with our Shell.
Therefore, the above commands + Shell addition will make the following script:
#!/bin/bash
cd driver_directory
insmod driver.ko
ifconfig eth0 192.168.0.9
We can also make it shorter:
#!/bin/bash

12

insmod /home/roger/driver_directory/driver.ko
ifconfig eth0 192.168.0.9
Now, we have a script. Or rather a text file that contains the relevant commands. We need to
make it into an executable file. First, we need to save the file. Let's call it network_script. To
make the script executable:
chmod +x network_script
Now we have a real script. We need to place it in the /etc/init.d directory so that it will be run
during bootup.
cp network_script /etc/init.d/
And finally, we need to update the system, so it will take our script into consideration.
update-rc.d network_script defaults
After you reboot, you will realize that your driver loads automatically and that your network card
is configured! Alternatively, it is possible that the make install of the driver will place in the
default directory:
/lib/modules/<KERNEL VERSION>/kernel/drivers/net/driver.ko
Or you could place the driver in this directory by yourself. This way, you will be able to avoid
the step of writing the script. However, my method, even if not the most elegant one, has one
advantage: Drivers that you have manually compiled and placed into the default directories will
be lost every time you update the kernel. This means you will have to reinstall them again after
every such update. My method un-elegantly escapes this problem.

Mounting a drive
If you run a dual-boot system, it is entirely possible that you have installed your Linux before
you have formatted all the Windows drives. This means that some of these drives might not be
mounted - or accessible - when you're booted in Linux. Alternatively, you might have formatted
the drives, but you have resized and relettered and renamed the partitions and they are no longer
recognized by Linux. Furthermore, you just might be unlucky and your Linux refuses to see the
drives despite your best efforts. Finally, you might be able to see them, but you cannot write to
the NTFS drives and this irks you so. Compared to the above tasks, mounting drives is a simple
job.
To be able to do this correctly, you need to know how your drives are ordered and what they are
called, both in Windows and Linux. This requires that you be able to correlate between Windows
partitions (E:\, G:\, K:\ etc.) and Linux partitions (hda1, hda4, hdb2 etc.).

13

First, make sure you know the order of your partitions in Windows. Then, when booted in Linux,
list the Partition Tables:
fdisk -l
The above command will display all the available partitions on your system. In this example, you
see only the Linux partitions present, but there might be other (Windows) partitions.

For the sake of this exercise, let's assume that Linux partitions are hda4-6, while Windows
partitions are hda1-3.
Namely:

hda1 will be Windows C:\ drive.

hda2 will be Windows F:\ drive - also called Data.

hda3 will be Windows G:\ drive - also called Games.

hda4 will be Linux swap / Solaris.


14

hda5 will be Linux (your /root).

hda6 will be Linux (your /home).

Now, before you mount a drive, you need to create a mount point. This is most conveniently
done by assigned a directory within the /media directory. For example:
mkdir /media/data
The name data is arbitrary, but it can help relate the mounted drive to its Windows designation.
Now, we need to mount the drive that corresponds to data. In our case, this is hda2.
There are several ways of mounting the drive. By default, NTFS partitions are mounted as readonly, although write access can also be enabled. FAT32 partitions are writable by default.
Like before, mounting the drive only once will hold valid for the current session. After reboot,
the changes will be lost. Therefore, we need to add the mounting of the relevant partitions to the
boot chain. The configuration file that holds this crucial information is called fstab and is located
under /etc (/etc/fstab).
Therefore, in order to mount the NTFS drive (Windows F:\ drive called data) as read-only we
need to:

Create a directory called data within /media.

Backup fstab.

Add a new line to the fstab file - that will mount the NTFS drive hda2 (Windows F:\ data) as read-only.

mkdir /media/data
cp /etc/fstab /etc/fstab.bak
gedit /etc/fstab
After opening the file in the text editor, we need to add the mount command. NTFS read-only:
/dev/hda2 /media/data ntfs nls=utf8,umask=0222 0 0
The necessary commands, as well as procedures are well-documented in the Unofficial Ubuntu
6.10 (Edgy Eft) Starter Guide. Here, you can see the sample fstab file inside Kate text editor, for
Kubuntu Linux.

15

Other options
Alternatively, if you have partitions formatted with FAT32 file system or you wish to be able to
write to NTFS partitions from within Linux, you can use the following commands:
FAT32 read/write:
/dev/hda2 /media/data vfat iocharset=utf8,umask=000 0 0
NTFS read/write - requires installation of software that can write to NTFS drives.
apt-get install ntfs-3g
/dev/hda1 /media/data ntfs-3g defaults,locale=en_US.utf8 0 0
An exercise: Let's assume we wish to be able to write to NTFS partition C, read-only NTFS
partition F and use FAT32 partition G. In that case, the list of commands that we need to execute
is:
apt-get install ntfs-3g
mkdir /media/windows
mkdir /media/data
16

mkdir /media/games
cp /etc/fstab /etc/fstab.bak
gedit /etc/fstab
ADD FOLLOWING LINES TO FSTAB
/dev/hda1 /media/windows ntfs-3g defaults,locale=en_US.utf8 0 0
/dev/hda2 /media/data ntfs nls=utf8,umask=0222 0 0
/dev/hda3 /media/games vfat iocharset=utf8,umask=000 0 0

Installation of graphic card drivers


Please note that commands used in this subsection are for Nvidia drivers ONLY - I have several
computers, ALL of which have Nvidia graphic cards - but some of the solutions presented work
for both Nvidia and ATI cards.
Although I have already discussed the installation of graphic card drivers in my Installing SUSE
Linux and Installing Kubuntu Linux articles, I think a bit of extra guidance will not hurt anyone.
Basically, you can install the graphic card drivers using a Package Manager or via the command
line. For most people, the first method should work flawlessly. The first method is embodied in
these two commands - the download of the required package and the installation of the driver:
apt-get install nvidia-glx
nvidia-glx-config enable
Some people might prefer to install the drivers manually, with the X Windows stopped. To do
this, you literally need to stop the desktop from running.
/etc/init.d/gdm stop
OR
/etc/init.d/kdm stop
OR
/etc/init.d/xdm stop
The desktop should vanish and be replaced with a command line. You will probably need to
login. It is possible that you will only see a black screen and no command prompt. Do not be
alarmed! Linux operating system usually has 7 virtual consoles. The first six consoles provide a
text terminal with a login prompt to a UNIX shell. The 7th virtual console is used to start the X
Windows.
In other words, it may occur that by stopping the X Windows you will have simply switched off
the graphics AND remain in the 7th virtual console, therefore having no command line to work
with. All you need to do is switch to one of the text consoles by pressing Alt + F1-6 on the
keyboard. Now, you need to install your driver:
17

sh NVIDIA-<DRIVER VERSION>.run
After the installation is complete, you should simply restart the X Windows.
/etc/init.d/gdm start
OR
/etc/init.d/kdm start
OR
/etc/init.d/xdm start
If you see an Nvidia splash logo, it means the driver has been successfully installed. Reboot your
machine just to make sure. This is where you might encounter a problem.
Instead of the Nvidia logo, you will see an error message indicating that the X Server has been
disabled and that you need to manually edit the settings in the xorg.conf file before being able to
proceed to the desktop. Now, there are many possible reasons for such an error and trying to
provide a general solution is impossible.
However, I have found the following argument to hold true for many cases: If you have setup
your Linux distribution using the GUI installer, you will have probably used the default
configurations and the generic kernel will have been installed. I this case, sometimes, the built-in
Nvidia driver (nv) might interrupt with the installation. There are two methods for solving this
problem.
Method 1: Alberto Milone's envy package
Envy is a command-line application that will download the latest drivers for your card, clean up
old drivers and install the new ones. Instructions for the usage can be found below the download
links.
Method 2: Do it yourself
First, download the required driver. Then, execute the following commands:
The offending built-in driver needs to be disabled.
gedit /etc/default/linux-restricted-modules-common
Change the last line to DISABLED_MODULES="nv". This will prevent the built-in driver from
loading and interrupting with your own installed driver.

18

Now, you should remove all conflicting files from your system:
apt-get install linux-headers-`uname -r` build-essential gcc gcc-3.4 xserver-xorg-dev
apt-get --purge remove nvidia-glx nvidia-settings nvidia-kernel-common
rm /etc/init.d/nvidia-*
After the offenders are removed, you should install the drivers from the command line:
/etc/init.d/gdm stop
sh NVIDIA-<DRIVER VERSION>.run
nvidia-xconfig --add-argb-glx-visuals
/etc/init.d/gdm start
Again, you should see the Nvidia splash logo. Reboot just to make sure there are no more
surprises. This should get you up and running with the latest graphic card driver.

19

Network sharing
If you have more than one computer, you are probably sharing resources among them.There is no
reason why you should not continue doing this if one of the machines is running a Linux
distribution. Sharing can be accomplished in many ways. Perhaps the simplest is using Samba
server. First, install Samba:
apt-get install samba
After the Samba server is installed, you will need to edit a few options in the configuration file to
allow sharing privileges.
cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
gedit /etc/samba/smb.conf
In the configuration file, you will need to setup a number of parameters:

workgroup = workgroup_name - the name of the Workgroup for your LAN (e.g. HOME)

netbios name = netbios_name - without spaces; computer alias by which you will be able
to call it across the network

security = user

After saving the configuration file, you will have to restart the Samba server:
/etc/init.d/samba restart
Now, select a folder that you wish to share.

20

If you have ticked the option Writable, you will be able to modify the contents of this
folder. Finally, to be able to connect to this share from Windows, you will have to create a Samba
user:
smbpasswd -a 'name'
Under 'name' you should specify an existing UNIX user (e.g. roger). Do not forget the
apostrophes! You will be asked to create a password. And finally, restart the Samba server again,
for the changes to take effect. Now, the sharing itself. Very simple.

Windows > Linux


Start > Run > \\xxx.xxx.xxx.xxx OR \\netbios_name
When asked for username and password, provide the Samba user name, e.g. roger and the
relevant password. And that's it. Browse to the shared folder. If the shared folder is writable, you
will be able to modify the contents.

Linux > Windows

21

Press Alt + F2. This will bring up the Run Command window. In the Command line, specify the
IP address or the name of the computer that you wish to connect. You can see an example below:

And that's it. Easy peasy lemon squeasy!

Printer sharing
Well now, folder and file sharing is really easy. What about the printers? Again, it is very simple.
If you have a printer installed on a Windows machine, accessing it from a Linux machine will be
easy. The rougher side of the coin is accessing a printer installed on a Linux machine from a
Windows machine.First, you will have to allow your printer to be shared. Backup and then edit
the Common UNIX Printer System configuration file.
cp /etc/cups/cupds.conf /etc/cups/cupsd.conf.bak
gedit /etc/cups/cupsd.conf
In the file, search for the entry #Listen 127.0.0.1:631 and add or change as follows:
#Listen 127.0.0.1:631 OR localhost:631
xxx.xxx.xxx.xxx:631 OR *:631
Listen /var/run/cups/cups.sock
CUPS listens on the port 631. If you use a static IP address for the Linux machine, you can
specify only that IP. Otherwise, you might need to use a wildcard. Of course, you should be
aware that an open port means a wee less security than before, so keep that in mind. After saving
the changes, you will have to restart CUPS:
/etc/init.d/cupsys restart
Now that the printer is available, you will have to add it for the Windows machine.
Start > Settings > Printers and Faxes
File > Add Printer
22

... A network printer, or a printer attached to another computer ...


... Connect to a printer on the Internet or on a home or office network ...
http://xxx.xxx.xxx.xxx:631/printers/printer_name
OR
http://netbios_name:631/printers/printer_name
When prompted for the driver, either select from a list or install it from a disk (like CD). And
that's it! You can now print from a Windows machine on a printer connected to a Linux machine.
Tip: If you are using a Lexmark printer, you will probably not be able to find the right Linux
drivers for your printer. Worry not! Using generic drivers for Hewlett Packard printers will work
remarkably well.

Other useful commands


Here's a tiny sampling of some other useful tools that you might want to know. Be aware that the
commands are presented in a generic way only. A variety of options (switches) can be used in
conjunction with many of the commands to make their usage far more complex and effective.

Switching between runlevels


init 0-6
OR
telinit 0-6

Backing up the X Windows configuration file


cp /etc/X11/xorg.conf /etc/X11/xorg.conf.bak
Sometimes, you may need or want to configure the X Windows manually:
dpkg-reconfigure xserver-xorg

Display system environment information


You can use the cat (concatenate) command, which will print the contents of the files into the
terminal. To display the CPU parameters:
cat /proc/cpuinfo
To display the memory parameters:

23

cat /proc/meminfo
To find the version of your kernel and the GCC compiler:
cat /proc/version
Furthermore, to find out the version of your kernel:
uname -r

Listing information about files and folders


This command is the equivalent of the DOS dir command.
ls
To display hidden files as well (starting with dot).
ls -a

Kill a process

Sometimes, you may start an application ... only it does not really start. So
you try again. But this time, your distro informs you that the process is already running. This can
also happen in Windows. Sometimes, processes remain open and need to be killed. Before you
can kill a process, you need to know its ID. The command below will list all running processes:
ps -elf
Then, kill the offending process by its ID.
kill PID
Alternatively, you can kill a process by its name. The below command will terminate all
processes with the corresponding name (or names).
killall process_name

Conclusion Well, that's it, for now. Hopefully you have learned something.
If you have had problems with your software installations, compilation from sources, drivers,
partitions, and sharing, this article may have helped you overcome some of the problems.
Personally, the above tips cover about 90% of tasks that a normal user would have to confront as
a part of his/her daily usage. Isn't Linux so much fun? Well, have fun tweaking.
P.S. If you find this article useful, please support Dedoimedo.

24

A collection of useful commands I've picked up over time (history | grep X). Understanding the
purpose of each parameter is left to the reader - note typing '/' in man lets you search for specific
terms in the manual page. Note that these commands have all been tested on an Ubuntu
installation, and with the exception of package management they should work universally. Many
commands require extra permissions and start with "sudo" - take extra caution when using these.
I update this page pretty frequently. Always lots to learn! :)
Index of commands:

aspell (command line spell checking)

apt/dpkg (package management, software installation)

cp/mv/rm (copy, move, delete files)

dd (clone a hard drive, backup drive to file)

df/du/find (drive usage)

ffmpeg (video transcoding, desktop recording, etc.)

gcc (creating software programs)

git (revision control system)

grep (search files for strings)

locate (search for files/directories)

man (software documentation)

mount (enabling access to drives/filesystems)

rsync (backups)

ssh (log into another machine)

tar/gzip (archive, compress)

Other stuff:

blacklisted nvidia_experimental_310 issue

copy/pasting into the terminal

filesystem mounting options for a solid state drive


25

using udisks and gnome-session-properties to automount partitions on login

changing file ownership on a USB drive not formatted to FAT32

getting multi-monitor settings with nvidia-settings to stick after reboot

removing overlay-scrollbar from default Ubuntu installation

fixing the fontconfig warning when running applications

setting up an environment for making documents with TeXworks and LaTeX

switching between qt4 and qt5 with qtchooser

open a terminal through nautilus

youtube issues with chromium

hostnames, avahi and .local

linker errors using webkitwidgets

convert a PDF into a series of images

remove cached startup errors

digitally sign a PDF

s3cmd - Manage Amazon S3 buckets (webhosting)

aspell (command line spell checking)

Spell check an input file:


aspell -c sample.tex

Spell check an input file (do not create backup file):


aspell -dont-backup -c sample.tex

Show personal dictionary (note: the first one does not work on Ubuntu,
alternate provided):
aspell dump personal
sudo updatedb
locate .aspell*
cat ~/.aspell.en.pws

26

Show aspell configuration:


aspell dump config

apt/dpkg (package management, software installation)

Add a package:
sudo apt-get install package_name

Remove a package:
sudo apt-get remove package_name

Add repository:
sudo apt-add-repository ppa:sample_ppa/sample

Search packages:
sudo apt-get update
apt-cache search search_term

List installed packages:


dpkg -l

List files and directories of an installed package:


dpkg -L package_name

cp/mv/rm (copy, move, delete files)

Copy a file:
cp /example/file1 /example/file2

Copy a directory (dir1 into dir2):


cp -a /example/dir1 /example/dir2

Move a file:
mv /example/file1 /example/file2

Delete a file:
rm /example/file1

Delete a directory (be careful):


27

rm -rf /example/dir

dd (clone a hard drive, backup drive to file)

List drives and partitions:


sudo fdisk -l

Clone a drive (note: drive /dev/sdb must have size greater than or equal to
/dev/sda):
sudo dd if=/dev/sda of=/dev/sdb

Clone drive to a file (note: output file location should not be on any partition
of /dev/sda):
sudo dd if=/dev/sda of=/home/sda_as_backup_file

Report progress (sends signal to dd every 10 seconds):


ps au | grep dd
sudo watch -n 10 "kill -USR1 processid"

List partition UUIDs:


sudo blkid

Modify partition UUID (if ext2/3/4, device is e.g. /dev/sda1):


tune2fs -U random /dev/sda1

df/du/find (drive usage)

Report usage for all mounted drives:


df -h

Show sorted usage of directories at root:


sudo du -hsx /* | sort -n

List files bigger than 100 MB:


find -size +100M -ls

ffmpeg (video transcoding, desktop recording, etc.)

Record desktop (at 24 fps, 1920x1080 resolution, on screen 0, using mpeg4):


ffmpeg -f x11grab -y -r 24 -s 1920x1080 -i :0+0,0 -vcodec mpeg4 -sameq
sample_out.mp4

28

Record desktop (400x400 portion of desktop at offset 200x200 on screen 1):


ffmpeg -f x11grab -y -r 24 -s 400x400 -i :1+200,200 -vcodec mpeg4 -sameq
sample_out.mp4

Record webcam/microphone:
ffmpeg -f alsa -ac 2 -i hw:0 -i /dev/video0 -acodec ac3 -ab 128k -vcodec
mpeg4 -sameq -r 24 sample_out.mp4

Transcode video (and resize):


ffmpeg -i sample.mp4 -sameq -s hd720 sample_720.mp4

Transcode audio only:


ffmpeg -i sample.mp4 -vcodec copy -acodec aac -sameq sample_out.mp4

Speed up video:
ffmpeg -i sample.mp4 -vf "setpts=0.05*PTS" -r 25 -s hd720 -sameq
sample_out.mp4

Rotate video 90 degrees clockwise:


ffmpeg -i sample.mp4 -vf "transpose=1" -sameq sample_out.mp4

Rotate video 90 degrees counter-clockwise:


ffmpeg -i sample.mp4 -vf "transpose=2" -sameq sample_out.mp4

Video overlay:
ffmpeg -i sample.mp4 -aspect 4:3 -vf "movie=overlay.png [logo]; [in]
[logo] overlay=0:0:1" -sameq sample_out.mp4

Images to video:
ffmpeg -r 1 -i dgplogo%01d_1080.png -sameq sample_out.mp4

Merge videos (not supported by all formats):


ffmpeg -i "concat:sample1.avi|sample2.avi" -vcodec copy -acodec copy
sample_out.mp4

gcc (creating software programs)

Compile object file(s):

29

gcc -c sample.c -o sample.o

Create static library (.a):


ar crs libsample.a sample.o

Create shared library (.so):


gcc -shared -o libsample.so sample.o

Linking a static library (creates executable program "test_static"):


gcc -static test.c -L. -lsample -o test_static

Linking a shared library (creates executable program "test_shared"):


gcc test.c -L. -lsample -o test_shared

Add shared library path:


(General) Append path to /etc/ld.so.conf
(Ubuntu) Append path to /etc/ld.so.conf.d/.conf

Update shared library paths:


sudo ldconfig

Add shared library path temporarily to run executable:


#!/bin/bash
LD_LIBRARY_PATH=/directory/for/libs/:$LD_LIBRARY_PATH
echo 'looking for shared libraries here first' $LD_LIBRARY_PATH
/path/to/executable

View shared libraries needed by executable, and paths to files linked at


runtime:
ldd /path/to/executable

Output assembly code (extension is .s):


gcc -S -c sample.c

git (revision control system)


Configure username and email (globally), and set merge tool:
git config --global user.name "My Name"
git config --global user.email "example@email.ca"

30

git config merge.tool kdiff3

Copy remote repository contents locally:


git clone https://github.com/Example/repo.git

Add and show remote repository (call it "upstream"):


git remote add upstream https://github.com/Example/repo.git
git remote -v

See history of repository ("upstream"):


git log upstream

Show details of last commit:


git show

Show remote branches (fetch updates local list):


git fetch
git branch -r

Show local branches:


git branch

Delete local branch:


git branch -D branch_name

Add files to be committed:


git add /path/to/files

Upload all local changes to master branch of remote repository "origin":


git commit -a -m'made some changes'
git push origin master

Merge pull request:


git pull upstream master

Stash local changes (to pull):


git stash

31

Merge another branch to active branch (note this auto-commits):


git merge origin/some_branch

Show merge conflicts:


git status

Resolve merge conflicts:


git mergetool

Revert all local changes to previous commit:


git reset --hard commit_hash_value

Create a new branch:


git branch new_branch

Switch to work on other branch:


git checkout new_branch

grep (search files for strings)


Search file for string:
grep search_string filename

Output line numbers where search string is found:


grep -n search_string filename

Display filenames containing search string:


grep -l search_string filenames*

locate (search for files/directories)

Search:
locate 'search_term1 search_term2'

Search (case insensitive):


locate -i search_term

Update filesystem database:


32

sudo updatedb

Find locations of program executable/source/documentation:


whereis program_name

Locate a command:
which program_name

man (software documentation)

View manual page:


man program_name

Search manual pages for keyword:


man -k keyword
apropos keyword

mount (enabling access to drives/filesystems)

List mounted drives:


mount

Mount a device (SATA drive 1, /media/drivedir must exist):


sudo mkdir /media/drivedir
sudo mount /dev/sda1 /media/drivedir

Unmount device:
sudo umount /media/drivedir

rsync (backups)

Back up a directory:
rsync -av source_path dest_path

Back up a directory and exclude files/directories:


rsync -av --delete-excluded --ignore-errors --exclude=*.gvfs*
--exclude='.local' source_path dest_path

Creating a backup script:


#!/bin/bash
echo "Backing up..."
# may want to mount drive for source/dest paths first here
rsync -av source_path dest_path

33

chmod 744 ./backup.sh

Set ownership of dest path (e.g. if new partition owned by 'root'):


chown james:james /media/james/Drive -R

ssh (log into another machine)

Connect to server using ssh:


ssh username@server_address

Create public/private key (RSA):


ssh-keygen -t rsa

List keys loaded:


ssh-add -l

Add a new key:


ssh-add /path/to/private_key

Print key fingerprint:


ssh-keygen -lf /path/to/key

tar/gzip (archive, compress)

Create archive of directory and compress:


tar -czvf file.tar.gz /path/to/compress/

Extract archive:
tar -xvf file.tar.gz

Compress single file:


gzip input_file

Uncompress single file:


gunzip input_file.gz

On getting nvidia_experimental_310 to work:

I had issues getting the nvidia_experimental_310 package working. It turned out there was a
"nvidia_experimental_310" entry in a file "/etc/modprobe.d/blacklist-local.conf" causing the
trouble. How and why that got there I may never know. Commands I tried to track down this
problem and my path to a solution:

34

Show loaded modules (with 'nvidia' in name):


lsmod | grep nvidia

Not loaded. Show errors in X.org log:


cat /var/log/Xorg.0.log | grep '(EE)'

Error found, suggests checking kernel log:

[ 10.865] (EE) NVIDIA: Failed to load the NVIDIA kernel module. Please check your
[ 10.865] (EE) NVIDIA: system's kernel log for additional error messages.
[ 10.865] (EE) Failed to load module "nvidia" (module-specific error, 0)
Show kernel log (and view in 'less'):
cat /var/log/kern.log | less

Last entry shows it trying to load nvidia module? Not very helpful unfortunately.

Show all nvidia kernel objects:


locate *.ko | grep nvidia

...
/lib/modules/3.5.0-21-generic/updates/dkms/nvidia_experimental_310.ko

Existence of the kernel object for the current version of the kernel I'm running (uname -r) is
encouraging as it means when installing the nvidia_experimental_310 package it compiled OK.
Let's try to link it into the kernel again ourselves.
Load a module (in this case, 'nvidia_experimental_310'):
sudo modprobe nvidia_experimental_310

modprobe: WARNING: Not loading blacklisted module nvidia_experimental_310

Blacklisted? Huh?
Search all blacklisted modules (whose name contains 'nvidia'):
cat /etc/modprobe.d/blacklist* | grep nvidia

blacklist nvidiafb
blacklist nvidia_experimental_310

Aha! After removing blacklist-local.conf which contained the above entry, I tried again.
Load a module, then restart display manager:
sudo modprobe nvidia_experimental_310
sudo service restart lightdm

Working well!
35

copy/pasting into the terminal:

"Control-Shift-V" pastes text directly into the terminal, avoiding the need to right click and
choose "Paste" each time.
filesystem mounting options for a solid state drive:

You can edit "fstab" (the file system table) by doing the following:
gksudo gedit /etc/fstab

To identify which is the SSD:


blkid

Listing all partition information can be helpful to identify the drive:


sudo fdisk -l

Under "options" in the fstab, for the SSD, adding discard adds TRIM support,
adding noatime, nodiratime disables extra writes to keep track of when files and
directories were last accessed. For instance if the SSD line in fstab is:
UUID=03f7d0a1-2fcb-4878-afef-8487799df4a4 / ext4 errors=remount-ro 0 1

Change it to the following, using commas to separate each option:


UUID=03f7d0a1-2fcb-4878-afef-8487799df4a4 / ext4
discard,noatime,nodiratime,errors=remount-ro 0 1

Do not forget to save and restart.

using udisks and gnome-session-properties to automount partitions on login:


The easiest way to set up automatic mounting is using the gnome-disks tool, and
choosing "Edit mount options...". The next easiest way is by running gnomesession-properties and add the following command:
/usr/bin/udisks --mount /dev/sdb1

where "/dev/sdb1" the partition you wish to mount. Using a UUID is preferred in case
drives get switched around, to view partition UUIDs use:
blkid

Given the UUID of the partition, change the udisks command parameters to:
/usr/bin/udisks --mount /dev/disk/by-uuid/1234567890ABCD

Or, one can edit the filesystem table file (/etc/fstab).

changing file ownership on a USB drive not formatted to FAT32:


The drive will not allow you to write to it since you are not the owner of files on that
filesystem (the root account is). Chances are, while FAT* does not support the
concept of user ownership, the existing filesystem does (e.g. ext4), causing the
problem. Use the "chown" command to change the ownership to your account. With
the drive mounted, do:
36

sudo chown james /media/james/kingston32gb

This changes the files mounted to /media/james/kingston32gb to be owned by user


james. You will then be able to both read and write files to the device.
getting multi-monitor settings with nvidia-settings to stick after reboot:
I had an issue with three display devices having their positions reset every reboot
(two standard monitors, plus an Oculus Rift). The Oculus Rift would always be reset
to be positioned between the two monitors. Using nvidia-settings and saving to
/etc/X11/xorg.conf never seemed to work. Bring up a terminal and run:
gksudo nvidia-settings

Set the desired display configuration. Then, save xorg.conf configuration settings to:
/usr/share/X11/xorg.conf.d/xorg.conf

You may notice when browsing the directory /usr/share/X11/xorg.conf.d/ that a file
xorg.conf.backup was instead saved. You can copy or rename this file using gksudo
nautilus using a GUI, or use the terminal command
cd /usr/share/X11/xorg.conf.d/
sudo cp xorg.conf.backup xorg.conf

On restart, the monitor settings should be remembered! (Tested on Ubuntu 13.04.)


removing overlay-scrollbar from default Ubuntu installation:
The selection zone to bring up the overlay scrollbar I have issues with. It appears
when the cursor is over the left side of the window edge, but is displayed on the
right. When moving the cursor to the right to manipulate the control, it often
disappears - I find this frustrating.

Fortunately, it is easy to disable the "overlay scrollbars". On Ubuntu 12.04:


gsettings set org.gnome.desktop.interface ubuntu-overlay-scrollbars false

and to bring them back:

gsettings reset org.gnome.desktop.interface ubuntu-overlay-scrollbars

For Ubuntu 12.10 and 13.04, to disable them:

gsettings set com.canonical.desktop.interface scrollbar-mode normal

and to bring them back:

gsettings reset com.canonical.desktop.interface scrollbar-mode

The command should take effect immediately. Previously, I removed the package
using "sudo apt-get remove overlay-scrollbar". While that worked, warnings would
appear about the missing "overlay-scrollbar" GTK module when running
applications.
fixing the fontconfig warning when running applications:

37

When running my Qt applications, under application output I would always see the
message: Fontconfig warning: "/etc/fonts/conf.d/50-user.conf", line 9: reading
configurations from ~/.fonts.conf is deprecated. This can be fixed by doing the
following:
mkdir ~/.config/fontconfig
mv ~/.fonts.conf ~/.config/fontconfig/fonts.conf

The change should take effect immediately -- applications will no longer complain
about it. (Tested on Ubuntu 13.04.)
setting up an environment for making documents with TeXworks and LaTeX:
On a new Ubuntu installation, to produce academic papers I install TeXworks
software, the latexmk script, and some LaTeX packages, using the following:
sudo apt-get install texworks latexmk texlive-latex-recommended texlive-latexextra

In TeXworks, Edit>Preferences>Typesetting. Add latexmk processing tool with the


program usr/bin/latexmk and the following command line arguments:
-e
$pdflatex=q/pdflatex $synctexoption %O %S/
-pdf
$fullname

Check "view PDF after running", press OK. For default - set to latexmk.

switching between qt4 and qt5 with qtchooser:


I reinstalled Ubuntu 13.04 on a machine (comes with qt4) overtop a 13.10
installation (comes with qt5). I found when building through qtcreator that there
were errors in relation to using the qt5 libraries rather than qt4. The program
"qmake" is a symlink to the program "qtchooser", which was configured to use qt5.
To set it back to qt4, the /usr/share/default.conf symlink needs to point to qt4.conf:
cd /usr/share/qtchooser
sudo rm default.conf
sudo ln -s qt4.conf default.conf

open a terminal through nautilus:

Use the following command to install the extension:


sudo apt-get install nautilus-open-terminal

youtube issues with chromium:

On an Ubuntu 12.04 installation with chromium, youtube videos often fail to load
with the message "This video is currently unavailable". The fix (in my case):
sudo apt-get remove chromium-codecs-ffmpeg
sudo apt-get install chromium-codecs-ffmpeg-extra

hostnames, avahi and .local:

38

You may find you are unable to connect using the hostname to another computer on
the network (e.g. for a computer whose hostname is "whirringbox"):
ping whirringbox
ping: unknown host whirringbox

Ubuntu (and others) include software called avahi, "zero-configuration networking


software" which includes support for something called mDNS (or the "multicast
Domain Name System"). On Ubuntu installations, there will be a program called
avahi-daemon running. For example, if we run on whirringbox:
ps -ax | grep avahi

this displays
684 ?
687 ?
8350 pts/0

S
S
S+

0:00 avahi-daemon: running [whirringbox.local]


0:00 avahi-daemon: chroot helper
0:00 grep --color=auto avahi

The purpose of the avahi-daemon process is to make the computer accessible on


the local network. Supporting mDNS, avahi-daemon waits for a message on the
local network requesting the host with name "whirringbox.local" to identify itself.
Then, the avahi-daemon replies to this message, providing the IP address of
whirringbox. So in general, to connect to an Ubuntu machine by hostname for an
mDNS-supporting system, you need to add ".local":
ping whirringbox.local
PING whirringbox.local (192.168.0.11) 56(84) bytes of data.
64 bytes from whirringbox.local (192.168.0.11): icmp_req=1 ttl=64 time=0.543
ms
64 bytes from whirringbox.local (192.168.0.11): icmp_req=2 ttl=64 time=0.150
ms
64 bytes from whirringbox.local (192.168.0.11): icmp_req=3 ttl=64 time=0.152
ms

I find this a great alternative to the idea of setting up static IP addresses and
messing with /etc/hosts.
linker errors using webkitwidgets:

When attempting to add a webpage viewer to my Linux Qt5 application (Ubuntu


14.04) via a "QWebView", part of the "webkitwidgets" module (QT +=
webkitwidgets), I was missing some development libraries which were causing
numerous linker errors (libraries which could not be found). Many related to
gstreamer, but there were a few others. Installing the following few packages fixed
this for me:
sudo apt-get install libgstreamer0.10-dev
sudo apt-get install libxslt-dev
sudo apt-get install libgstreamer-plugins-base0.10-dev

convert a PDF into a series of images:

Use the command line utility pdftoppm:


pdftoppm -png slides.pdf slide_imgs/slide

39

where -png defines the format (e.g. png, jpg) can be specified, slides.pdf is the input
file, and slide_imgs/slide is the prefix for each filename (this puts slides into a
slide_imgs subdirectory).
remove cached startup errors:
You may encounter some startup errors with a dialog saying "system program
problem detected", even if nothing is actually wrong. These may be caused by
errors that occurred long ago that have been not been cleared properly. To do this
manually, use the following:
sudo rm /var/crash/*

If you still have startup error dialogs after doing this, check the contents of the
/var/crash directory.
digitally sign a PDF:
Xournal is a great bit of software that allows you to import a PDF file (with
formatting intact - the same cannot be said for LibreOffice), and place text and
images into the document and export.
sudo apt-get install xournal

s3cmd - Manage Amazon S3 buckets (webhosting):


s3cmd is a great little command line application which lets you manage Amazon S3
buckets.
sudo apt-get install s3cmd

An often used command (put it in a script if used frequently), to recursively


copy/update/delete files from a local working directory to the remote:
s3cmd sync * s3://www.example.com --acl-public --progress --verbose --deleteremoved

40

Das könnte Ihnen auch gefallen