LinuxPlanet Blogs

By Linux Geeks, For Linux Geeks.

Archive for the ‘CLI’ Category

Finch, a command line alternative to Pidgin

without comments

I don't know in which scenario should I suggest you to use a console based IM client but I came across Finch for the first time while trying to save my laptop's battery life during power cuts by shifting to old school console . I am not sure whether my basic aim was fulfilled or not but it was fun seeing what ncurses could do :).

For starters, you don't need to start configuring finch just like you did with Pidgin the first time. It automatically takes all the required information from your home directory's .pidgin folder. This means, its exactly like Pidgin but on console. So, if you have been using Pidgin then you won't need to do any configuration on finch.

Install finch

In order to install it on Ubuntu/Debian based systems either click this link(help -> apturl, apt protocol) or run the following command in the terminal.

[shredder12]$ sudo apt-get install finch

I am not sure about Fedora/RedHat systems but try running this.

[shredder12]$ su -c 'yum install finch'

Now, in order to launch it just run the command finch on the terminal.

Finch shortcuts

Some basic key shortcuts are:

Alt + a Bring up a list of available actions. You can use this list to access the accounts window, plugins window, preference window etc.
Alt + n Go to the next window
Alt + p Go to the previous window
Alt + w Show the list of windows. You can select and jump to any window from the list.
Alt + c Close the current window.
Alt + q Quit Finch.
Alt + m

Start moving a window. Press the cursor keys to move the window. When you are done, press Enter or Escape.

Alt + r Start resizing a window. Press the cursor keys to resize the window. When you are done, press Enter or Escape.

These are just the basic ones which should be enough but a complete list check out its man page

[shredder12]$ man finch

Written by shredder12

May 26th, 2010 at 7:47 am

Posted in CLI,Linux,Pidgin,finch

Stop the Corruption! – Putty and Screen

without comments

I use putty to make ssh connections to my home server when I'm forced to use MS Windows, such as when I'm at work. The first thing I do after connecting is start up screen, which opens several pre-assigned applications in "tabs". Putty's default settings seem to cause screen corruption with some applications, notably newsbeuter, finch, links, mc and hnb.




Not pretty.

This is simply fixed with 2 settings in putty. First, in the putty configuration tool go to "Terminal" and check the box for "Use background colour to erase screen". Then select "translation" found under the "Window" section and change the character set to "uft-8" using the drop down menu.

Here are the results:



Written by Jared

April 16th, 2010 at 3:11 pm

Vim – Cut and Paste a Block of Text Between 2 Files

without comments

Vim is my editor of choice, but I would never consider myself an expert. So when I wanted to copy text from one text file to another in vim, I was challenged. Although I was frustrated for a brief moment, I remembered uncle google and he helped me with my conundrum. So here is how you cut and paste a section of text from one text file to another using vim.

First open your first text file in vim. Scroll down to the first line of the block of text you wish to copy and press "ma" (that is m followed by a, without the quotation marks). "m" marks the beginning of your block. The "a" makes the assignment of copying the text to buffer "a".

Now scroll to the end of the block of text you wish to copy and press "y'a" (again without the quotes). The "y" yanks the text block. The single quote in the middle, I guess designates the end of the block and "a" again identifies the buffer being used.

Next open the second text file by typing ":split filename.txt" (Remember no quotes). This will open the second text file in a split vim session window. Scroll to the line where you would like the text pasted and press "p" (You should know, don't include the quotes). This will paste the block of text on the line below the current cursor position. Save and your done.

Please leave comments with other examples of cutting and pasting in vim.
Enjoy.

Written by Jared

April 13th, 2010 at 8:19 am

Newsbeuter and Google Reader

without comments



If you go to the newsbeuter website you'll be told that it's the mutt of rss feed readers. It is text based and highly configurable. Newsbeuter is fairly easy to set up and configure. Just install newsbeuter using your distros package manager. It should be available on most distributions Ubuntu, Fedora, Opensuse, Arch, Slackware, Debian, etc.

Now that it's installed, just type newsbeuter in the terminal to start it. There's probably not much to see as we haven't added any RSS feeds yet, but I usually start an application before configuring it because usually there are configuration files that are created when an app first starts up. Press "q" to quit.

To add feeds open the ~/.newsbeuter/urls file and simply add your feed urls to that file. Save and close and you're good as gold. You can edit the ~/.newsbeuter/config file to customize your keybindings and other settings. See the man page for configuration options.

I recently learned that you can use newsbeuter to view your Google Reader feeds. To do this make sure you have the latest version of newsbeuter and simply add the following to your ~/.newsbeuter/config file.

urls-source "googlereader"
googlereader-login "your-googlereader-account"
googlereader-password "your-password"

Save and start newsbeuter. You now have your Google Reader Feeds.
Please see the newsbeuter documentation site for more configuration options.
Enjoy.

Written by Jared

April 2nd, 2010 at 7:00 am

id3 – Managing mp3 Tags

without comments

I listen to alot of podcast and very few of them actually use mp3 tags or they use tags that don't make sense to me. I have a sansa fuze media player which lists my podcast as "Season 3" or "Released as a Single" or simply "unknown". I mean how am I suppose to know what Season 3 is. Well, I've put a stop to the madness and use an application called id3 to change the mp3 tags, so I can have some sanity to my mp3 playlist.

One of my favorite podcast is for the TV show Lost, hosted by a father and son who discuss the show. The file name for the podcast is d66027dd-8873-2829-c731-97fcc5a62bb9.mp3. I know, but the name of the file really doesn't matter since the media player only really reads the tags associated with the file. To list the tags of the file:

id3 -l d66027dd-8873-2829-c731-97fcc5a62bb9.mp3


Which will give you the following output:

d66027dd-8873-2829-c731-97fcc5a62bb9.mp3:
Title : Lost Podcast (MP3): EP. 5.11 " Artist: Jeremiah Glatfelter
Album : Year: 2010, Genre: Unknown (255)
Comment:

My fuze displays this podcast as Jeremiah Glatfelter. Who the hell is Jeremiah? Maybe it's some inside joke or something, but the hosts of the show are Jay and Jack and that's what I would like displayed as the artist. So, to change the artist portion of the tag, I use the following:

id3 -a "Jay and Jack" d66027dd-8873-2829-c731-97fcc5a62bb9.mp3


Which outputs the following to show that the change has been made.

Title : Lost Podcast (MP3): EP. 5.11 " Artist: Jay and Jack
Album : Year: 2010, Genre: Unknown (255)
Comment:

Pretty straight forward. Here are the options to change the other aspects of the tags using the same syntax.

usage: id3 -[tTaAycg] `text' file1 [file2...]
id3 -d file1 [file2...]
id3 -l file1 [file2...]
id3 -L
id3 -v
-t Modifies a Title tag
-T Modifies a Track tag
-a Modifies an Artist tag
-A Modifies an Album tag
-y Modifies a Year tag
-c Modifies a Comment tag
-g Modifies a Genre tag
-l Lists an ID3 tag
-L Lists all genres
-R Uses an rfc822-style format for output
-d Deletes an ID3 tag
-h Displays this help info
-v Prints version info

Now you can tag to your hearts content.
enjoy.

Written by Jared

March 16th, 2010 at 10:04 am

My .bashrc File Part 5 – Pimping the Prompt

without comments


This is the final installment of my .bashrc series. PS1 is a variable that allows you to change your prompt environment. Here is my setting as found in my .bashrc file which I use to get the prompt above.

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

The numbers in the brackets represents colors. The \u option is username and \h is hostname which defines the first part of my command prompt. The second part of my prompt is indentified with /w which displays my current path which is shown above in blue.

Your possibilities are limitless when it comes to customizing your prompt and I don't have time here to list and explain all the options available, especially when the detail is readily available with a simple google search. Nevertheless, here are some links you might find useful to help pimp your prompt.

10 examples with syntax explanation.

This IBM article is a great resource as well.

I hope this series has been useful. Please share your pimped command prompt in the comments.

Written by Jared

March 10th, 2010 at 8:00 am

My .bashrc File Part 4 – Alias’

without comments

If you are unfamiliar with the alias command then you are missing out on an effective and efficient tool. Alias is a way to create a shortcut command in bash. You can take very long commands with several options or triggers and create your own shorthand equivalent of that long command. For Example, for me to get the weather for my local area using the weather-util application I would normally need to type:

weather -f --id=KSLC -c "Salt Lake City" -s UT

Well, that's way to long. I normally only want to know the weather in my local area, so I've created an alias for this long command.

alias weather='/usr/bin/weather -f --id=KSLC -c "Salt Lake City" -s UT'

This command essentially substitutes the longer command to display the weather for Salt Lake City with just the command "weather". I have several alias' in my .bashrc file to make my life easier.

# some ls aliases

alias ll='ls -l'

alias la='ls -A'

alias l='ls -CF'

#Information

alias weather='/usr/bin/weather -f --id=KSLC -c "Salt Lake City" -s UT'

alias gcalcli='gcalcli --cals all'

#For getting around

alias videos='cd /home/jared/Videos/ && ls'

alias pics='cd /home/jared/Pictures/ && ls'

alias music='cd /home/jared/Music/ && ls'

alias podcasts='cd /home/jared/Podcasts/ && ls'

alias dropbox='cd ~/Dropbox/ && ls'

alias documents='cd ~/Documents/ && ls'

alias notes='cd ~/Notes/ && ls'

alias manti='cd ~/Manti/jared/ && ls'

The first group of alias' are very common shortcuts for the "ls" command. The second group of alias' give me shortcuts for the weather and gcalcli applications which displays the weather and my google calendar information. Finally, the las group gives me shortcuts to commonly used directories. This saves me tons of time as I don't have to type out the complete path of a commonly used directory.

Please share some of your cool alias' that you have implemented.

Written by Jared

March 8th, 2010 at 8:00 am

My .bashrc File Part 3 – Making Life Easier

without comments

A very common thing to do in the command line is to extract compressed files. Now as many of you probably know there are a dozen different compression methods out there. Let's say I have a .bz2, .7z, .gz and a .rar file and I don't want to think about which app to use and what option I need to extract my file. I just want my file uncompressed. Let's make life a little easier and insert the following into your .bashrc file.

#------Extraction of compressed files--------------
# from ARCH Wiki

extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) rar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "don't know how to extract '$1'..." ;;
esac
else
echo "'$1' is not a valid file!"
fi
}

Now when you need to uncompress a file, simply type "extract filename" and slam-bam-thank-you-ma'am. No thinking or looking up the correct syntax, all you are left with is an uncompressed file and isn't that all we really wanted?

What fun things are you hiding in your .bashrc file that makes life easier? Please share.

Written by Jared

March 4th, 2010 at 8:00 am

Couple of Random Server Tips

without comments

1) If you are running a 64 bit version of OpenVZ on the Hardware Node, don't expect your 64 bit guests to work on a 32 bit host. 2) If you get an error saying asm/bitsperlong.h missing, then run make sure /usr/src/linux/include/asm/bitsperlong.h -> /lib/modules/2.6.31-gentoo-r10/build/include/asm-generic/bitsperlong.h is linked. 3) Do not be afraid.

Written by Andy

March 4th, 2010 at 4:53 am

My .bashrc File Part 2 – Useful System Information

without comments

In the last segment I discussed displaying some useful personal information using a function script within my .bashrc file. Today I'll discuss displaying useful system information. I have two funtions which display system information, which is set up very similar to my previous script.



This first script displays my internal IP address and my WAN IP address by simply extracting that information from ifconfig whenever I type "myip" in the terminal. Here is the script.




function myip() # get IP adresses
{
MY_IP=$(/sbin/ifconfig eth0 awk "/inet/ { print $2 } " sed -e s/addr://) \ MY_ISP=$(/sbin/ifconfig
eth0 awk "/P-t-P/ { print $3 } " sed -e s/P-t-P://)
}




This displays:




External IP:
xxx.xxx.xxx.xxx
Internal IP:
192.168.0.97




This second function displays my machine statistics, file system space available, memory stats and IP information, when I type "ii" in the terminal. Here is the function:




function ii() # get current host related info
{
echo -e "\nHello ${RED}$USER"
echo -e "\nSystem information:$NC " ; uname -a
echo -e "\n${RED}Machine stats :$NC " ; uptime
echo -e "\n${RED}Storage stats :$NC " ; df -h grep -v varrun grep -v varlock grep -v udev grep -v\ devshm
echo -e "\n${RED}Memory stats :$NC " ; free -m
echo -e "\n${RED}Local IP Address :$NC" ; ifconfig grep
'inet addr:' grep -v '127.0.0.1' cut -d: -f2 awk '{ print $1}'
echo -e "\n${RED}ISP Address :$NC" ; wget
www.whatismyip.com/automation/n09230945.asp -O - -q
echo ""
}



You'll notice that in this script, my outside WAN IP is pulled from a website instead of from the ifconfig command. Here is the output:




Hello jared

System information:
Linux manti 2.6.24-24-server #1 SMP Fri Sep 18 17:24:10 UTC
2009 i686 GNU/Linux


Machine stats :
10:02:17 up 81 days, 15:14, 10 users, load average: 0.15, 0.38, 0.37

Storage stats :
Filesystem
Size Used Avail Use% Mounted on

/dev/sda1 17G 3.0G 13G 19% /
/dev/sda2 276G 246G 16G 94% /home
/dev/sdb1 187G 146G 32G 82% /media/backup

Memory stats :
total used free shared buffers cached
Mem: 502 492 10 0 37 65
-/+ buffers/cache: 389 113
Swap: 1874 30 1844

Local IP Address :
192.168.0.97
ISP Address :

xxx.xxx.xxx.xxx


I apologize that not everything is lined up correctly, it's due to the layout in blogger. The output lines up fairly cleanly in the terminal.

Enjoy!

Written by Jared

March 3rd, 2010 at 8:00 am