Linux

Shutdown from command line, the easy way

Being stupid with friends a couple of nights ago, this is the way I shutdown my laptop (fixing a typo, you know):

echo "sudol init 0" | sed 's/sudol//'|xargs sudo

Using `xargs` makes me feel better.

Scribes editor cheatsheet

Scribes editor cheatsheets This morning I decided to give Scribes another try. It has some great and cool features such a snippets (see the demo) and automatic word completion.
It also offers a pretty big set of keyboard shortcuts, some of them solve those little repetitive tasks you are used to if you edit a lot of code (like “free current line” or “free next line” to make space for more code).
So I thought a cheatsheet would be a good thing to start with and to have at hand. It took me a lot of time, expecially because I have been experimenting with a couple of tools I had never tried before, Scribus and Inkscape. I finally decided to go with the latter, as it gave me more ease of control on images.
I publish here the result for everyone to use. See further CC licence details clicking on the image below.
Get the cheatsheet from Flickr at different sizes or download the local copy (JPG 361KB).

Creative Commons License

This is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 License.

Extreme Basherism

In the past you may have encountered this problem: looping through a list of files with a Bash “for loop” gave you headaches if filenames had spaces inside. This is our setting:

flevour@voyance:/tmp/blog_post$ touch "my filename with space"
flevour@voyance:/tmp/blog_post$ touch one two three other filenames
flevour@voyance:/tmp/blog_post$ ls -l
total 0
-rw-r--r-- 1 flevour flevour 0 2007-05-07 17:49 filenames
-rw-r--r-- 1 flevour flevour 0 2007-05-07 17:48 my filename with space
-rw-r--r-- 1 flevour flevour 0 2007-05-07 17:49 one
-rw-r--r-- 1 flevour flevour 0 2007-05-07 17:49 other
-rw-r--r-- 1 flevour flevour 0 2007-05-07 17:49 three
-rw-r--r-- 1 flevour flevour 0 2007-05-07 17:49 two

Now, the elite hacker that is in you wants to add a cool extension to all of these. Before getting your hands dirty with mv command, you cleverly echo the variables in the for loop so you know where you are going.
First try:

flevour@voyance:/tmp/blog_post$ for i in `ls`; do echo $i; done
filenames
my
filename
with
space
one
other
three
two

No luck. “Maybe”, you think, “I need to add the -1 (minus-one) switch to have each filename on a single line”, no luck anyway (feel free to try), The fact is Bash “for loop” parses input stream and stops as soon as it finds a “space”. Now if you surf a bit around you may find this solution that, although very compact and easy to remember, doesn’t satisfy your unconsciously deep need for deeper hackery hacknessity:

flevour@voyance:/tmp/blog_post$ ls | while read i; do echo $i; done
filenames
my filename with space
one
other
three
two

This solution correctly loops all the files. But I would like to show you a different approach that is obscure and great at the same time (found at LinuxQuestions):

flevour@voyance:/tmp/blog_post$ IFS=$'\n'
flevour@voyance:/tmp/blog_post$ for i in `ls`; do echo $i; done
filenames
my filename with space
one
other
three
two

Some remarks:

  • it’s generally suggested to backup the original content of IFS and restore it when you don’t need the different value anymore
  • IFS=$’\n’ looks strange to me, I don’t understand the need for the dollar sign. If you try with IFS=’\n’, you’ll get weird results. Any hackers out there can get the riddle an answer (Rionda? Riff Raff?)
  • after some brief researches it’s not clear if IFS modification and restore is seen as a good programming pattern
  • stands for Internal Field Separator

Of course the final script (we wanted to add extensions, remember?) would be:

flevour@voyance:/tmp/blog_post$ ifs=$IFS
flevour@voyance:/tmp/blog_post$ IFS=$'\n'
flevour@voyance:/tmp/blog_post$ for i in `ls`; do mv $i $i.1337; done
flevour@voyance:/tmp/blog_post$ IFS=$ifs

Enjoy your Bash hacking time!

Technorati Tags:

Bored?

Booooooorriiing
Read `man bash` or the Simmetry entry on Wikipedia.

Technorati Tags:

Dependency-hackish way to install LAMP on Ubuntu

Lampen-PaarA lot of guides go into details to explain the correct sequence for getting a Apache+PHP+MySQL environment running on Linux.
I am running a fresh Ubuntu installation right now and when I typed “apt-get install phpmyadmin” I noticed everything I needed was correctly installed (except for mysql, this calls for another hard “apt-get install mysql-server” command).
Next time I’ll need LAMP, I’ll “apt-get install phpmyadmin mysql”, instead of going through other step-by-step guides…

Technorati Tags:

Missing extension

071020062253 I got some problems with signing in my Google Browser Sync and I am finding out how much I have come to rely on it for my daily browsing: session restore, password autocompletion, URL autocomplete and so on … hope it comes back soon …

Technorati Tags:

Great news since last post, linux installation on TM8106

I bought a new laptop and I spent the last 4 days configuring it and getting it to a "development ready" state. I am writing this post laying on my bed via my newly installed WIFI network. Whoah. The new laptop is a TM8106WLMI. I installed Gentoo. I am available for giving out tips and tricks for the configuration, just drop me a line at tm8106 AT the domain of this blog. I'll be glad to help you out! I have got working everything important (video drivers and wifi).
Technorati Tags:

Nostalgic post

Reading Phrack magazine via Gopher tastes totally different, even if the client (Firefox understands HTTP and Gopher protocols; surprised about the first? Get used to it, there will be much to talk about it - > search for "pipeline") stays the same. I wish I lived those days in which txt was the Way. Will be such days return in the future in a different fashion? NB: The title of the post is imprecise. I can't be nostalgic of something I didn't live, but, well, whatever.
Technorati Tags:

You don't read chinese/indian sites all the day, do you?

Add this line to your .bash_profile and love the Firefox speedbust (I am sorry to inform you won't be able to read those favourite chinese or indian blogs of yours since with this command you are actually disabling the loading of Pango library):  export MOZ_DISABLE_PANGO=1 Via Fullo (italian blog). 
Technorati Tags:

Trying to setup RSA authentication

Always remember to run "chmod 0700 ~/.ssh && chmod g-w ~&& chmod o-w ~" or SSH will refuse to cooperate (thanks ramses0 in Dreamhost old User Knowledge Base).
Technorati Tags:
Syndicate content