Linux For Cynics One user's experiences with Linux

9Sep/130

Pull a Git Branch from Remote

In order to check out a remote git branch, first do a git pull:

git pull 

Then

git checkout -b [new_branch] > origin/[new_branch]

So for example, if your branch name is "newfeature", you'd do:

git pull
git checkout -b newfeature origin/newfeature
Tagged as: No Comments
2Aug/130

Reset or Change Terminal Background

Sometimes if you use vim in a virtual terminal with a color scheme with more than a 256 color pallet, you will have some ugly results:
debian-2013-08-02 14_46_17-
Even worse, those ugly colors may stick around after vim has exited. This is because a virtual terminal is essentially a state machine. When something changes, it has to be explicitly changed back to reverse it:
debian-2013-08-02 14_48_40-

One way to do this is to use the

tput

command. To go back to the normal colors, simply use this command:

$ tput reset
8May/133

Restart VNC Server via SSH

This is handy if the VNC server isn't working but you can connect via SSH. These instructions are for Ubuntu, which comes with vino-server for VNC.

To kill the currently running vino-server (if it is running), use pkill:

$ pkill vino

Then to start it again,

$ export DISPLAY=:0.0
$ /usr/lib/vino/vino-server &

That works in Ubuntu 12.10. If using something else, replace /user/lib/vino/vino-server with the location of your VNC server.

29Apr/131

Wifi from Command Line

In this short how-to I'll show you how to connect to a WPA wifi network from the network without any GUI tools.

First, we have to install the relevant software. Some distros do not come with much wifi firmware or wpa support out of the box and they must be installed after the fact. In Debian, follow this guide to install them.

Display the currently active network interfaces:

$ sudo iwconfig

You should see something like wlan0. Let's activate it:

$ sudo ifconfig wlan0 up

Optional if you know the SSID of the network you want:
Scan the interface for access points:

$ sudo iwlist wlan0 scan

Open the /etc/network/interfaces file (replace editor with text editor of your choice):

$ sudo editor /etc/network/interfaces

and add an entry for the network you want to join (replace words in CAPS with your details, where NAME is what you want to call the entry):

iface NAME inet dhcp
  wpa-ssid YOUR-SSID
  wpa-psk YOUR-PASSWORD

Now, just connect to that network!

$ ifup wlan0=NAME

To connect to a different network, simply add another entry to /etc/network/interfaces and run ifup wlan0=NEW-NETWORK-NAME.

24Apr/130

Install Wifi Firmware and WPA Support in Debian

Debian is a wonderful distribution but it is a bit strict on what it comes packaged with. Most wifi cards do not have open drivers, so you have to install them from the non-free repos. Here's now to install them and use them with wpa-supplicant.

First, we need to add the non-free Debian repositories. Add these lines to the /etc/apt/sources.list file:

deb http://ftp.us.debian.org/debian/ wheezy main contrib non-free
deb-src http://ftp.us.debian.org/debian/ wheezy main contrib non-free
 
deb http://security.debian.org/ wheezy/updates main contrib non-free
deb-src http://security.debian.org/ wheezy/updates main contrib non-free

Once the non-free repo is added, update and install the driver I need. You might need different firmware:

$ sudo apt-get update
$ sudo apt-get install firmware-iwlwifi

Also get the wireless-tools package:

$ sudo apt-get install wireless-tools

So we have the driver, but now we need to use it!

Since the iwlwifi module is automatically loaded for supported devices, we need to reload this module to access installed firmware:

$ sudo modprobe -r iwlwifi ; modprobe iwlwifi

Now we see if the device has an available interface:

$ sudo iwconfig

Yep! Mine is called wlan0. Connecting to a wpa secured wifi will be covered in the next post.

22Apr/130

Shutdown from Command line

In order to shut down your system from the command line, use the shutdown command in a virtual terminal or terminal emulator:

$ sudo shutdown -h now

The shutdown command must be invoked with a time to shut down. That's what now is. The -h flag tells the system to power off. For more options, see the man page.

Tagged as: No Comments
19Apr/130

Check your Laptop Battery Status from Command Line

The tool used to query laptop battery state is called acpi. In Ubuntu or Debian, install it like so:

$ sudo apt-get install acpi

Let's run it!

$ acpi

The output looks something like this:

Battery 0: Discharging, 99%, 02:34:33 remaining

There are various options for acpi we can use:

Check the temperature:

$ acpi -t

Output:

Thermal 0: ok, 48.0 degrees C
Thermal 1: ok, 48.0 degrees C

To check the AC power status

$ acpi -a 

Output:

AC Adapter 0: off-line

You can check all the status together:

$ acpi -V

Output:

Battery 0: Discharging, 96%, 02:33:55 remaining
Battery 0: design capacity 1773 mAh, last full capacity 1723 mAh = 97%
Adapter 0: off-line
Thermal 0: ok, 48.0 degrees C
Thermal 0: trip point 0 switches to mode critical at temperature 105.0 degrees C
Thermal 0: trip point 1 switches to mode passive at temperature 90.5 degrees C
Thermal 1: ok, 47.0 degrees C
Thermal 1: trip point 0 switches to mode critical at temperature 127.0 degrees C
Cooling 0: LCD 8 of 15
Cooling 1: Processor 0 of 10
Cooling 2: Processor 0 of 10
17Apr/130

Change the Hostname (Computer name) in Ubuntu

Changing your computer's name (also called the system's "hostname") in Ubuntu is simple. You just have to change two files and restart the computer. These instructions also work for Debian and Ubuntu-based distros (like Linux Mint). The files in question are /etc/hosts and /etc/hostname

1. Open /etc/hosts with sudo (or gksu if you're going to use something like gedit)

$ gksu gedit /etc/hosts

The file will look something like this:

127.0.0.1       localhost
127.0.1.1       current_hostname

Instead of current_hostname you'll see the hostname / computer name. Change it to whatever you want the new name to be. Save and close the file.

2. Open /etc/hosts with sudo (or gksu if you're going to use something like gedit)

$ gksu gedit /etc/hostname

This file just contains the hostname / computer name. Change it to whatever you want the new computer name to be. Make sure it matches the name you put in /etc/hosts. Save and close the file.

3. Restart your computer.

Tagged as: , No Comments
15Apr/130

Root Droid Razr Maxx HD Running 4.1.2

If you have a Motorola Droid Razr HD or Driod Razr Maxx HD running Android version 4.1.2, you might have read that it's not possible to root your device. Well, that has changed. Last week Dan Rosenberg released a root method for the Razr HD, Razr Maxx HD, Razr M and Atrix HD.

I tested this method using a Razr Maxx HD (XT926) with build 9.16.6. It was very easy and worked flawlessly. Here are the instructions from Dan's post:

1. Download this file to your PC.
2. Extract the entire contents of the zip file.
3. If you are using Windows, ensure you have installed the latest Motorola USB drivers available for your phone. I did not have to install any special drivers using Linux (tested with Debian 7.0 and Ubuntu 12.04).
4. Ensure USB Debugging mode is enabled on your device.
5. If you are using Linux or OS X, navigate to the extracted directory in a terminal and execute “./run.sh” (If you are using Windows, navigate to the extracted directory and execute “run.bat”).

Here's a video showing the rooting process:

Tagged as: No Comments
12Apr/131

Using rxvt-unicode-256color with ssh and screen

urxvt is one of the best terminal emulators available, however it comes with problems. For example, if you use ssh to connect to a remote host and then try to use screen, you might get an error like this:

Cannot find terminfo entry for 'rxvt-unicode-256color'.

The work around for that is to add this line to your ~/.Xdefaults or ~/.Xresources file (I used .Xresources):

URxvt*termName: rxvt

This will make urxvt identify as rxvt, which should work with screen.