New Linux commands for old habbits

posted on 2013-11-26

Best to start with a disclaimer: I'm not a system admin, I'm a programmer. I don't keep up with the old and the new commands floating around and as for GNU tools, it's easy to keep an old approach working. Until you install Arch Linux and discover most of your commands are considered old or obsolete. Below is a list of some of the old approaches I came across, and their new rivals.

netstat becomes ss

Netstat allows you to see the different open connections. I often use netstat -l to see whether a daemon even got to binding the right port.

The netstat command has been replaced with ss. The command-line switches are almost the same.

Common things to do with ss:

  • To see a numeric list of listening processes Was netstat -lnp becomes ss -lnp.

ifconfig becomes ip addr

Ifconfig was used to configure the network interfaces and has been replaced by ip. The ip command takes the sentence building approach you saw with ifconfig even further, by combining more network related tools behind one command. I'll give ip route it's own section below.

  • Bring a network interface up or down. Was ifconfig eth0 up, now use ip link set dev eth0 up
  • Configure an ip address on a device. Was ifconfig eth0 10.200.2.5/16, now use ip addr dev eth0 add 10.200.2.5/16

The same hold for the route command, which now falls under ip route.

ps aux | grep becomes pgrep -af

I've been using pipes filled with ps for ages, but you always end up seeing one command you don't want to see: the ps command itself.

The replacement is pgreg which you can give two options: -a for a full listing of the command-line of the found process and -f to match the given pattern to the complete command and not only the program name.

gnome-open becomes xdg-open

I've been using gnome-open for a few years now. When you are on the command-line a lot, it's the easiest way to open files you don't remember the application for. With the new releases of gnome-shell, this command has finally been killed of in favour of gvfs-open. In the meantime, the Freedesktop.org tools have released the equivalent xdg-open command (which delegates to the system default, in my case gvfs-open). You can simply exchange the two and know that you can use it on different desktops.

It is possible to use gvfs-open as well, but best to stick with the wider accepted xdg-open.

Host a directory with Python

I use Python as a quick way to locally host a directory. With Python 2 you can use

python -m SimpleHTTPServer 4000

This will start a simple HTTP server on http://localhost:4000, and yes the last argument is the port number.

With Python 3 the modules have moved around, so now it's:

python -m http.server 4000

Surely I missed something, feel free to post a comment.