The Archives

  • 18.Feb.17
    Understanding the strace command shell | fernape | (0)
    strace is a utility that traces system calls and signals. It is very useful for debugging purposes, specially if you don't have the source code of the problematic software. In its simple form it works like this: $ strace ls /tmp strace ls /tmp/ execve("/bin/ls", ["ls", "/tmp/"], [/* 80 vars */]) = 0 brk(0) = 0x1c3e000 access("/etc/", F_OK) = -1 ENOENT (No such file or directory) mmap(NULL, 8192, ...
  • 21.Jul.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 ...
  • 27.Mar.10
    Downloading a file with wget through a specific interface network | rafacas | (0)
    Sometimes I need to download a file from a computer with multiple net interfaces, but only one is connected to the Internet. In these cases I use the bind-address option of the wget command, which binds the connection to the address specified in the local machine. $ wget --bind-address= \ > --2010-03-27 12:25:56-- => `ppp-2.4.4-11.fc11.src.rpm.1' Resolving Connecting to||:21... connected. Logging in as anonymous ... Logged in! ==> SYST ... done. ==> PWD ... done. ==> TYPE I ... done. ==> CWD /vol/rzm1/linux-fedora-secondary/development/source/SRPMS ... done. ==> SIZE ppp-2.4.4-11.fc11.src.rpm ... 724348 ==> ...
  • 06.Sep.09
    How to verify MD5 or SHA-1 digests security | rafacas | (2)
    MD5 and SHA-1 are cryptographic hash functions. They are deterministic procedures that take an arbitrary block of data as input and return a fixed-size bit string, the hash value (called message digest or fingerprint as well). Verifying MD5 or SHA-1 digest is highly recommended when you download new software for your system. In most of Linux distros the md5sum and sha1sum commands are available: $ md5sum ubuntu-9.04-desktop-i386.iso 66fa77789c7b8ff63130e5d5a272d67b ubuntu-9.04-desktop-i386.iso $ sha1sum ubuntu-9.04-desktop-i386.iso 19aabf327fdbde9e66db54dc04e3a83b92f70280 ubuntu-9.04-desktop-i386.iso Solaris (even version 10) doesn’t ship either with md5sum or sha1sum installed. However you can use digest: % /usr/bin/digest -a md5 GNUgcc.3.4.4.SPARC.64bit.Solaris.10.pkg.tgz 498c344fe2839631bb7cf4b869b7b830 % /usr/bin/digest -a sha1 GNUgcc.3.4.4.SPARC.64bit.Solaris.10.pkg.tgz a8da8247900dd06a7000fd0e6d41f834d6ab3e40 And in Mac OS X, ...
  • 25.Jun.09
    Samba available shares shell | pfortuny | (0)
    $ smbclient -L //melchor -U username Shows all the available shares at melchor. Asks for a password if needed. The -U option may be unnecessary if shares are browseable. The snippet is useful if you have forgotten a share name, for instance.
  • 30.Apr.09
    Changing your login shell shell | fernape | (0)
    Yes, I have to admit this is the first thing I do on my account after installing FreeBSD :). This example however, comes from a Linux box (you may notice it due to the default installation paths for the shells). $ chsh -l /bin/ash /bin/bash /bin/csh /bin/tcsh The command above lists the available shells. (I have omitted some of the entries to shorten the list). $ chsh -s /bin/bash The next time you log in, your shell will be bash. Enjoy!
  • 20.Apr.09
    Monitoring HTTP requests from the command line network | rafacas | (0)
    Some days ago Javisantana sent me a tweet with a link to a one-liner HTTP requests monitor. It goes as follows with some ouput added: $ sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*" Password: tcpdump: listening on en1, link-type EN10MB (Ethernet), capture size 65535 bytes GET / HTTP/1.1 Host: GET / HTTP/1.1 Host: GET / HTTP/1.1 Host: GET / HTTP/1.1 Host: GET /intl/en_com/images/logo_plain.png HTTP/1.1 Host: [...] Replace en1 with your network interface's name. Usually enX in BSD-like OSes and ethX in Linux. You can create an alias named httpdump and add it to ~/.bash_profile: alias httpdump='sudo tcpdump -i en1 -n -s 0 -w ...
  • 26.Mar.09
    Mounting ISO images cmd | rafacas | (0)
    # mount -o loop file.iso /mnt/iso Mounts an iso image on the /mnt/iso directory. The loopback module needs to be enabled.
  • 24.Mar.09
    Linux Kernel 2.6.29 released news | rafacas | (0)
    Via Slashdot I have found out that Linus Torvalds has just released the Linux 2.6.29 kernel. There is a temporary change of logo to Tuz, a Tasmanian Devil, wich is an endangered species. Besides the logo, some of the new important features are: Support for kernel mode-setting on Intel hardware. "Mode setting" is for setting up things like screen resolution and depth mode, in other words, configuring whatever is necessary on the graphics card for displaying things on the screen. Btrfs: is the next-generation Linux filesystem, developed from scratch following the design principles of filesystems like ZFS, WAFL, etc. Squashfs: is a highly compressed ...
  • 10.Mar.09
    Converting filenames to lowercase cmd | rafacas | (0)
    $ for i in *; do mv "$i" "$(echo $i|tr [:upper:] [:lower:])"; done Turns all uppercase characters in the present directory filenames into lowercase. There is no collision detection, so if some name gets repeated, the destination file will be overwritten and the first file will be lost. Use the above if you know that there will be no collisions.