Friday, January 28, 2011

Remove empty lines from a file

Use awk to strip a file of empty line. Do it with

  awk ‘NF>0′ < text_file    

Check your laptop battery in Linux

If you run Linux off a laptop, you might want to check your battery status alt least once a year:

    grep -F capacity: /proc/acpi/battery/BAT0/info    

This will output something like

design capacity: 7800 mAh
last full capacity: 6414 mAh

Backing up the bootsector

Afraid you might mess up your MBR? Back up the bootsector:

    dd if=/dev/hda of=bootsector.img bs=512 count=1    

If anything goes wrong, you can boot from a LiveCD and restore the bootsector with

    dd if=bootsector.img of=/dev/hda    

Convert text between different encodings

Want to convert a subtitle file to a different encoding? Use

  iconv -f WINDOWS-1253 -t ISO-8859-7 subtitle_file.srt    

Limit the CPU usage of a certain application in Linux

You can do this by installing cpulimit. You can limit a certain running application either by name or by process ID:

  cpulimit -e firefox -l 30    

This won’t let Firefox go beyond a 30% CPU usage limit.
If you’d rather go by process, you can do it like this:

  cpulimit -p 3493 -l 40  

This will limit process number 3493 to 40% CPU consumption.

Mount Windows shares like normal drives in Linux

to have access to Windows shares and mount them like normal drives in Linux, use the smbmountcommand:

1
    smbmount “\\\\WINDOWS\\c” -c ‘mount /mount/Windows’ -I 192.168.0.3    

where “\\\\WINDOWS\\c” is the name of the share and /mount/Windows is the destination point. You need theSamba package installed for this as it contains the smbmount command.

Find out your router’s external IP address

To find out what external IP address your router has assigned to it, you can either search the Internet for sites that can display that said IP address or you can use the Linux command line:

    wget -O - -q icanhazip.com    

Find out active IPs in a Linux LAN

If you are on a LAN and wish to find out which computers in it currently have access to that certain LAN, you can use the following command:


    for ip in $(seq 1 254); do ping -c 1 192.168.1.$ip>/dev/null; [ $? -eq 0 ] && echo “192.168.1.$ip UP” || : ; done    

Monitor your changed files in real-time in Linux

Everybody knows top or htop. Ever wished there was something similar but to monitor your files instead of CPU usage and processes? Well, there is.
Run this:

    watch -d -n 2 ‘df; ls -FlAt;’   

Thursday, January 27, 2011

<pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;">  <code>  Some code here  </code>  </pre>

Display the current directory as a webpage in Linux

Display the current directory as a webpage in Linux

python -m SimpleHTTPServer

in the directory you wish to share, then access http://127.0.0.1:8000 in your browser.

File encryption with GnuPG

Encrypt file:

gpg -c private.txt

You will be prompted to enter a passphrase twice. The output is a file of the same name with ".gpg" as the extension.

Decrypt via:

gpg private.txt.gpg

By default the encrypted file is binary format with smaller file size. If you need ascii, then use the "-a" option which then outputs as "private.txt.asc".