The Archives

  • 18.Feb.13
    When you think everything is lost… shell | fernape | (0)
    I have seen people many times doing something like this: $cat binary_file The problem with the above is that usually you end up with a prompt that looks like this: �g`�g���i`�i��k`�kX@l`(l � Whatever you type, you get garbage in your terminal. In this case, what most people do is to despair and close the terminal, losing the information contained in it. reset is a command that gets the terminal back to its normal state. Sometimes everything is so mangled that there is no echo from the terminal. Don't panic, just type reset and press ENTER. If ENTER does not work, try to replace it by ...
  • 25.Sep.09
    Creating RSA keys security | rafacas | (0)
    RSA is an algorithm for public-key cryptography. Its advantage is that it does not require the initial exchange of secret keys unlike symmetric key algorithms. Each user has a pair of keys, one for encryption (the public key) and another one for decryption (the private key). The private key is kept in secret while the public key may be widely distributed. OpenSSL is usually the tool used for creating an RSA key pair (the public and private ones). $ openssl genrsa -out key.pem 1024 Generating RSA private key, 1024 bit long modulus ............................................++++++ .....++++++ e is 65537 (0x10001) This command creates a 1024-bit key pair and ...
  • 14.May.09
    Split a file shell | rafacas | (0)
    Sometimes you need split a file. For example, to send them attached to an email. For this, you can use the split command. $ split -b 1m big_file file_part_ In the example, the big_file size is 10MB, the -b option split the file in 1MB pieces, and the file_part_ is the name given to the different parts. $ ls file_part_* file_part_aa file_part_ac file_part_ae file_part_ag file_part_ai file_part_ab file_part_ad file_part_af file_part_ah file_part_aj All the files are 1MB long. For joining all the parts you can ...
  • 24.Mar.09
    gnuplot just for coordinates shell | pfortuny | (2)
    I needed a list of coordinates urgently, and I needed it in a text file (I am using LaTeX a lot lately). Gnuplot does the job properly, if told to do so: $ gnuplot gnuplot> set terminal table gnuplot> set output "hyperbola" gnuplot> set parametric gnuplot> plot [t=-1.5:1.5] cosh(t),sinh(t) gnuplot> quit $ cat hiberbola |awk '/[0-9]/{print "(",$1,",",$2,")"}' > hyperbola.txt The above saves in "hyperbola" a list of coordinates: each line contains a pair x y i (x coordinate, y coordinate, type of coordinate). The awk line turns it into a list of parenthesized coordinate pairs. The lines above saved me a lot of troubles yesterday.
  • 10.Feb.09
    Some xargs scripts, shell | pfortuny | (1)
    Rafacas has already mentioned it, but xargs is sometimes much more useful than what it looks like. Two examples come to mind: Way too many files for rm or ls. It may well happen that a script has generated more than 10000 files in the same directory (it was your friend, not you, I know). If you try and rm * in there, you will be in trouble. Ditto if you simply want to count them with ls | wc -l. However, the following works: $ find . -type f -print0 | xargs -0 ls | wc -l (or rm instead of ...
  • 15.Jan.09
    Where is an executable? cmd, shell | pfortuny | (0)
    # which cat /bin/cat The which command shows the first instance of an executable file with the specified name found following your $PATH variable.
  • 11.Jan.09
    Here documents shell | fernape | (0)
    A here document is a way to define a literal string preserving the space, new line characters, etc. It is used with the << redirection operator and it needs a delimiter token. Let's see an example: $ cat << _END >file > This is > a multiline > string > _END $ cat file This is a multiline string I used _END as delimiter, but you can use whatever you want (endOfDocument, _EOF_, etc)
  • 09.Jan.09
    Authpf: authenticated routing and firewalling on OpenBSD network, security, shell | pfortuny | (0)
    In our detailed description of OpenBSD's packet filter (here and there) we mentioned authpf, and spoke of it as a useful tool, but what is it use? I tend to understand it as an instrument for authenticated routing, that is, a way to provide routing (and firewalling etc...) services only to authenticated users. Think of a corporate setting with different users having access to different services according to their identities (and not according to their computer's IPs, which may well be dynamic or different). For example, user boss may access the firm's MAIN smb (ports 139, 435) server and any http ...
  • 18.Dec.08
    Cron job every 5 minutes automated, cmd, security | pfortuny | (0)
    $ cat < /var/cron/tabs/pfortuny */5 * * * * /usr/bin/my_task The specified task is run every 5 minutes.
  • 08.Nov.08
    Is this a tty? shell | pfortuny | (0)
    That is a funny question to ask if you are a human (because you *should* know the answer). But it is not that dumb for a system. As a matter of fact, among the multiple tests the shell admits (man 1 test), there is a -t which serves specifically for that: $ test -t 0 returns 0 (that is, success or true in shell jargon) if the standard input (file descriptor 0) is open and is associated with a terminal. So, unless things are going pretty bad, the following $ test -t 0 && echo $? Should always print a 0. However, when a file ...