There are various ways to launch applications and run commands in Linux. Which method is best is a matter of personal taste and individual productivity needs. Here I will discuss some of the best methods available in Linux to do the common quotidian tasks easier and faster.
Command Prompt
The basic method of running commands is through the gnome-terminal, i.e. the command prompt in the Windows language. To run gnome-terminal, just press ALT+F2, type “gnome-terminal” and press the enter key.
Similarly, you can run other applications, like “gnome-system-monitor” the task manager equivalent of windows, “gnome-control-center” the control panel equivalent of windows, by using the Run Application dialog box. In the terminal window, you can run any command, redirect the output to a file, run commands from command history, etc.
n>&m – Swap Standard Output and Standard Error
You can redirect the output of a console application to any file descriptor like:
command > output.txt
This will create a new file and send the output to that file.
If you want to append the output to an existing file, like your logs file:
command >> logs.txt
By default the output (cout) goes to the file and the error (cerr) goes to the screen, by using this way.
But there may be situation where you want to run your program automatically and logs all standard error to a file and discard the standard output, means send the error to a file and normal output to the screen. In the Bourne shell you can do that using redirection.
command 2> errorlogs.txt
File descriptors 0 means standard input, 1 means standard output and 2 means standard error. There are other file descriptors from 3 to 9 used as temporary descriptors.
When using pipes, you need different way, as pipes doesn’t have names. You can say point 2 to where 1 is pointing, like:
command 2>&1 |
This means send the standard error to where the standard output is going.
To swap the standard output and the standard error you need to say:
command 3>&2 2>&1 1>&3 |
Think this as swapping a and b using temporary temp:
temp = b;
b = a;
a = temp;
Command History
| Command |
Description |
| history |
List the last 16 commands |
| history -c |
Clears the commands history |
| fc -l 20 30 |
List commands 20 through 30 |
| fc -l -5 |
List the last five commands |
| fc -l cat |
List the last command beginning with cat |
| fc -ln 5 > doit |
Save command 5 to file doit |
| fc -e vi 5 20 |
Edit commands 5 through 20 using vi |
| fc -e emacs |
Edit previous command using Emacs |
| !! |
Reexecute previous command |
| !cat |
Reexecute last cat command |
| !cat foo-file |
Reexecute last command, adding foo-file to the end of the argument list |
| !N |
Reexecute Command number N in history list. |
| !-N |
Reexecute Nth command back from current command. |
| !$ |
Last argument of previous command. |
Command Alias
You can also define command short aliases by adding the alias in the ~/.bashrc file.
gedit ~/.bashrc
alias ll='ls -l'
alias sysmon='gnome-system-monitor'
alias ins='sudo apt-get install'
You can also run the alias command in the terminal window to create an alias for that session only:
alias h='history'
unalias h
You can also use variables in the aliases like:
alias cdo="cd \"\$OLDPWD\""
Note: it is important, that there are ONLY double quotes in the expression above, no single quotes like in the other examples!
Global Hotkeys
You can also create hotkeys for the most commonly used programs by following the steps:
- Launch gconf-editor by typing in a terminal: gconf-editor.
- In gconf-editor choose apps » metacity » global_keybindings.
- In global_keybindings assign keyboard shortcuts.
- Select keybinding_commands (right below global_keybindings in the metacity menu).
- In keybinding_commands assign the custom commands you would like to launch with the keyboard shortcuts you created in step three.
Gnome-do
You can use gnome-do, this is similar to QuickSilver (Mac) or Launcy/wxQuickRun (Windows). Install the program and the plugins using the Synaptic Package Manager.
Just launch the program, and press “Win/Command key + Space Bar” and type your commands. Use the arrows keys for selecting various items, and the tab key to move to a different pane. You can also download additional plugins from the gnome-do repository and copy them to “~/.local/share/gnome-do/plugins“.
Dock Window
Ever like the cool Mac GUI effects and the docking window to launch your favorite application without searching through the maze of menus. Well now we have lots of docking managers for Linux also namely: Avant Window Navigator, Cairo Dock, wbar, etc.
SUSE Linux Favorite Application
SUSE Linux Enterprise Desktop 10 uses a desktop menu to help you launch applications. This menu has three sections: Favorite Applications, Recently Used Applications, and Recent Documents. You can add or remove any application to your favorite application section. This allows easy access to the commonly used application.
References