LinuxPlanet Blogs

By Linux Geeks, For Linux Geeks.

Archive for the ‘command line’ Category

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

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

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

My .bashrc File Part 1 – Useful Information

without comments

I thought it would fun to have a short series regarding my .bashrc file. Feel free to share any cool aspects or insights from your .bashrc file during this series. A short disclaimer for this series, regarding most of what I will be sharing with you is NOT original content. I've copied most aspects of my .bashrc from others who have been so kind to share their cool ideas. Now, lets begin.

I want to focus the first apart of this series on having bash display useful information in an easily accessible and concise way. For example, the first thing I do each morning is run my "update" script which displays the time, my schedule for the day and the weather, which looks something like this:

Hello jared, How are you today?

Current Date and Time:

Fri Feb 26 09:00:40 MST 2010

Your Schedule:
Mon Feb 22 12:00am Zone 4
Fri Feb 26 12:00am Safety Kids Fair

6:30am Scriptures
11:00am Preschool time
Sat Feb 27 9:30am Food Co-op Pick up

Current Weather Conditons:

Current conditions at UT (KSLC)
Last updated Feb 26, 2010 - 10:53 AM EST / 2010.02.26 1553 UTC
Wind: from the SSE (160 degrees) at 13 MPH (11 KT)
Sky conditions: mostly cloudy
Temperature: 35.1 F (1.7 C)
Relative Humidity: 69%
City Forecast for Salt Lake City, UT


Here is the script I use in my .bashrc file.

function update() # Current date, time, weather and calendar
(
echo -e "\nHello $USER, How are you today?"
echo -e "\nCurrent Date and Time: $NC " ; date
echo -e "\nYour Schedule: $NC " ; gcalcli agenda head
echo -e "\nCurrent Weather Conditons: $NC " ; weather head -n 7
echo ""
)

Let me run through this function. As you can see it's all just echo commands spewing out the information I desire. I begin by having bash say "Hello" to me. Just because it's a shell doesn't mean it can't be polite. Next it displays the current date and time which is followed by my schedule for the day. My schedule is produced by a cool little app called gcalcli which was a Google summer of code project that displays your google calendar on the command line. I blogged about this app previously here. I then finish things up with the weather using the weather-utils application. I have the weather command set up as an alias (which I'll cover in another segment) to display my local weather.

As mentioned previously, this is the first command I type into the terminal when I first wake up, which gives me a quick and concise outlook for the day.

Well, I hope this was interesting to some of you. My next installment will cover displaying useful system information. So until then... enjoy!

Written by Jared

March 1st, 2010 at 8:00 am

Catching up with Arch Linux

without comments

Let's begin with a little update. I've been off-line for a few months now, mostly due to a new job and just feeling like I needed a break. Recently though, I've been having the urges to blog again, mostly due to Quvmoh putting the audio of my presentation "Life without a GUI" from UTOSC on HPR. (thanks Quvmoh) This also reminded me that I need to put my slides up from the presentation which you can find here. Use the tpp application to view them as slides or any text editor will work as well. You can also download my handout of the presentation here. The handout will give you useful links for file conversion and the syntax for playing video in the framebuffer.

The last time I blogged I was praising Slackware, but since then I've moved on to Arch. Don't get me wrong Slackware is awesome, but there was one unforgiving issue that caused me to dump Slack for Arch. It was the lack of supported software for Slackware. I just couldn't find everything I wanted on the main repo or on slackbuild.org or anywhere else. One example of this was tuxpaint for my son. I just could not get it installed on my 64-bit system. After hours of frustration without any progress I was done. This is tuxpaint for heaven's sake, it shouldn't be this hard, especially when I could easily just "apt-get install tuxpaint" on Debian/Ubuntu or "yum install tuxpaint" on Fedora or "pacman -S tuxpaint" on Arch.

And speaking of pacman... WOW! I'm in love. It really does put apt to shame. It is so fast. I literally blink and applications are installed. More praises for Arch, include the rolling release methodology. I always have the latest and greatest stuff and everything is stable. I just can't say enough about it. I recommend everyone to give it a try.

Finally, I've been throwing around the idea of doing a Linux command line podcast. I figure it's a niche topic that's not exclusively covered in any other linux podcast. I would cover alot of what my UTOSC presentation was all about, "How to live life and get everything done in the command line." Topics I might cover could include: How to deal with various office document formats, How to blog from the command line, How to email and view attachments from the command line, How to do photo editing from the CLI, discuss how to use the various apps listed on my CLI apps list or maybe interview the developers of these apps, and so on. For the 2 people out there that read my blog let me know what you think. If anyone is interested and would like to co-host that would be great. Now all this being said, I really don't know anything about podcasting so if anyone could give me some tips or advice or just point me in the right direction that would be greatly appreciated.

Written by Jared

February 22nd, 2010 at 10:16 am

Redirected Domain

without comments

I love DynDNS. It's a great service. Using this service, I've registered cli.homelinux.net and redirected jaredandcorlee.com to that domain.

The new CLI domain better fits the subject matter on the site. If you haven't checked out the site, please give it a look over. Understand that it still needs work, but definitely stop by the CLI applications list which is the core focus of the site. Also, please send your CLI suggestions and site recommendations.

Written by Jared

July 17th, 2009 at 8:51 am