We all need to look for word definition. Online dictionaries and wikipedia are great but we are not always connected to the net. sdcv is a console version of StarDict dictionary. Using sdcv you can search for definitions while still offline. So here are the step to install and make use of this great program.
Jargon File: “A comprehensive compendium of hacker slang illuminating many aspects of hackish tradition, folklore, and humor.” – From Jargon FileHomepage.
$sudo tar -xvjf downloaded.tar.bz2 -C /usr/share/stardict/dic or
$sudo tar -xvzf downlaoded.tar.gz -C /usr/share/stardict/dic
Note: Make sure the user who will be invoking the sdcv command has read and execute permissions on /usr/share/stardict/dic/ and its subfolders.
On Mac OS X
$mkdir -p $HOME/.stardict/dic
$sudo tar -xvjf downloaded.tar.bz2 -C $HOME/.stardict/dic
Note: Unfortunately you need to repeat this process for every user that needs access to these dictionary files.
Step 4. Enjoy sdcv
Searching for definition
$ sdcv Linux (looks for linux in the dictionary.)
$ sdcv (invoes sdcv in the interactive mode, press Control-D to quit).
In earlier article we covered how to use espeak, now you can combine sdcv and espeak together. Sdcv to look for definition and espeak for pronunciation.
$ sdcv Linux && espeak Linux
Here is a picture.
Note: Sometimes due to the long definition of a particular word text scrolls down too fast for you to read, advanced users can set SDCV_PAGER environment variable to /usr/bin/less. Now, less will be used to display to the dictionary’s article. You may consider adding this to your .bashrc file. Check out manpage for sdcv for more information.
Sometimes we want out Linux box to speak to/for us.This ability is very useful to make announcements and alerts in case of many critical events in our machines or can be used just for sheer fun. There exists a command line synthesized known as espeak that comes pre installed in Ubuntu. You can also install it on debian systems by typing the command sudo apt-get install espeak in a command console .For all other operating systems you can install it from source available at http://espeak.sourceforge.net/download.html The usage of espeak is pretty straight forward, just type espeak “text to announce” in a text console and listen your computer speaking the text.Some basic options to control espeak are :
a <integer> sets the amplitude/loudness of the speech
f <filename> speaks the content of the given file
p <integer> sets the pitch/frequency of the speech s <integer> sets the speed of the speech in words/minute
Espeak is a cross platform utility that runs on more than half a dozen of OS platforms. So go through its man page by typing man espeak in a text console , explore it more and make your machine speak.
Command line terminals are an indispensable part of *IXs. We all need those sooner or later. Usually we want to open many terminals at a time to do various things in those but placing them in the same screen is bit chaotic. We have an utility on GNOME desktop environment known as terminator that is able to create multiple terminals in same window. These multiple terminals could be created by horizontally, verticallly or tab dividing the window. Screenshot of the same is shown below :
Multiple Terminals
To install it on Ubuntu, issue command sudo apt-get install terminator. To launch it on ubuntu go to Applications -> Accessories -> Terminator . You can also type terminator in cli shell to launch it. If you want to install it manually then you can download it from their official page .
The basic key combinations are:
Ctrl+Shift+O for the horizontal division Ctrl+Shift+E for the vertical division, Ctrl+Shift+T for the tab division Ctrl+Tab to switch between the created terminals Ctrl+Shift+q to quit terminator.
The terminator supports a hell lot of functionalities like grouping ,automatic logging,multiple searching etc. For more info about the terminator, access its man page through man terminator command.
Wikipedia : One of the most important web portal in geek’s life. Whenever I need to search anything I use two things. First open up the Google and then search for the related wikipedia page. Exploring wikipedia page using shell is possible. Interested fact is that we can do it without even opening the cli browser. We can make wikipedia text query over dns for an ip address. I learned this trick from Ajay Sharma (ajayctk@gmail.com). Thanks to him for teaching me this wonderful trick. Let’s explore how to do it 🙂
We will use ‘dig‘ utility for this purpose. Dig is more popularly known as the DNS lookup Utility. You can find more about it using man pages. Syntax for the text based wikipedia query is : dig +short txt <keyword>.wp.dg.cx . For example if you want to look into the wikipedia page of Linux you need to type something like this : dig +short txt linux.wp.dg.cx . Screenshot of the same is attached below :
Making A Wikipedia Query In CLI
For multiple word search having spaces in between them you can use the traditional ‘\’ operator. To grasp the wikipedia page of Free Software Foundation (FSF) we need to type dig +short txt free\ software\ foundation.wp.dg.cx .
FSF Wikipedia Search
Only problem is its quite limited. I am trying to figure out a way through which we can look up the whole page but I think this much is also quite useful as most of the times we came to know about the product by reading one or two lines only. So play with wikipedia using Shell only 🙂
This is a part of my article which got published in the International Magazine “Linux For You” also popularly know as LFY. The article was published under the name of “Let’s Play With Emacs CLI” in the August 2010 edition. All the work done is under the creative common license as specified in the widgets also 🙂
Text Editors are very important tool for everyone, especially for the programmers. So let’s play with them 😀 I am going to discuss the basics of Emacs text editor in this post.
Emacs was developed by Richard Stallman under the GNU project and he released his Emacs source code under a similar free copyleft software license called the EMACS Public License. C and Emacs Lisp are the programming languages behind this editor. This editor is also known as “The King Of Editors”. Believe me, the title matches exactly with its unique features. The Emacs environment doesn’t seem intuitive at first glance and it doesn’t work like other editors and word processors but learning Emacs is very easy. The latest version of Emacs is 23.2 . It comes pre installed in most of the distributions. You can install it by typing “sudo apt-get install emacs ” (without quotes) on debian distribution. To install it manually download it from http://ftp.gnu.org/gnu/emacs/ . You can check your version by typing “emacs –version” in the terminal. Emacs is a cross platform text editor and I have tried it on windows as well. Emcas was designed by keeping in mind that users don’t have to waste their time in clicking mouse buttons (start using Emacs and you will feel the same).
Emacs has two modes – GUI and CLI . Type “emacs” in the terminal to get the graphical mode. Below is the snapshot of the graphical mode :
GUI Mode Of Emacs
Graphical mode can be useful if you are not much familiar with the command line of GNU/Linux. Our main focus in this article is on the CLI mode. You can start the CLI mode by typing “emacs -nw”in the terminal. You should get something like this :
Welcome to CLI mode of Emacs
Start a new file in Emacs by typing “emacs -nw filename” in the terminal and you should see a blank buffer. Emacs works on buffer system. Any thing you write will be there on your buffer. When you save the buffer, it gets permanently written on your disk. Default buffer in it is known as SCRATCH BUFFER. New file buffer should look something like the screenshot shown below :
New File
At the top is the menu bar like in the GUI interfaces but you hardly use it in the CLI. Below that is your buffer area where you can write your contents and data. Mode line is below the buffer. You can call it as the status bar of the editor. It gives you important information about your Emacs session and about the current buffer displayed in the window above it, including whether your latest changes were saved to disk or not , on what line number the cursor is at, how far into the buffer the bottom of the screen is (in percentage of the whole) and the current active features and settings of Emacs. Mini Buffer is below the modeline where Emacs displays the message relevant to any operations.
You don’t need to use the mouse in Emacs as there are many key bindings (combination of keys) in this editor. Key bindings starts with two most important and common key that are Ctrl and Meta keys. Meta key in case is Alt key or Esc key. I have already told you how to start the Emacs and now going to tell how to exit it because it doesn’t have a normal exit. To exit the Emacs, key combination used is Ctrl-x Ctrl-c. It means press Ctrlkeythen press xwhile still holding the Ctrl key and then press c while holding the Ctrl key. It exits the Emacs command line and you will again be in the terminal. In the mini buffer you will see the progress of your command while you are typing it. I am listing some important commands below that will help you to start your work initially on Emacs :
Key CombinationFunction
C-x C-s Saves the content in the buffer
C-x C-f Find a file, Start a file by giving location
C-x k Kill buffer
C-x b Switch between multiple buffer
C-p Move the cursor to previous line
C-n Move the cursor to the next line
C-f Move the cursor one letter forward
C-b Move the cursor one letter backward
M-f Move the cursor one word forward
M-b Move the cursor one word backward
C-a Move to beginning of line
C-e Move to end of line
M-a Move to beginning of sentence
M-e Move to end of sentence
C-_ Undo the change
C = Ctrl, M = Meta (Alt or Esc)
I hope this will be enough for you to start with the emacs. Believe me guys, it’s worth giving a try! In the next part , we will take a look about the different modes and functions used in Emacs and also their usages. Till then, explore more material on internet about it and have fun in the geeks way with Emacs.
Linux is generally considered as a geek’s operating system and I am completely agree with it. Linux is not only limited to work only. You can also enjoy a lot while working on it. There are many crazy commands which will bring a big smile on your face. Below we are going to discuss few out of them.
1. Oneko : This utility remembers me of the cat mouse game. Cat chases the mouse pointer regardless of its position. You have to download it from the repository by typing “sudo apt-get install oneko” (without quotes) in ubuntu .Then just launch it by typing oneko . You will see a cat following your mouse pointer. You can terminate this command by using the famous Ctrl-c.
2. Xpenguins: We all know about the relationship of the Linux with the penguin “Tux”. By using this utility you will see penguins dancing around your desktop. This command is partially GUI based but can be invoked using the CLI. You can install it by using “sudo apt-get install xpenguins” and can invoke it simply typing xpenguins on your terminal. To terminate follow the same Ctrl-c rule.
3. Fortune : You can generate famous quotes using this. It uses the random function during the generation. You can find it in the “fortune-mod” package. For the installation of the package you need to type “sudo apt-get install fortune-mod” . Launch it by typing fortune . You can add it in your bashrc file so that everytime you log in you see a message .
4. Cowsay and Xcowsay : Want to say something to anyone using a cow as a medium?? If yes this utility fits the best. CLI version is cowsay and GUI version is xcowsay . You can find them in the cowsay and xcowsay package respectively. To invoke follow the syntax : cowsay text (CLI) and xcowsay text(GUI) . Example – Let’s say “hello” through the cow.
cowsay hello
xcowsay hello
5. sl (oops ls) : As we all know that the “ls” utility (used for listing of files) is used at a very high rate in Linux. But sometimes due to high speed typing we typed it “sl” and “ls”. If you had “sl” utility installed you will see a train engine passing by in your command line warning you that you have misspelled the ls. Install sl by using “sudo apt-get install sl” and invoke it using sl.
There are lots of others crazy commands too. Google them and have fun!!!
We can classify all of the Linux/Unix commands into two types- Internal And External. Internal commands are the shell built-in commands while external commands are files present in the $PATH. (Remember we treat everything in the Linux as a file). Commands like pwd, cd ,echo comes under the category of the internal commands while ls,cp etc comes in the other category. To check whether the command is internal or external we will use the typeutility (type itself is internal one). Just type the name of the command after the utility and it will return you something like this –
Using Type Utility
If you got a message like “cd is a shell builtin” after the execution of the command it is an internal command. If you got something else it comes under the category of external commands (like cp in this case).
How Execution Takes Place : For the external commands, execution is possible only if the command file is present in the locations mentioned in the $PATH. Otherwise it will give you an error.If the command file is available , but the path to that file is not included in the PATH variable, it will show you an error. Internal commands don’t need files for their execution. Set of internal commands is stored in shell by default. Sometimes a command with the same name exist in both the categories. Example – echo (external one lies in the /bin/echo) . In this case shell will give preference to the internal echo first, then comes the turn of the external ones. So if you use the echo utility internal will get executed. External echo rarely gets executed (You can execute it in the shell by creating a subshell though).
There are two types of user interfaces Graphical User Interfaces (GUI) and command line interface (CLI). In GUI you use mouse to give instructions, in command line you type commands to control your computer. Linux provides two ways of exploring command line, you can either start a terminal emulator or switch to virtual console.
Terminal Emulator
Terminal emulator is a program that provides access to command line when you are in GUI. It opens up a window in which you can type commands. To start a Terminal Emulator look in the application menu.
Terminal Emulator
Virtual Consoles
Virtual Console Example
To switch to virtual console press <Ctrl><Alt><F1> i.e. press and hold control key then press and hold Alt, now press F1 key. It will give you a log in prompt where you can type in your username and press enter. Now type your password to login. While typing the password you won’t see it on screen. You can type commands after logging in. There are six virtual consoles by default. To switch to second one press <Ctrl><Alt><F2> and so on. To switch back to GUI press <Ctrl><Alt><F7> .
When you open up a terminal or login into virtual console it will show you something like
[username@hostname~]$ eg. My laptop shows [sumit@sumit-laptop ~]$.
The $ sign means that you are normal user, you only have limited powers. A root user has many more powers than a normal user, as a root user you change all the critical system settings. There are some commands that only a root user can run. To become a root user press enter after typing
su – [if you are using Slackware, Fedora or Red Hat based distribution.]
sudo -i [ if you are using Debian, Ubuntu].
It will ask for your root password please enter it and also it is important to note that while you
are typing the password it will not be displayed on the screen for security reasons press enter after your are done typing the password. For Ubuntu this password is same as your user password, Fedora and others asks you to set root password during installation.
After you become a root the prompt will look something like [root@hostnamename~]#.
Now you are root user. Since a root user can make critical changes and even delete important system files so be careful with what you type as a root user. Only login as root user when necessary.
Basic Linux Commands
In Linux the general syntax of any command is
command name [options] [arguments]
Options usually start with “–”
Example : In command ls -l /home, -l is option and /home is argument.
The things that are written in [] brackets means that they are optional i.e. you may or may not use them its your choice but you may use them to modify the behavior of command according to your needs. If you don’t use them some defaults options and/or arguments will be used.
To find out where you are in file system tree i.e. current directory type
[user@host~]$ pwd
/home/sumit
So by looking at the output we can say in am currently in /home/sumit directory.
2. ls – list directory contents
Now you know that you are currently in /home/sumit. Now you can type ls to list all the files and directories in /home/sumit directory.
ls command also acceps arguments and options like most of linux commands. Using ls with option -l i.e. Typing ls -l will give you more detailed output. If you type ls /home, the command will display all the files in /home folder. Here /home is taken as argument.
Output of pwd and ls
3. cd – change directory
You can you use cd to change you current directory (pwd). While using cd you can either specify relative path or absolute path. Relative path depends on your current directory (output of pwd command) i.e. their result depend upon your current location in file system tree, absolute paths always start from / and their result does not depend on your current directory. Ex – Let us say your current directory is /home/sumit and /home/sumit contains a folder named Documents. I can type “cd Documents” to go to Documents directory (relative path) or I can type /home/sumit/Documents. The former only works when my current directory is /home/sumit. If you type cd .. it will take you to the parent directory i.e. if you are in /home/sumit/ typing cd.. will take you to /home, now typing cd .. once more will take you one step higher to / directory.
Output with Cd
4. mkdir – make directories
You can use mkdir command to create new directories, here you can use absolute or relative paths just like cd command.
[user@hostname ~]$ mkdir dirname (create a directory named mkdir in current directory)
[user@hostname ~]$ mkdir /home/sumit/test2 (creates directory /home/sumit/test2 using absolute path).
5.Using Tab auto completion
Use can use auto completion to save time when typing commands or filenames. If you are typing mkdir command, just type mkd and press tab it will auto complete the command, if it doesn’t press tab twice and it will list all the commands that has mkd as its first three characters. Simiraly you can type
ls /ho and press tab is will auto complete the command to ls /home.
6.Using History
All the commands you type and stored in history. You can move b/w history by using upper and downward arrow keys on your keyboard, and press enter to execute.
Although u can also type Command-”history” and you will see that the commands you types in the past with a number. Want to run the command directly without typing again type “!number” and the command on that number will get executed. Here’s the screenshot
Histoy Command Output
Well thats it for now… Wanna know More abt the CLI Basics… Wait For Part-2