Friday 31 August 2012

How to install software on Linux using repositories

This is a beginner guide on how to install software through terminal, using package managers. I will list the most common distributions (according to Distrowatch) and their command to search and install a certain software.


Search


Ubuntu, Debian, Mint (apt)

apt-cache search [software_name]

Fedora, Red Hat, CentOS (yum)

yum search [software_name]

Mandriva, Mageia (urpmi)

urpmi -y [software_name]

openSUSE (ZYpp)

zypper search [software_name]

Arch (pacman)

pacman -Ss [software_name]

Gentoo (portage)

emerge -s [software_name]


Install


Ubuntu, Debian, Mint (apt)

sudo apt-get install [software_name]

Fedora, Red Hat, CentOS (yum)

sudo yum install [software_name]

Mandriva, Mageia (urpmi)

urpmi [software_name]

openSUSE (ZYpp)

zypper install [software_name]

Arch (pacman)

pacman -S [software_name]

Gentoo (portage)

emerge [software_name]

Update 


Ubuntu, Debian, Mint (apt)

sudo apt-get upgrade

Fedora, Red Hat, CentOS (yum)

sudo yum update

Mandriva, Mageia (urpmi)

urpmi—auto-select

openSUSE (ZYpp)

zypper update

Arch (pacman)

pacman -Syu 

Gentoo (portage)

emerge -uD [software_name]


Uninstall


Ubuntu, Debian, Mint (apt)

sudo apt-get remove [software_name]

Fedora, Red Hat, CentOS (yum)

sudo yum remove [software_name]

Mandriva, Mageia (urpmi)

urpme [software_name]

openSUSE (ZYpp)

zypper remove [software_name]

Arch (pacman)

pacman -R [software_name]

Gentoo (portage)

emerge -C [software_name]


For Slackware, there is no package manager settling dependencies for you, and you can use pkgtool or slackpkg. Although, there is also slapt-get which somehow helps getting dependencies.


If you have a distribution that is based an older one, even if not listed here, it will most probably have the need the same commands to install software (e.g. Ubuntu is a Debian-based distribution, so they share the same installation commands).

Sunday 26 August 2012

How to batch rename files in Linux

Say you have a bunch of pictures and you want to rename them in a certain fashion. You can do it without the use of any external software and without painfully modifying the name of the pictures manually.

You can do it using just one command line! (even without using sed nor rename, if in a bash shell)


Strategy

Open a terminal and access the folder in which you have the files you want to modify:

$ cd ~/Desktop/Folder_name

Then use this command to modify the name of the files inside, to your need:

$ for file in *.* ; do mv [SOURCE_NAME] [DEST_NAME]; done


Examples

The examples below have increasing difficulty. Make sure to understand the previous ones before passing to the more complicated ones. Some knowledge of BASH will certainly help, but even you could use them blindly. Remember to be wise and make backups first, though.

If you have files with the same extension in the folder, such as JPG images, and you want to add a prefix, use this command:

$ for file in *.JPG ; do mv "${file}" "prefix_${file}"; done

If you want to add a suffix, instead, use this:

$ for file in *.JPG ; do mv "${file}" "${file%.JPG}_suffix.JPG"; done

And if your folder is full of mixed files, but you still want to add a suffix:

$ for file in *.*; do mv "${file}" "${file%.*}_suffix.${file#*.}"; done

If you want to number the files as well, sorting for modification time, use:

$ c=0; for file in $(ls -rt); do let c=${c}+1; mv "${file}" "prefix_${c}_suffix.${file#*.}"; done

Have fun renaming!

Wednesday 22 August 2012

Monitor your badwidth usage: bwbar

The repositories include a nice little program to monitor your bandwidth usage. Very useful if you have a restriction on your bandwidth and you want to track your daily bandwidth usage.

The program is called bwbar. It generates a graphical readout of the bandwidth usage locally in a .png and a .txt file.

Installation


Ubuntu/Debian
$ sudo apt-get install bwbar

Fedora
$ sudo yum install bwbar


Usage


When installed, you need to modify the configuration file:

$ sudo emacs -nw /etc/default/bwbar

And uncomment the lines:

#DIR=/var/www
#RUNAS=www-data
#OPTIONS="eth0 1.5"

removing the # from the beginning of the line (it should change color from red when you do), and change the values depending on the directory you want the logs saved in, the user you want the program to run as, and other options you want to include when you run bwbar.


Then, you need to change the permissions, as following (if you kept the same folder):

$ sudo chown -R www-data:www-data /var/www/bwbar/

And then you can start the daemon by typing:

$ sudo /etc/init.d/bwbar start

You can see the bandwidth bar on http://[your-server-ip]/bwba.


If you want to track traffic, check out the package darkstat.

Thursday 16 August 2012

Mogrify: scale and crop multiple images in one command

When dealing with a lot of pictures, sometimes we want to make a common modification such as a change of resolution. In the case of multiple screenshots it is also common to crop all of the images at a fixed position (such as selecting only the same window).
Doing this job by hand, even just for three or four times, using the same parameters, is stressful and tiring, so we can ask for help to the terminal!

Mogrify is a command of the ImageMagick package and allows us to perform many operations on multiple images. In addition to scaling, resizing and cropping, mogrify can compress, convert, apply filter to images and much more.

Installation

For Fedora:
$ sudo yum install ImageMagick

For Ubuntu/Debian:
$ sudo apt-get install ImageMagick

Usage

The program overwrites the existing images, so, in order to prevent any unwanted modification, make a backup of the images or at least try the command on a sample image to make sure that it is the wanted modification.
Firstly, enter in the directory where the images that we want to modify are
$ cd folder_name

Then, say you want to scale the pictures to a resolution of 640x480:
$ mogrify -scale 640x480 *.* 
(note: if using the wildcard *.* , every single file in the folder will be modified by the command, so make sure that the folder contains only the files you want to modify or use different wildcards as *.jpg or e.g. *-2012.jpg)

If you want to scale the pictures keeping the aspect ratio, specify only the length in pixels and the height will be adjusted to keep constant the aspect ratio:
$ mogrify -scale 640 *.* 

Or using the same argument for the height instead of the width:
 $ mogrify -scale x480 *.* 

Or can also use a percentage of the original size, so if you want to halve the resolution:
$ mogrify -scale 50% *.*  

Or you can even modify only pictures bigger (or smaller) than the specified resolution and keep the others unchanged, respectively:
$ mogrify -scale '640x480>' *.*  
$ mogrify -scale '640x480<' *.*  


If you want to crop pictures in a window of 300x200 starting at pixels x=0 and y=100 where x is the offset in length from left to right and y is the offset in height from top to bottom, you need to use another option.
Since it is difficult to know the offset precise values a priori using gimp (a graphical editor) to take these values from the cursor position or selection can help. Then, use:
$ mogrify -crop 300x200+0+100 *.* 


If you want to compress images, use:
 $ mogrify -compress JPEG -quality 85 *.jpg 

where JPEG is the compression type and 85 is the quality for JPEG compression, which varies from 0 (lowest) to 100 (highest).


Or convert images from gif to jpeg format:
$ mogrify -format jpg -quality 85 *.gif


And rotate by an angle, e.g. 90 degrees:
$ mogrify -rotate 90 *.* 

Or if you want to rotate the image only in specific occasions, as if height is bigger than length (e.g. 480x640) (and viceversa), use, respectively:
$ mogrify -rotate '90>' *.*
$ mogrify -rotate '90<' *.*


Useful Links

Check out the official page of ImageMagick on Mogrify here, where you can find with more detail all the options of mogrify.

Saturday 11 August 2012

How to reinstall the network-manager if you accidentally removed it

Using the aptitude package manager in Debian, I noticed a message that suggested me to use the command:

$ apt-get autoremove

This would have removed the unused dependencies following to having removed some unused packages. The list was long and I skimmed quickly through it, noting the fact that there weren't important packages, as someone would expect.

Unfortunately, the Gnome network-manager was included in the list, and when I run the command it removed my possibility to connect to the internet and even to re-install the network-manager itself!

In this ironic situation, angry by being tricked to run a damaging command, I was already thinking to reinstall Debian. But wait! That would be a silly move.

The solution


In order to have an internet connection, you don't need the network manager. If you still have ethernet available, grab that cable and open a terminal:

$ sudo ifconfig eth0 up
$ sudo dhclient




This will make your ethernet working even without the Gnome network-manager. After this, you can run a:

$ sudo apt-get install network-manager-gnome

and have your wireless connection working again.

A suggestion


Do not use the auto-remove command if you do not know what it is removing. It might be a vital component for your system and damage it heavily.

You can use the auto-remove with the simulate option first (-s), or just deactivate the auto-remove in /etc/apt/apt.conf 

 // auto-remove breaks on meta packages
APT::Get::AutomaticRemove "0";
APT::Get::HideAutoRemove "1";

// Recommends are as of now still abused in many packages
APT::Install-Recommends "0";
APT::Install-Suggests "0";
Debug::pkgAutoRemove "0";

// PDiffs reduce the required download for apt-get update, but increase the
// CPU requirements and quite often fail.
Acquire::PDiffs "0";

// Remove apt unauthenticated warnings
APT::Get::AllowUnauthenticated "0";

Tuesday 7 August 2012

Change language in Firefox and Thunderbird

Just after I installed Debian, I immediately felt the need to install Firefox and Thunderbird, as they are my favorite web and mail browsers.

As they are not present in the debian repositories, I had to use the ones from linuxmint (I added to my /etc/apt/sources.list):

deb http://debian.linuxmint.com/latest testing main contrib non-free

And after I installed Firefox and Thunderbird, I found myself with a Firefox in Afrikaans and Thunderbird in Arabic. Why this weird combination?

It is because of a bug in the Linux Mint repositories. When you go to install the browsers, they pick the first language pack they find, in alphabetical order!

In order to go back to english, you need to remove the language packs, using the package manager, and then install the english ones:

$ sudo apt-get remove firefox-l10n-af thunderbird-l10n-ar

This command alone actually automatically asked to install the English language packs. You can install also other languages by browsing in the repository:

$ apt-cache search firefox | grep l10n

For some reason, though, after this operations, the browsers did not work, so I tried:

$ sudo apt-get install firefox thunderbird

And everything worked like a charm, in a familiar language.

Sunday 5 August 2012

Ethernet connection not working in Debian after fresh installation

Just after I installed Debian Squeeze, at first boot, the wired ethernet connection, which worked so well during the install, was not working in the X system (Gnome).

I wondered a lot trying to find an error in ifconfig or dmesg, but could find none. After a while, I noticed that the "status" of the connection in Gnome whenever I clicked on the network manager icon was:

 "Wired device not managed"


The device was simply not activated in the interfaces!

In order to activate it, type from a terminal:

$ sudo emacs /etc/NetworkManager/NetworkManager.conf
(or 'vi' or 'nano' instead of emacs, depending on your favourite text editor)

Then change the line:


[ifupdown]
managed=false

to

[ifupdown]
managed=true

Then save the file and restart the network manager:

$ sudo service network-manager restart

And the wired connection should be working straight away.