Archive | Linux

Linux
10 April 2012 1 Comment

About .bashrc, .profile, .bash_profile and .bash_login

How it works

There are various files that may be executed by the Bash shell when it is started. Usually they follow this logic:

  • When bash is invoked as an interactive login shell:
    1. Bash first reads and executes commands from the file /etc/profile, if that file exists.
    2. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. Usually there is a default ~/.profile file, and ~/.bash_profile and ~/.bash_login usually do not exist.
  • When bash is invoked as an interactive non-login shell:
    1. Bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files exist.
    2. The standard ~/.profile sources (runs) ~/.bashrc if it exists.

A login shell means a session where you directly log into a system, e.g. setting up a remote SSH session or logging in through a non-graphical text terminal. A non-login shell is then the type of shells you open after logging in: typically in a graphical session when you open a new terminal window.

The bottom line is that you should put customisations that should always be executed in ~/.bashrc!
Example

Example: After installing…

Tags: ,
Linux
22 October 2011 1 Comment

Expand Tabs to Spaces Recursively

If you have a bunch of files with tabs, and you want to replace these tabs with the appropriate amount of spaces then you can use the expand command.

$ expand --tabs=4 stuff.php > stuff.php

With the –tabs switch the tab width is denoted, in spaces. So in this example each tab is replaced with four spaces.

In order to run this command on all PHP files in a directory, including its subdirectories, use this script:

#!/bin/sh
#
# Iteratively replaces tabs in .php files with 4 spaces.
#
 
find . -name "*.php" | while read line
do
  expand --tabs=4 $line > $line.new
  mv $line.new $line
done

Save it to a file and execute it in the directory you want to run the expands:

// Create the file in the current directory
$ touch expand.sh
 
// Use a text-editor like 'nano' to put the script code in the file.
$ nano expand.sh
 
// Make the script executable
$ chmod +x expand.sh
 
// Run the script
$ ./expand.sh

Tags: , expand, , php, spaces, tabs
Linux
7 October 2011 0 Comments

Linux Package Manager Tips

dpkg is the software at the base of the Debian package management system. dpkg is used to install, remove, and provide information about .deb packages.

dpkg itself is a low level tool; higher level tools, such as APT, are used to fetch packages from remote locations or deal with complex package relations. Tools like aptitude or synaptic are more commonly used than dpkg on its own, as they have a more sophisticated way of dealing with package relationships and a friendlier interface.

What package is that file in?

Source: http://www.ubuntugeek.com/what-package-is-that-file-in.html

One question I get all the time is “What package is that file in?” There’s a really easy way to find out yourself. It’s called apt-file and it can search for a file in any package (installed or not). It’s really easy to use:

[sourcecode language="bash"]
$ sudo apt-get install apt-file
$ sudo apt-file update
$ apt-file search autoexpect

expect-dev: usr/share/doc/expect-dev/examples/autoexpect.1.gz
expect-dev: usr/share/doc/expect-dev/examples/autoexpect.gz
expect-tcl8.3: usr/share/doc/expect-tcl8.3/examples/autoexpect
expect-tcl8.3: usr/share/doc/expect-tcl8.3/examples/autoexpect.1…

Tags: aptitude, , synaptics,
Linux
7 October 2011 0 Comments

Make the Ubuntu Network Manager Ignore an Interface

If you have several wired and/or wireless interfaces, the default Ubuntu network-manager program will manage them all. To make the network manager ignore an interface, you must edit the /etc/network/interfaces file.

The /etc/network/interfaces file contains network interface configuration information for the both Ubuntu and Debian Linux. This is where you configure how your system is connected to the network.

Look at your current interfaces:

$ ifconfig

To make network-manager ignore wlan0:

$ sudo nano /etc/network/interfaces

And add the line:

iface wlan0 inet manual

The manual keyword denotes that network-manager should ignore the interface. After a reboot, the network manager will show device not managed for wlan0.…

Linux
2 October 2011 5 Comments

Fixing Ralink 3090 Wireless Problems on Linux

Introduction

If you have a Ralink 3090 (RT3090) wireless network card, you can run into problems when running Linux. These problems manifest themselves as a connection that is unreliable and slow, or even completely broken.

The Linux kernel decides which modules (drivers) should be loaded for your hardware setup, but it can get it wrong. If you are having lots of wireless networking problems, you probably don’t have the correct modules loaded. The included-by-default kernel module that seems to give the best results with the RT3090 is called rt2860sta. If you are running Ubuntu, you can try the rt3090-dkms package, which might give better results than the rt2860sta module.

List Modules

To see your currently loaded kernel modules:

$ lsmod | less

Using the rt3090-dkms Module

If you are running Ubuntu, this module might give better results than rt2860. In my case Ubuntu would no longer shut down, but there are many positive stories about the module too.

First, install the package from the Markus Heberling’s personal package archive.

$ sudo add-apt-repository ppa:markus-tisoft/rt3090
$ sudo apt-get update
$ sudo apt-get install dkms rt3090-dkms

Now you should …

Linux
1 October 2011 0 Comments

Tips for Tweaking a New Ubuntu/Gnome2 Installation

Introduction

If you are a Windows poweruser, the switch to a Linux desktop environment can be quite a shock. Many of your favorite shortcuts and tricks become useless, and it can be quite challenging to get back up to speed. There are many tweaks that you do to make Ubuntu’s Gnome 2 desktop environment easier to use and more powerful. This article presents a list of things to do after a fresh install that may help both Ubuntu newbies and adept users.

Note that the 11.04 release of Ubuntu introduced a new desktop environment called Unity. It is a trainwreck of an UI at this point (2011), and power-users will most likely be much more productive in the ‘classic’ Gnome 2 UI. The tips in this article apply to Gnome 2 for Ubuntu, but some things might work for other distros and UIs.

Programs to Install

There are several invaluable programs that everyone should get after a fresh install.

Ubuntu Tweak

Ubuntu Tweak is a tool for Ubuntu that makes it easy to configure your system and desktop settings. If you are a Windows user you might know Windows Powertoys, which is very similar. You can configure login settings, package related jobs, default folder locations, which items to display…

Linux
20 July 2011 0 Comments

An Introduction to Using Screen on Ubuntu

Introduction

Screen is a window manager for Linux. The power of Screen is described well in this article:

The same way tabbed browsing revolutionized the web experience, GNU Screen can do the same for your experience in the command line. GNU Screen allows you to manage several interactive shell instances within the same “window.” By using different keyboard shortcuts, you are able to shuffle through the shell instances, access any of them directly, create new ones, kill old ones, attach and detach existing ones.

Instead of opening up several terminal instances on your desktop or using those ugly GNOME/KDE-based tabs, Screen can do it better and simpler. Not only that, with GNU Screen, you can share sessions with others and detach/attach terminal sessions. It is a great tool for people who have to share working environments between work and home. By adding a status bar to your screen environment, you are able to name your shell instances on the fly or via a configuration file called .screenrc that can be created on the user’s home directory.

If you are a Linux user, chances are you have been using additional Putty windows if you needed simultaneous access to more than one secure…

Linux
25 June 2011 2 Comments

Layer 2 Ping – Using the arping Tool

Introduction

The arping tool for Linux is the Layer 2 equivalent of the ping command. It is used to send ARP (Address Resolution Protocol) request messages to a destination host in a Local Area Network (LAN) . This is useful to test whether a particular IP address is in use and online in the network. The arping tool operates at OSI Layer 2, so it can only be used in local networks: ARP messages cannot be routed across routers or gateways. Many Linux distributions, including Backtrack, include arping by default.

When arping is run without parameters it will not do anything – except display the command line options:

$ arping
ARPing 2.09, by Thomas Habets <thomas@habets.pp.se>
usage: arping [ -0aAbdDeFpqrRuv ] [ -w <us> ] [ -S <host/ip> ]
 [ -T <host/ip ] [ -s <MAC> ] [ -t <MAC> ] [ -c <count> ]
 [ -i <interface> ] <host/ip/MAC | -B>
For complete usage info, use --help or check the manpage.

Arping with an IP Address Argument

Now let’s see arping in action by supplying it with an IP address to probe. This is the most common way to use arping. Say we want to send…

Linux
21 June 2011 1 Comment

Linux: Showing Open Ports and the Processes that Own Them

How do you list the open TCP and UDP ports on your server and the processes that own them? The answer is to use either the netstat or the lsof command:

netstat

$ sudo netstat -lptu
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 *:ftp                   *:*                     LISTEN      3825/vsftpd
tcp        0      0 *:ssh                   *:*                     LISTEN      3539/sshd
tcp        0      0 localhost:6600          *:*                     LISTEN      3922/mpd
tcp        0      0 localhost:mysql         *:*                     LISTEN      30004/mysqld
tcp        0      0 *:svn                   *:*                     LISTEN      3810/svnserve
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN      3539/sshd
tcp6       0      0 [::]:microsoft-ds       [::]:*                  LISTEN      3805/smbd
tcp6       0      0 localhost:6600          [::]:*                  LISTEN      3922/mpd
tcp6       0      0 [::]:netbios-ssn        [::]:*                  LISTEN      3805/smbd
tcp6       0      0 [::]:www               

Tags: , lsof, , open ports, tcp, udp
Linux
19 June 2011 0 Comments

Extracting a .tar.gz File With a Single Command

This will extract the contents of files.tar.gz to the current directory:

tar -xzf files.tar.gz

I find that a good mnemonic for this is the “angry German ordering you to extract an archive” mnemonic:
Xtract Ze Files!!

Tags: extract, gz, tar, xvzf