Author

The Archives

  • 09.22.11
    How to know if a CPU is 32 or 64-bit shell | rafacas | (0)
    Nowadays almost all the computers have a 64-bit CPU, but sometimes we are logged in on a remote server and do not know what kind of CPU it has and we need to know it to install a package or... out of mere curiosity. In those cases we can run the following command: $ grep --color lm /proc/cpuinfo flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc up ida nonstop_tsc arat pni ssse3 cx16 sse4_1 sse4_2 popcnt lahf_lm If the lm flag ...
  • 09.15.11
    Resume rsync file transfers network | rafacas | (0)
    I did not know that rsync had the resume capability till last week when I had to transfer almost 200GB between two servers with no good connection. I think some context is needed here: My company has two servers in two different cities where the backups are stored. There is a daily syncronization between the backup tree between the servers. That is, a cron task that calls a script that basically runs rsync. Due to the bad connection, I have had to add the -P option to the rsync command so that the command run by the cron task is: $ rsync ...
  • 09.08.11
    Changing permissions only in directories cmd | rafacas | (1)
    $ chmod -R u+rX Changes recursively the write permissions only in the directories. It has been very useful to me lately and I have to admit I did not know this till some weeks ago.
  • 09.01.11
    Adding formatting to an XML document shell | rafacas | (0)
    Sometimes, when I have to program a web service client I have to deal with unformatted XML files. For example, the next one: <users><user><email>pfortuny@commandliners.com</email><passwd>a0f901492d89fe2ba88cc96bf9d 2475e</passwd></user><user><email>n0str0m0@commandliners.com</email><passwd>7e1b6dbfa824d 5d114e96981cededd00</passwd></user><user><email>rafacas@commandliners.com</email><passwd> 70c1db56f301c9e337b0099bd4174b28</passwd></user></users> This is not a bad thing, because it is sent that way to save traffic, but I'd rather see it in a human readable format. So I use the xmllint command, that reformat and reindent the input. $ xmllint --format test.xml <?xml version="1.0"?> <users>   <user>     <email>pfortuny@commandliners.com</email>     <passwd>a0f901492d89fe2ba88cc96bf9d2475e</passwd>   </user>   <user>     <email>n0str0m0@commandliners.com</email>     <passwd>7e1b6dbfa824d5d114e96981cededd00</passwd>   </user>   <user>     <email>rafacas@commandliners.com</email>     <passwd>70c1db56f301c9e337b0099bd4174b28</passwd>   </user> </users> The indentation can be controlled by the environment variable XMLLINT_INDENT. The default value is two spaces. pfortuny, n0str0m0, do not worry guys, those are not your ...
  • 08.25.11
    Clearing the terminal screen cmd | rafacas | (0)
    Ctrl + l Clears the terminal screen.
  • 08.18.11
    Determining if an XML document is well-formed shell | rafacas | (0)
    After creating an XML document from scratch I always check if it is well-formed. This means it must adhere to a number of rules, including the following: Every start-tag must have a matching end-tag. Elements may nest, but may not overlap. There must be exactly one root element. Attribute values must be quoted. An element may not have two attributes with the same name. This is not an exhaustive list and I do not mean to explain all the rules. There are many, many ways a document can be malformed. But if you need to determine if and XML document is well-formed there is a linux ...
  • 07.25.11
    Edit a file using vi in read-only mode cmd | rafacas | (0)
    $ vi -R filename Edits filename in read-only mode. I use it more often than the more or less commands to read code because of vi's syntax highlighting.
  • 07.21.11
    Printing sequential numbers in BSD shell | rafacas | (0)
    In Linux, the seq command is pretty useful in some scripts, because it prints a sequence of numbers: $ seq 1 5 1 2 3 4 5 It is usually used in for loops: for i in `seq 1 5`; do ... done But this command is not included in BSD-like OSes. It is contained in the sh-utils, so one option is downloading and compiling it. But I prefer using the commands that come by default with the OS, for portability. In the BSD case, I found the jot command that prints sequential or random data. The following example shows the seq behaviour with jot. $ jot 5 1 2 3 4 5 Other example ...
  • 02.15.11
    find command in Powershell shell | rafacas | (0)
    In my actual job I have a laptop with Windows 7 installed on it. The last time I used Windows on a daily basis was four years ago and it was Windows XP. The terminal (cmd.exe) was... well, that was not a real terminal neither a real shell. The first days using Windows 7 I had a problem (which I will explain it later) and while I was installing cygwin to run some commands I found Powershell. I have to admit that Windows now has a real shell and it seems pretty powerful. It can be installed in Windows XP and ...
  • 08.04.10
    The Sibyl security | rafacas | (1)
    The Sibyl is a project invented and implemented by Pedro (pfortuny) and me (rafacas). Although I have to admit that it was Pedro's idea. It started with the goal of secure storage of the shadow file and, in general, of any database of secret authentication tokens (think of passwords -actually hashes of passwords- of users of a Web-based service, for example). We consider it addresses the main concern on those databases: dictionary attacks and rainbow tables, which have become available at negligible cost: there is a cloud-based service for doing dictionary attacks on a WPA key. Our approach for storing shadow files ...