Top 4 Terminal GUI Applications

Written by BinnyVA on June 19, 2009 – 1:19 am -

Terminal

Terminal GUI Apps? Does sound oxymoronic doesn’t it? Well, there are GUI apps in the terminal – and here is a tribute to ones that I find most useful…

top/htop – Process Viewer

From the man page…

The top program provides a dynamic real-time view of a running system. It can display system summary information as well as a list of tasks currently being managed by the Linux kernel. The types of system summary information shown and the types, order and size of information displayed for tasks are all user configurable and that configuration can be made persistent across restarts.

I always have a processor load displaying applet(System Monitor) in my panel. Whenever I see a spike, I fire up a console and type in the top command – its very useful in finding which process is creating the load. Usually, it is some cron job like updatedb or makewhatis. But occasionally, I find a zombie processes this way.

htop is, for the lack of a better word, a better top. It provides a more colorful display(top has a color mode as well – open top and press ‘z’). It also makes it a bit more easier to kill processes.

htop

mc – File Manager

mc(or Midnight Commander) is a file manager. Sure you can cp and mv your files around, but after a while, it gets tiring. mc is a dual pane file manager -it means you can see two folders at the same time. You can copy/move files from one to the other, delete, rename, view file etc – in short, everything a file manager is expected to have, mc has.

mc

mpg123 – Audio Player

I am not writing too much about this – considering the fact that I have already wrote a post about mpg123/mpg321 in the audio player series.

aptitude

aptitude is a ncurces based GUI for the apt package manage – as a result, this is only available in Debian based systems(Ubuntu, Knopix, etc.). I have not yet seen anyone using aptitude – if they have a GUI system, they use synaptic – and if they are comfortable with the command line, they use apt-get command. But still, there is a middle ground – if for some reason you need it.

aptitude

Thanks to Rajesh for the aptitude screenshot.

Anything Else?

Any other Terminal GUI application? I can only think of these at the moment. If you can think of others, comment.


Tags: , , , , , , , ,
Posted in Applications, Command Line, Reviews, Tools | 12 Comments »

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: 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 »

    fish(Friendly Interactive Shell)

    Written by BinnyVA on April 8, 2007 – 1:00 pm -

    fish(Friendly Interactive Shell) is a new shell for Linux. I tried it out and have decided to dump bash for fish. Try it out – you will come to the same conclusion as well.

    Features of fish

    Syntax Coloring

    The shell colorizes the commands as you type them – if it is a valid command it will have a green color. For example, lets say I want to see my network interfaces. Recently, I had a lot of use for that – but that is another post. So, I type ifconfig into the shell. When I am at ‘ifco’, the shell will be like this…

    Ifco - Typing completion

    When I have completed the command, ifconfig, the shell will be like this…

    Completed

    Strings, matching etc. are also highlighted as you type.

    Syntax Highlighting

    Tab Completion

    You would not think that this is a new feature. Bash has tab completion. Even Windows XP’s DOS terminal has tab completion. But fish’s tab completion is no ordinary tab completion – think of it as tab completion on steroids.

    fish’s tab completion implements a feature that I really needed – tab completion for subcommands. Subcommand is the command line argument that is given to some programs. For example,

    yum update gimp
    cvs commit file.php

    In the first example, yum is the command an ‘update‘ is the subcommand. Just type ‘yum upd’ and press Tab to complete the command. Similarly in the second case cvs is the command and commit is the subcommand.

    Many other completions are also supported…

    • Commands, both builtins, functions and regular programs.
    • Environment variable names (Eg. $HOME).
    • Usernames for tilde(~) expansion.
    • Filenames, even on strings with wildcards such as ‘*’, ‘**’ and ‘?’.
    • Job id, job name and process names for process expansion. This is very useful when using kill.

    Enough talking. You can download the fish shell from their official website. For Red Hat/Fedora Core users, this command will do the trick.

    yum install fish

    If you are a debian or Ubuntu user, use this command

    apt-get install fish


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