Nicolás Brailovsky


A modern blog

Archive for the ‘Console’ Category

Starting Ubuntu in console mode

author Posted by: nico on date Oct 13th, 2011 | filed Filed under: Console, Gnome, Linux

Like it or not, Ubuntu is so easy to install that even for servers is very comfortable to just mount the iso and create as many virtual machines as you may need. Sometimes you already have an iso for Ubuntu, but are too lazy to download the server version. For those occasions you can either decide to waste precious RAM running a GUI for a server that will never need it, or you can remove all traces of the graphical login. Like this:

  1. sudo update-rc.d -f gdm remove

This will remove GDM from the startup scripts, meaning you can still fire up the graphical interface (*) if you want, but it will start Ubuntu without loading any graphics stuff. This is very useful to save on RAM, startup time and processing power, which even if not that useful for a desktop machine is incredible beneficial when you have several virtual machines running in a single physical server.

(*) More precisely, if you have users that need it. Remember though, if it can’t be done in console mode, it ain’t worth doing.

http://www.makarras.org/2008/06/17/gandalf/

Running commands on Windows from Linux, through ssh

author Posted by: nico on date Sep 22nd, 2011 | filed Filed under: Console

Running Windows is something I don’t usually like (running of Windows is a different story) but having to run something on Windows command line interface is something I wouldn’t wish even to my worst enemies. I was stuck in that situation, don’t remember why, but I needed to run a command in a Windows machine, automatically, and I only had ssh (is there a better way of automating scripted tasks in Windows, remotely and without a GUI?). Well, this is what I came up with:

  1. ssh host cmd /c dir

Running that in a bash shell will show the directory listing of C: in machine “host”. Ugly as hell, but it’s a good way of kickstarting a batch script.

Zero padding for Bash scripts

author Posted by: nico on date Sep 15th, 2011 | filed Filed under: Console

Lately I found myself trying to generate a video from a series of images generated by a program. Doesn’t sound difficult, until you start running into a stupid issue: your 1000th frame will come before your 2nd frame!

Luckily there’s a very easy fix for this problem, just add zero padding in a bash script. How?

  1. for i in `seq 1 10`; do echo $i; done

That will print all the numbers between 1 and 10. This one will do the same, with zero padding:

  1. for i in `seq 1 10`; do printf "%02d\n" $i; done

sshfs, quick remote mount

author Posted by: nico on date Jun 9th, 2011 | filed Filed under: Console

When all you have is ssh access to a machine you have enough to mount a remote disk to your work station. How? easy:

  1. sshfs user@host:/path/to/remote/dir /path/to/local/dir

Remember you need permission for both local and remote directories.

Repeat (and fix) last command

author Posted by: nico on date May 26th, 2011 | filed Filed under: Console

How many times have you run a command but forgot to add sudo at the beginning? How many times did you open vim instead of gvim? All that has an easy fix, instead of pressing up-left-left-left-left-left… (almost like a Konami code, isn’t it?) just use !!.

!! expands to the previous command, so for example “vim foo”, then “g!!” will execute “gvim foo”.

Another common problem, you mistype vim for vmi (hey, it may be a common problem if you’re dyslexic). Just type fc, short for fix command, to open the last command in your configured editor. Fix it (lxp, bonus points if anyone understand this :D ) then write and save. The fixed command will be executed.

Go home

author Posted by: nico on date May 19th, 2011 | filed Filed under: Console

It really bothers me when people type “cd $HOME” or even worse, “cd /home/username”. Why? Just type cd alone, it’ll go home by itself.

Another useful cd tip, use “cd -” as an alias for “cd $OLDPWD” (oldpwd is the previous directory).

Know your history (at least in bash)

author Posted by: nico on date Apr 28th, 2011 | filed Filed under: Console

I always wonder why do you see so many people pressing up a bazillion times when trying to bring a command they recently typed. Just use ctrl+r and type part of the previous command, it’ll save you many hours of pressing up.

echo “Hola mundo” > /dev/full

author Posted by: nico on date Apr 21st, 2011 | filed Filed under: Console

I’d write something witty but there’s not a lot to talk about /dev/full. Anyway, it is a cool tip, so I’ll share it:

Everyone knows /dev/null, and most will know /dev/zero. But /dev/full was unknown to me until some time ago. This device will respond to any write request with ENOSPC, No space left on device. Handy if you want to test if your program catches “disk full” – just let it write there

From Myon’s Blog

Time your time

author Posted by: nico on date Mar 29th, 2011 | filed Filed under: Console

“time” is a useful command line utility to measure how long it takes for your super optimized algorithm to run, but it’s useful as a timer too: just write “time read” and press enter when you get tired of waiting. Instant timer on your console!

Sorting by random in bash and mocp random updated

author Posted by: nico on date Sep 9th, 2010 | filed Filed under: Console

Random is nice. And now you can sort by random your output using sort -R. Why would this be useful? Well, I updated my mocp random script with a oneliner:

  1. mocp -c && find -type d | sort -R | head -n1 | awk ‘{print "\”"$0"\”"}’ | xargs mocp -a