UrFix's Blog

A geek without a cause

Category: Tricks

  • I found an awesome ascii aquarium for Linux terminals called Asciiquarium.You can now discover the mysteries of the sea from the comfort of your own terminal using ASCIIQuarium. It is an aquarium animation in ASCII art created using perl.
    Linux asciiquarium

    Installing Term-Animation

    First, you need to install Perl module called Term-Animation. Open a command-line terminal (select Applications > Accessories > Terminal), and then type:

    $ sudo apt-get install libcurses-perl
    $ cd /tmp
    $ wget http://search.cpan.org/CPAN/authors/id/K/KB/KBAUCOM/Term-Animation-2.4.tar.gz
    $ tar -zxvf Term-Animation-2.4.tar.gz
    $ cd Term-Animation-2.4/
    $ perl Makefile.PL && make && make test
    $ sudo make install

    Download and Install ASCIIQuarium

    While still at bash prompt, type:

    $ cd /tmp
    $ wget http://www.robobunny.com/projects/asciiquarium/asciiquarium.tar.gz
    $ tar -zxvf asciiquarium.tar.gz
    $ cd asciiquarium_1.0/
    $ sudo cp asciiquarium /usr/local/bin
    $ sudo chmod 0755 /usr/local/bin/asciiquarium

    How do I view my ASCII Aquarium?

    Simply type the following command:

    $ /usr/local/bin/asciiquarium

    or

    $ perl /usr/local/bin/asciiquarium

  • Securing your Linux server is a crucial step in protecting your data, intellectual property, and time, from the hands of crackers (hackers). The system administrator is liable for security Linux box. Lets start with this

    World-Writable Files

    Anyone can modify world-writable file resulting into a security issue. Use the following command to find all world writable and sticky bits set files:

    find /dir -xdev -type d \( -perm -0002 -a ! -perm -1000 \) -print

    You need to investigate each reported file and either set correct user and group permission or remove it.

    Noowner Files

    Files not owned by any user or group can pose a security problem. Just find them with the following command which do not belong to a valid user and a valid group

    find /dir -xdev \( -nouser -o -nogroup \) -print

    You need to investigate each reported file and either assign it to an appropriate user and group or remove it.

  • dd is a common Unix program whose primary purpose is the low-level copying and conversion of raw data. dd is an application that will “convert and copy a file”according to the referenced manual page for Version 7 Unix and is most likely inspired from DD found in IBM JCL, and the command’s syntax is meant to be reminiscent of this.
    Learn how to use DD by visiting this site Here

    Hope you enjoy

    1) Duplicate several drives concurrently

    dd if=/dev/sda | tee >(dd of=/dev/sdb) | dd of=/dev/sdc

    If you have some drive imaging to do, you can boot into any liveCD and use a commodity machine. The drives will be written in parallel.

    To improve efficiency, specify a larger block size in dd:

    dd if=/dev/sda bs=64k | tee >(dd of=/dev/sdb bs=64k) | dd of=/dev/sdc bs=64kTo image more drives , insert them as additional arguments to tee:

    dd if=/dev/sda | tee >(dd of=/dev/sdb) >(dd of=/dev/sdc) >(dd of=/dev/sdd) | dd of=/dev/sde

    2) create an emergency swapfile when the existing swap space is getting tight

    sudo dd if=/dev/zero of=/swapfile bs=1024 count=1024000;sudo mkswap /swapfile; sudo swapon /swapfile

    Create a temporary file that acts as swap space. In this example it’s a 1GB file at the root of the file system. This additional capacity is added to the existing swap space.

    3) Backup your hard drive with dd

    sudo dd if=/dev/sda of=/media/disk/backup/sda.backup

    This will create an exact duplicate image of your hard drive that you can then restore by simply reversing the “if” & “of” locations.

    sudo dd if=/media/disk/backup/sda.backup of=/dev/sdaAlternatively, you can use an SSH connection to do your backups:

    dd if=/dev/sda | ssh user@ssh.server.com dd of=~/backup/sda.backup

    4) Convert a Nero Image File to ISO

    dd bs=1k if=image.nrg of=image.iso skip=300

    This line removes the 300k header from a Nero image file converting it to ISO format

    5) send DD a signal to print its progress

    while :;do killall -USR1 dd;sleep 1;done

    every 1sec sends DD the USR1 signal which causes DD to print its progress.

    6) show dd progress part 2

    killall -USR1 dd

    if you need see progress of long dd command, enter subj on other console

    7) How to copy CD/DVD into hard disk (.iso)

    dd if=/dev/cdrom of=whatever.iso

    A dear friend of mine asked me how do I copy a DVD to your hard drive? If you want to make a copy of the ISO image that was burned to a CD or DVD, insert that medium into your CD/DVD drive and (assuming /dev/cdrom is associated with your computer?s CD drive) type the following command

    8) Watch the progress of ‘dd’

    dd if=/dev/zero | pv | dd of=/dev/null

    need pv (pipe view) :

    http://www.ivarch.com/programs/pv.shtml

    9) Clone IDE Hard Disk

    sudo dd if=/dev/hda1 of=/dev/hdb2

    This command clone the first partition of the primary master IDE drive to the second partition

    of the primary slave IDE drive (!!! back up all data before trying anything like this !!!)

    10) Test network speed without wasting disk

    dd if=/dev/zero bs=4096 count=1048576 | ssh user@host.tld 'cat > /dev/null'
    

    The above command will send 4GB of data from one host to the next over the network, without consuming any unnecessary disk on either the client nor the host. This is a quick and dirty way to benchmark network speed without wasting any time or disk space.

    Of course, change the byte size and count as necessary.

    This command also doesn’t rely on any extra 3rd party utilities, as dd, ssh, cat, /dev/zero and /dev/null are installed on all major Unix-like operating systems.

    11) clone a hard drive to a remote directory via ssh tunnel, and compressing the image

    dd if=/dev/sda | gzip -c | ssh user@ip 'dd of=/mnt/backups/sda.dd'
    
    
  • 1) Create a pdf version of a manpage

    man -t manpage | ps2pdf – filename.pdf

    Quick and dirty version. I made a version that checks if a manpage exists (but it’s not a oneliner). You must have ps2pdf and of course Ghostscript installed in your box.

    Enhancements appreciated :-)

    2) Bind a key with a command

    bind -x '"\C-l":ls -l'
    
    
    the -x option is for binding to a shell command

    3) Use file(1) to view device information

    file -s /dev/sd*

    file(1) can print details about certain devices in the /dev/ directory (block devices in this example). This helped me to know at a glance the location and revision of my bootloader, UUIDs, filesystem status, which partitions were primaries / logicals, etc.. without running several commands.

    See also:

    file -s /dev/dm-* file -s /dev/cciss/*etc..

    4) Single use vnc-over-ssh connection

    ssh -f -L 5900:localhost:5900 your.ssh.server "x11vnc -safer -localhost -nopw -once -display :0";
    vinagre localhost:5900
    
    This command

    1. SSH into a machine
    2. Tunnels VNC port to your local computer (“-L 5900:localhost:5900”)
    3. Runs a single use vnc server (“x11vnc -safer -localhost -nopw -once -display :0”)
    4. Goes into the background (“-f”)
    5. Runs VNC viewer on the local computer connecting to the remote machine via the newly created SSH tunnel (“vinagre localhost:5900”)

    
    

    5) Stop Flash from tracking everything you do.

    for i in ~/.adobe ~/.macromedia ; do ( rm $i/ -rf ; ln -s /dev/null $i ) ; done

    Brute force way to block all LSO cookies on a Linux system with the non-free Flash browser plugin. Works just fine for my needs. Enjoy.

    6) A child process which survives the parent’s death (for sure)

    ( command & )

    Test scenario:

    * Open xterm (or konsole, …)

    * Start xeyes with: ( xeyes & )

    * Close the xterminal

    The xeyes process should be still running.

     

    7) Compare copies of a file with md5

    cmp file1 file2

    8) backup delicious bookmarks

    curl --user login:password -o DeliciousBookmarks.xml -O 'https://api.del.icio.us/v1/posts/all'
    
    

    Useful script to backup all your delicious bookmarks. With decilicious shutting down soon , it could be useful

    9) Run a program transparently, but print a stack trace if it fails

    gdb -batch -ex “run” -ex “bt” ${my_program} 2>&1 | grep -v ^”No stack.”$

    For automated unit tests I wanted my program to run normally, but if it crashed, to add a stack trace to the output log. I came up with this command so I wouldn’t have to mess around with core files.

    The one downside is that it does smoosh your program’s stderr and stdout together.

    10) back ssh from firewalled hosts

    ssh -R 5497:127.0.0.1:22 -p 62220 user@public.ip

    host B (you) redirects a modem port (62220) to his local ssh.

    host A is a remote machine (the ones that issues the ssh cmd).

    once connected port 5497 is in listening mode on host B.

    host B just do a

    ssh 127.0.0.1 -p 5497 -l user

    and reaches the remote host’ssh. This can be used also for vnc and so on.

    11) Rename HTML files according to their title tag

    perl -wlne'/title>([^<]+)/i&&rename$ARGV,"$1.html"' *.html
    
    

    The above one-liner could be run against all HTML files in a directory. It renames the HTML files based on the text contained in their title tag. This helped me in a situation where I had a directory containing thousands of HTML documents with meaningless filenames.

Chat

Hi 👋, how can we help?