Customizing the Terminal: 6 Command Line Tips and Tricks

Written by BinnyVA on April 26, 2009 – 9:06 pm -

Terminal

A few tips and tricks on the terminal to make you more efficient when using it. If you know of any other tips, add it in the comments section.

1. ls Without ls

When you are trying to cd into a deep folder, you might not know the correct folder name some levels deep. You might have to do something like…

$ cd ~/Scripts/Perl
$ ls
bin	SedGUI       ToSee	Cronjobs  Maintenance
$ cd Maintenance

There is an easier way – go to the wanted folder

$ cd ~/Scripts/Perl

Now, without pressing enter, double tap the TAB key. You will get a list of files. And the command prompt waiting to be filled…

$ cd ~/Scripts/Perl/[TAB TAB]
bin	SedGUI       ToSee	Cronjobs  Maintenance
$ cd ~/Scripts/Perl/_

You can also use double-TAB to auto-complete commands.

2. Searching the history with Ctrl+R

If you have to use a command you have already used before, press CTRL+R and then type a few characters of the command. The latest command with those characters will be shown – if that is the command you want to execute, press enter and it will be executed. If not, just press CTRL+R again and it will show the next command.

You have no idea how useful this tip is if you haven’t been using it. I use this all the time.

For more details, read this article.

3. Open Terminal using a Shortcut

If you are a GUI user, chances are you prefer using a Terminal emulator(like gnome-terminal or konsole) instead of going into the Terminal mode by pressing CTRL+ALT+F1. If so, assign a shortcut to those emulator apps. I prefer using the shortcut ‘Ctrl+Alt+A’ to do this.

Gnome

If you are in gnome, there is a very easy way to do this…

  • Go to System > Preferences > Keyboard Shortcuts
  • Find ‘Run a Terminal’ – assign the shortcut ‘Ctrl+Alt+A’

KDE

  • Right Click on the K-Menu > Menu Editor
  • Find your terminal application in the list(usually System > Terminal Applications > Terminal)
  • Select the ‘Current Shortcut Key’ option and set it to ‘Ctrl+Alt+A’

You can also do this by opening the KHotKeys application.

4. Bash Keyboard Shortcuts

Learn the bash keyboard shortcuts – these are the ones I use the most…

CTRL+R
Search the history. We already talked about this.
CTRL+L
Clears the screen. Use this instead of the clear command.
CTRL+D
Use this instead of the exit command.
CTRL+C
Kill whatever is running
CTRL+Z
Puts whatever is running into a suspended background process. Use fg to restore it.

5. Find Command using apropos

Find the command you want using the apropos command. Just type in a description of the command as the first argument. For example, lets say you want to find the command to list the directory contents. Use the command…

$ apropos "directory contents"
dir                  (1)  - list directory contents
ls                   (1)  - list directory contents
ls                   (1p)  - list directory contents
ntfsls               (8)  - list directory contents on an NTFS filesystem
vdir                 (1)  - list directory contents

The only problem is that I can never spell ‘apropos’ – so I keep this in my .bashrc file…

alias apox='apropos'

6. Learn New Commands

There are a few sites that publish cool commands on a daily/semi-daily basics – subscribe to those and learn new commands…

  • Txt – Linux Commands and Code Snippets – My own site – I wrote about this a while ago.
  • commandlinefu.com
  • shell-fu
  • Bash Snippets
  • Codesnippt.com – Shell Scripts
  • bash code

  • Tags: , , , , , ,
    Posted in Command Line, Configuration, Tools | 5 Comments »

    Customizing the Terminal: 5 Configuration Settings in Bash that makes you a CLI Power User

    Written by BinnyVA on April 13, 2009 – 1:10 am -

    Terminal

    There are some settings that are very useful if you work on the terminal a lot. Many of the cool ones are not enabled by default – this is a small list of the configuration settings that I use to make my terminal usage more productive.

    This is part 3 of the Customizing the Terminal series. Already published posts in this series are…

    1. Case Correction

    I like to title case my folders and files’ names. The folders in my home are ‘Scripts’, ‘Documents’, ‘Temp’ etc. The first character is in upper case. But when I work on the command line, I don’t always remember to uppercase the first character when trying to cd into a folder. Consequently, the tabbing will not work. Fortunately, there is an option that auto corrects the case for you. Just open a terminal and type in this command…

    shopt -s nocaseglob

    Other useful shopt option are…

    cdspell
    Corrects typos in your file/directory name.
    histappend
    Makes sure that histories in multiple simultaneous shells don’t overwrite each other.

    2. Select Which Commands to Store in History

    By default, all commands you type in are stored in the history. You can pick and chose the commands you want to store by putting the option…

    export HISTCONTROL=ignorespace

    in your ~/.bash_profile file. This will make sure that bash don’t store any command beginning with the space character. So if you want bash to forget that you typed in ‘ls’, just type in ‘ ls'(<space>ls).

    3. Don’t Store Duplicate Commands in your History

    As I said earlier, all commands you type are stored – even the duplicate ones. You can prevent this by putting this text in your .bash_profile file…

    export HISTCONTROL=ignoredups

    If you want to ignore spaced commands and want to prevent storing of duplicate commands, use the option…

    export HISTCONTROL=ignoreboth

    4. Auto-complete Command from History

    Picture this – you type in ‘ssh’ and press the ‘Page Up’ key – and bash automatically fetches the last command that starts with ssh – and completes the command for you. Well, its possible – add the following line in your ‘.bash_profile’ file…

    export INPUTRC=$HOME/.inputrc

    Now, create a file called .inputrc in your home and enter this into it…

    #Page up/page down
    "\e[5~": history-search-backward
    "\e[6~": history-search-forward

    Yes, I am aware of the up Ctrl+R trick – that comes in the next post.

    5. Infinite History

    You can increase or decrease the size of the history by adding this line in the .bash_profile file…

    export HISTSIZE=500
    export HISTFILESIZE=500

    This will limit the commands to be stored in the history to 500. If you want to remove the limit use these lines…

    unset HISTSIZE
    unset HISTFILESIZE

    There is a good chance that this will make your history file quite huge – use with care.

    Please share your configuration settings for bash in the comments.

    Related Links


    Tags: , , , , , , ,
    Posted in Command Line, Configuration | 6 Comments »

    Customizing the Terminal: Create Useful Aliases

    Written by BinnyVA on March 28, 2009 – 12:35 am -

    Terminal

    This is part two of the ‘Customizing the Terminal’ series. Part one is ‘Customizing the Terminal: The Prompt‘. In this part, we’ll see how to create aliases to make working in the console easier.

    How To Create an Alias

    You can create a temporary alias using this command…

    alias new_name='old command'

    This will stop working when you exit the terminal. If you want to make the alias permanent, put the same command in your ~/.bashrc file.

    There is another way to create an alias – create a executable file and place it in a folder in your path. This is not technically an alias – but it works the same way. I use this for alias that tend to change often. Its easier to find a file in a folder and edit it. YMMV.

    My Aliases

    This is a incomplete list of the aliases I use. Feel free to copy them to your .bashrc file.

    Quick Directory Jumps

    Create an alias to jump to folders you have to visit often. This is my list…

    alias www='cd /var/www/html'
    alias e='cd /mnt/x'

    Relative Jumps

    The above jumps are absolute jumps – relative jumps are possible too…

    alias ..='cd ..'
    alias ...='cd ../..'
    alias ....='cd ../../..'
    alias .....='cd ../../../..'

    Some prefer this syntax…

    alias ..='cd ..'
    alias ..2='cd ../..'
    alias ..3='cd ../../..'
    alias ..4='cd ../../../..'

    Often Used Commands

    If you use some commands a lot, create smaller alternative for it…

    alias x='exit'
    alias q='exit'
    alias rmdir='rm –rf'

    Many of my own scripts are also alias’ed this way…

    alias bk='perl "/home/binnyva/Scripts/Perl/Maintenance/Rsync Backup/RsyncBackup.pl"'
    alias rbk='perl "/home/binnyva/Scripts/Perl/Maintenance/Rsync Backup/RsyncRemoteBackup.pl"'
    alias nbk='perl "/home/binnyva/Scripts/Perl/Maintenance/Rsync Backup/RsyncNetworkBackup.pl"'
    alias bdb='perl "/home/binnyva/Scripts/Perl/Maintenance/Database Backup/Dbbackup.pl"'

    Complex Commands

    Create a short version of long and complex command using alias…

    alias gitstat='git status | perl -pe "exit if(/Untracked files\:/)"'
    alias ra='ruby script/server'
    alias wikipedia='cd /mnt/x/Data/Wikipedia/mywiki; firefox "http://localhost:8001/"; python manage.py runserver 8001; '
    alias sup='svn update'

    and more.

    Command Changes

    When I came from Windows to Linux, I was used to the dos commands – but not to the linux’s mv,cp commands. So I used to have aliases for those(I don’t have these now)

    alias move='mv'
    alias copy='cp'
    alias ren='mv'
    alias del='rm'

    If you go from Red Hat/Fedora to Debian/Ubuntu(or vise versa), you can set up a few alias to make the change easier…

    alias yum='apt-get'

    You can get a lot of ideas for more aliases by looking at others .bashrc files.

    Now tell me you aliases…


    Tags: , , , ,
    Posted in Command Line, Configuration | 15 Comments »

    Customizing the Terminal: The Prompt

    Written by BinnyVA on March 10, 2009 – 11:34 pm -

    Terminal

    Most Linux ‘gurus’ spend a lot of time working in the terminal. If you belong to that group, this post is for you. This is a tutorial to configure the terminal prompt to the best possible value for your use. Note: This tutorial is for bash users – these instructions will not work in other shells.

    The Prompt

    You must have seen the prompt if you have use the terminal – it is the first few characters in each line. Usually, it will be…

    [username@localhost] ~ $

    In this case, the user is shown three piece of information in the prompt –

    • Username of the current user
    • Hostname
    • Current folder name

    This post will show you how to customize this prompt to your needs.

    Editing the Prompt

    Editing the prompt is very simple – you just have to edit a shell variable. To see the current prompt’s value, open a shell and type the command…

    echo $PS1

    The result will be something like this(in Ubuntu)…

    binnyva@binlap:~$ echo $PS1
    \[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$

    Which is functionally the same as…

    \u@\h:\W\$ 

    To edit this variable, run the command…

    export PS1=<New Prompt Value>

    Most desktop systems don’t need the username and hostname in the prompt – this is only relevent if your are connected to a remote system. So the first thing to do, if you are on a desktop system, is to remove those two. To do that, run the command…

    export PS1="[\W]\$ "

    This will change the prompt in the current terminal. To make it permanent, edit the ~/.bashrc and set the PS1 variable there. Just add this line at the end of the file…

    export PS1="[\W]\$ "

    A Better Prompt

    Currently, the prompt has the basename of the current working directory. That is, if we are in ‘~/Sites/Lindesk/posts’, the prompt will be ‘[posts]$ ‘. This is good enough for most people. But I have a problem with this. If I go to another folder, say, ‘~/Sites/OpenJS/posts’, the prompt is still ‘[posts]$ ‘. The prompt is a bit ambiguous in this case. This can be done using a different character – in this case \w(small ‘w’ – the default was capital ‘W’).

    [posts]$ export PS1="[\w]$ "
    [~/Sites/OpenJS/posts]$ _

    This is nice – but you will have a problem if the directory you are in is several levels deep. It might be something like this…

    [/var/www/html/sites/Lindesk/lindesk.com/wp-content/plugins/eventr/langs]$ _

    That’s long – and inconvenient. There are better ways of doing this.

    Show the Beginning and the End.

    A better way of doing this is to cut of a part of the folder – so the above path will look something like…

    [/var/www/html.../eventr/langs] $ _

    This option will show the first 15 characters of the path and then the last 15 characters – if the directory path is bigger than 30 characters. To enable this mode, open up the file ~/.bashrc and add this code…

    PROMPT_COMMAND='DIR=`pwd|sed -e "s!$HOME!~!"`; if [ ${#DIR} -gt 30 ]; then CurDir=${DIR:0:12}...${DIR:${#DIR}-15}; else CurDir=$DIR; fi'
    PS1="[\$CurDir] \$ "

    The First Character of Each Directory

    There is yet another method – I got this idea from the fish shell. In this approach, the big path will appear as…

    [/v/w/h/s/L/l/w/p/e/langs] $ _

    In this option, only the first character of each parent folder will be shown. Only the base folder name will be shown entirely. This is the approach I use. If you want to use this, open the ~/.bashrc file and add this…

    PROMPT_COMMAND='CurDir=`pwd|sed -e "s!$HOME!~!"|sed -re "s!([^/])[^/]+/!\1/!g"`'
    PS1="[\$CurDir] \$ "

    Prompt Variables

    The other values you can insert into the prompt are…

    \d
    the date in “Weekday Month Date” format (e.g., “Tue May 26”)
    \D{format}
    the format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation. The braces are required
    \e
    an ASCII escape character (033)
    \h
    the hostname up to the first ‘.’
    \H
    the hostname
    \j
    the number of jobs currently managed by the shell
    \l
    the basename of the shell’s terminal device name
    \n
    newline
    \r
    carriage return
    \s
    the name of the shell, the basename of $0 (the portion following the final slash)
    \t
    the current time in 24-hour HH:MM:SS format
    \T
    the current time in 12-hour HH:MM:SS format
    \@
    the current time in 12-hour am/pm format
    \A
    the current time in 24-hour HH:MM format
    \u
    the username of the current user
    \v
    the version of bash (e.g., 2.00)
    \V
    the release of bash, version + patch level (e.g., 2.00.0)
    \w
    the current working directory, with $HOME abbreviated with a tilde
    \W
    the basename of the current working directory, with $HOME abbreviated with a tilde
    \!
    the history number of this command
    \#
    the command number of this command
    \$
    if the effective UID is 0, a #, otherwise a $
    \nnn
    the character corresponding to the octal number nnn
    \\
    a backslash
    \[
    begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
    \]
    end a sequence of non-printing characters

    Tags: , , , , ,
    Posted in Command Line, Configuration | 22 Comments »

    Recovering Deleted Data in Linux Ext3 Filesystem: Use Trash Can

    Written by BinnyVA on January 25, 2009 – 11:55 pm -

    Deleting Files to the Trash

    As most of you know, Ext3 file system don’t have to be defragmented like the FAT32 or NTFS file systems. This is a nice feature – but this has a bad side effect as well. You cannot recover deleted files. This is a good trade-off in a server environment. Its not practical to run a defragmenter on a live server. It might take hours to complete – and disk access will not be allowed in that time. And most server environment have very strong backup mechanisms – so data recovery is not a big issue. But when it comes to the desktop environment, this is a very Bad Thing.

    From a desktop user perspective, it is not a huge deal to run a defragmenter once in a while. I used to do it once every month or so when I was on windows. But accidental deletion is a huge problem as most desktop users don’t have a very strong backup system in place.

    In Windows(FAT32 or NTFS) if you want a deleted file back, there are file recovery software available that might recover the file. There is a good chance of getting back the file in one piece if you try to recover the file soon. But this is not possible in Ext3 – the way the file system is designed makes it next to impossible. This is because the file system will overwrite the deleted portions – to prevent fragmentation of files. The advantage of this method is that fragmentation will be avoided. The disadvantage is, well, you will not be able to recover deleted files.

    Solution: The Trash

    There is a very simple solution to this problem – but it is something no self respecting geek will use. The Recycle Bin. The Trash Can. Use it.

    The problem is I have not seen anyone other than total newbies delete files into the Trash. Most people I know use the Shift+Delete shortcut to delete. I use a slightly different shortcut – Shift+Delete, Enter. That means I don’t even see the deletion confirmation prompt. And if when I delete something important, the only thing left to do is cry.

    I have several backup systems in place – but you know the Murphy’s law when in comes to backups…

    You have a backup of everything – except the file that was deleted

    So, start using the Trash – do a delete instead of a shift+delete. I would advice removing the confirmation dialog on the delete action to make it go faster. You can do it easily in Konquorer…

    • Open Konquorer
    • Setting > Configure Konquorer…
    • Behavior > Ask Confirmation For
    • Make sure the ‘Move to trash’ checkbox is turned off.

    I am sure this is possible in Nautilus as well – but I am not sure how to do it. If any of my readers is a gnome user, please post a comment on how to do it.

    One last thing – remember to clean the trash once every two days or so.


    Tags: , , , , , , ,
    Posted in Configuration, Opinion, Troubleshooting | 13 Comments »

    Creating Custom Service Menus in Konqueror

    Written by BinnyVA on October 7, 2008 – 12:23 am -

    If you are using Konqueror and have not used custom service menus, you are missing out. Just like the Nautilus Scripts in Nautilus, Konqueror also has the ability to customize the context menus. This post will show you how to do it.

    We are going to create two different kind of service menus – one will create an item in the action part of the right click menu. The next type will create a submenu in the ‘actions’ menu with multiple menu items. Hopefully, you will get an idea about how to do it by yourself.

    Single Item Service Menu

    This service menu will create a menu item in the Action section of the context menu for all ISO files. For this to work as intended, the mimetype for ISO file must be application/x-iso .

    • Open ~/.kde/share/apps/konqueror/servicemenus folder
    • Create a file with the name ‘PlayISO.desktop’ – the name can be anything – but the extension must be ‘.desktop’
    • Enter the following content…
    [Desktop Entry]
    ServiceTypes=application/x-iso
    Actions=PlayISOInXine
    
    [Desktop Action PlayISOInXine]
    Name=Play ISO File in Xine
    Icon=player_play
    Exec=xine -pq --no-splash dvd:/%f
    

    Now lets see a line by line explanation of the code.

    [Desktop Entry]
    Start the file with this line.
    ServiceTypes=application/x-iso
    This decides which all file types must this service menu be shown to. You can find the mimetype for various files by taking Control Center > KDE Components > File Associations. Then search for the extension in the given text field.
    Actions=PlayISOInXine
    Name of the action – this will be defined in the next line
    [Desktop Action PlayISOInXine]
    The definition of the ‘PlayISOInXine’ action goes here.
    Name=Play ISO File in Xine
    The text to be shown in the menu item.
    Icon=player_play
    The icon to be used in the menu. The icon can be an absolute path or the file name of an image in your current theme(for example, if you are using Crystal SVG theme, then the images you can use is in the folder ‘/usr/share/icons/crystalsvg/16×16/actions’).
    Exec=xine -pq –no-splash dvd:/%f
    The command to be executed when the menu item is clicked. The %f stands for the full name of the file. The other options are listed in the documentation.

    This is the end result…

    Submenu Service Menu

    This sample will give you the option to convert the selected html file to a plain text file or a compressed archive. The code looks like this…

    [Desktop Entry]
    ServiceTypes=text/html
    Actions=convertToText;convertToZip
    X-KDE-Submenu=Convert
    
    [Desktop Action convertToText]
    Name=Convert To Text
    Icon=txt
    Exec=lynx -dump "%f" > "`dirname "%f"`/`basename "%f" ".html"`.txt"
    
    [Desktop Action convertToZip]
    Name=Compress as Zip
    Icon=tar
    Exec=zip "`dirname "%f"`/`basename "%f" ".html"`.zip" "%f"
    

    Again, a line by line explanation…

    [Desktop Entry]
    You know.
    ServiceTypes=text/html
    This is only for HTML files – so we specify the mimetype as text/html
    Actions=convertToText;convertToZip
    We have two different actions instead of just one as in the last case. So we provide the name of both actions separated by a ‘;’.
    X-KDE-Submenu=Convert
    This will make sure its shown in a submenu – and that the name of the submenu is Convert.
    [Desktop Action convertToText]
    Defining the first action – convertToText
    Name=Convert To Text
    The label of the menu item
    Icon=txt
    And its icon
    Exec=lynx -dump “%f” > “`dirname “%f”`/`basename “%f” “.html”`.txt”
    This command will convert a html file to a text file and put the resulting file in the same folder as the html file.
    [Desktop Action convertToZip]
    Defining the next action – convertToZip
    Name=Compress as Zip
    Label
    Icon=tar
    And Icon
    Exec=zip “`dirname “%f”`/`basename “%f” “.html”`.zip” “%f”
    The command to compress the html file as a zip file.

    If done correctly, it should look something like this…

    Related Links


    Tags: , , , , , ,
    Posted in Applications, Configuration, KDE | 2 Comments »

    Adding Support for almost All Video Formats/Codecs in Linux

    Written by BinnyVA on September 13, 2008 – 12:25 am -

    Multimedia

    There is an over abundance of video formats right now – fortunately, our favorite OS, Linux, is capable of handling all of them. But some video formats are not supported ‘out-of-the-box’ – in such cases, we have to install the necessary codecs. This guide will show you how install the codecs for just about every video format under the sun.

    Before going into the topic further, let me pacify the flamers in the audience. There are many codecs that include DRM and many are proprietary – and for this reason, many distros refuse to support them. But these can be supported using external software – whether or not to do that is a choice I leave to the readers. I am only handling the technical issue of installing the codecs here. The moral and ethical concerns have been handled by others better than me.

    The Players – Video Trinity

    There is no shortage of video players in linux. Among these, three players are more prominent than the others – these are Mplayer, Xine and VLC. I call them the Video Trinity. Before doing anything, install all three players. Yes, all of them.

    Mplayer

    Mplayer is perharps the most popular among linux video players. You can install it in a Red Hat/Fedora system using this command(the command for debian/ubuntu systems will be similar – can someone post it in the comments?)…

    yum install mplayer mplayer-fonts mplayer-gui

    If you are on a Debian based system – like Ubuntu, use this command…

    apt-get install mplayer mplayer-fonts mplayer-skins

    Xine

    xine is a free multimedia player. It plays back CDs, DVDs, and VCDs. It also decodes multimedia files like AVI, MOV, WMV, and MP3 from local disk drives, and displays multimedia streamed over the Internet. It interprets many of the most common multimedia formats available – and some of the most uncommon formats, too. Installing xine is just as easy…

    yum install xine xine-lib xine-skins xine-lib-extras-nonfree 

    Again, on a Debian/Ubuntu system, use the command…

    apt-get install xine-ui

    VLC

    VLC media player is a highly portable multimedia player for various audio and video formats (MPEG-1, MPEG-2, MPEG-4, DivX, mp3, ogg, …) as well as DVDs, VCDs, and various streaming protocols. VLC is popular in the windows crowd as well. Here is the command to install it…

    yum install vlc

    Debain/Ubuntu uses should use the command…

    apt-get install vlc

    With these 3 players installed, you must be able to open 90% of the video files out there. But for the more exotic video formats, we must install the extra codecs provided by mplayer. First install the codes available in your distro’s repository – in Fedora(with Livna repository) the command I used is…

    yum install gstreamer libdvdcss gstreamer-plugins-ugly audacious-plugins-nonfree-mp3 kdemultimedia-extras-nonfree ...

    Or in Debian/Ubuntu system

    apt-get install gstreamer0.10-plugins-ugly gstreamer0.10-plugins-ugly-multiverse gstreamer0.10-plugins-bad gstreamer0.10-plugins-bad-multiverse gstreamer0.10-ffmpeg

    Essential Video Codecs

    The binary codec packages provided by mplayer adds support for codecs that are not yet supported natively, like newer RealVideo variants and a lot of rare formats. Note that they are not necessary to play most common formats like DVDs, MPEG-1/2/4, etc. Take a look at the codec status table for the list of currently supported codecs in Mplayer.

    Instructions for installing binary codecs can be found in the README or in the README.txt file that accompanies each codec package. Detailed usage instructions are in the codecs section of the documentation. A brief overview of the installation procedure is given below...

    Installing the Codecs

    First, download the codecs package that matches your system. In most cases, that is Linux x86.

    First, extract the file to a local directory. There should be 64 files(currently). Next, we have to copy this to the system's codecs folder(usually /usr/local/lib/codecs/). To do this, you must have root user privileges...

    sudo cp -R essential-20071007/ /usr/local/lib/codecs/

    Voila - we have installed the codecs. But we are not done yet. Some players look for the codecs in other folders - to accommodate those players, we have to link the other folders to the central codecs directory. To do that, run these commands(as root)...

    ln -s /usr/local/lib/codecs/ /usr/lib/codecs
    ln -s /usr/local/lib/codecs/ /usr/lib/win32
    ln -s /usr/local/lib/codecs/ /usr/local/lib/win32
    

    Playing the Video

    Now open up the video you are trying to play in any video player(say mplayer) - in 99% of the cases, it will play without any issues. In the unlikely event of a problem, open up the same video in xine. If it still does not play, go to vlc. Your video will be working in atleast one of these three players.

    Did it work for you - let me know in the comments...


    Tags: , , , , , ,
    Posted in Configuration, Troubleshooting, Video | 14 Comments »

    MPD – Music Player Daemon

    Written by BinnyVA on April 14, 2008 – 11:48 pm -

    MPD is not for everyone.

    Before continuing into the article, a word of warning. MPD is not for everyone. If you are a casual desktop linux user with zero geek genes, stay away from this player. There are many other simpler players for you.

    But then again, ‘casual desktop linux user’ – that sounds like a contradiction in terms. The very fact that you are reading this means that you are a geek.

    Getting Started with MPD

    Setting up MPD is not as simple as other music players.

    Installation

    To see MPD in action, first we have to install MPD – and a client. I installed the following…

    • MPD server
    • MPC – A command line MPD client
    • gmpc – A GUI client for Gnome

    In a RedHat based system, you can install these using the command…

    yum install mpd mpc gmpc

    Configuration

    Here is where it starts to get a bit confusing. MPD don’t have a pretty GUI to go along with it. It has to be configured using a text file. Create a file ‘.mpdconf’ in your home folder and enter the following in it…

    
    port					"6600"
    music_directory         "~/Songs"
    playlist_directory      "~/.mpd/playlists"
    db_file                 "~/.mpd/mpd.db"
    log_file                "~/.mpd/mpd.log"
    error_file              "~/.mpd/mpd.error"
    

    The ‘music_directory'(“~/Songs” in our example) must point to the folder where you keep your music. If you have your music in multiple folders then I cannot help you. MPD was designed with just one music root directory in mind.

    It is a good idea to create the playlist folder now – it will prevent errors later on. To do that run the command…

    mkdir -p ~/.mpd/playlists

    Next run these commands…

    mpd --create-db
    mpc update
    mpc add /
    mpc play

    If all went well, you must be hearing sweet music now. Here is an explanation of the commands we used and their purpose…

    mpd –create-db
    This will start the daemon. The ‘–create-db’ argument will read the contents of the root music directory and add the Music files to a text database. You should see the list of files being added into the DB. This may take some time to complete – based on size of your music collection.
    mpc update
    The command used here is ‘mpc’ – not ‘mpd’. We are using a command line client now. This command scans the root music directory for updates.
    mpc add /
    This command will add all the files in the music directory to the current playlist. Please note that the ‘/’ here means root music directory – and not the global linux root.
    mpc play
    This will start playing the files in the current playlist.

    GUI Clients

    There are many GUI clients for MPD – the ones I would recommend are…

    • Gnome Music Player Client(gmpc)
    • Sonata

    Once the mpd daemon is up and running, just open these clients and click on the connect button to control the daemon using these clients.


    Tags: , , , , ,
    Posted in Audio, Configuration | 4 Comments »

    Sound Issue in Fedora 8

    Written by BinnyVA on November 14, 2007 – 5:48 pm -

    Music

    Today I upgraded my system from Fedora 7 to Fedora 8. The installation process went very smoothly. But once the installation was done, I started the long process of configuring it. That’s when I ran into the sound issue in Fedora 8 – and based on the forum posts, so did many others.

    Basically, you get this error at KDE startup…

    Sound Error Informational Message:
    Error while initializing the sound driver:
    device: default can't be opened for playback (Permission denied)
    The sound server will continue, using the null output device
    

    You will not be able to play any sound – amarok will crash if you try to play anything. But if you run system-config-soundcard(or System -> Administration -> Soundcard Detection), you will be able to hear the test sound. That is because you are running it as root.

    Solution 1 – Console-Kit Service

    Did you turn of Console-Kit and avahi-daemon startup services using system-config-services? If so, go back and re-enable them.

    • Run system-config-services(or System -> Administration -> Services)
    • Find Console-Kit and enable it
    • Find avahi-daemon, enable it
    • Restart the system and see if that fixed the problem.

    This worked for me – so I did not try any of the following solutions.

    Solution 2 – alsa-plugin

    If the first solution did not solve the problem, try removing the pulseaudio plugin for alsa by running this command.

    yum remove alsa-plugins-pulseaudio

    Solution 3 – Permissions

    If neither of the above work, open /etc/security/console.perms.d/50-default-perms and add this line to the top…

    <sound>=/dev/dsp* /dev/snd/*

    And at the end, add this line…

    <console> 0666 <sound> 0600 root

    Related Links

    Hopefully, your problems are solved by now. If not, here are some links to help you further…

    More about Fedora 8 in the next post.


    Posted in Audio, Configuration, Fedora, Troubleshooting | 31 Comments »

    Five Amarok Tips and Tricks

    Written by BinnyVA on October 10, 2007 – 11:43 pm -

    Amarok

    Rating

    If the rating feature is turned on you can rate the songs from the player…

    Settings -> Configure Amarok -> General -> Use Rating = On

    Ratings in Amarok

    Song Information Fetching

    Amarok can automatically fetch information about the current song from the internet

    Lyrics

    Context -> Lyrics

    This will fetch the lyrics of the current song from http://lyrc.com.ar and display it within amarok.

    Lyrics in Amarok

    Singer Details

    Context -> Artist

    Fetches the Wikipedia page for the singer of the current song.

    Album Cover

    Right Click Song -> Edit Track Information -> Summary
    Right Click on the CD Cover Image -> Fetch from Amazon.com
    Click on the ‘Next’ button until you find an Image you like and then click ‘Save’.

    Plugins/Extensions/Scripts

    If you want more from amarok, you can install some Amarok plugins(they are called ‘Scripts’ in amarok)

    If you did not find the plugin you need, you can write your own plugin.

    OSD for Current Song

    It is possible see the title of the current song without opening amarok.

    Settings -> Configure Global Shortcuts -> Show OSD = Ctrl+Shift+Q(for example)

    Now whenever you press that shortcut, a small OSD will popup showing the name of the current song and the artist.

    Browse the Amarok DB

    Amarok stores all the information in a SQLite database(by default). This can be found at ‘~/.kde/share/apps/amarok/collection.db’. You can browse through it with a software capable of opening SQLite. You will find playlists, albums, fetched lyrics etc.

    I have not found a practical use for this – yet. If you find any, let me know.

    More Tips…


    Posted in Applications, Audio, Configuration | 6 Comments »