Showing posts with label cli. Show all posts
Showing posts with label cli. Show all posts

September 10, 2008

How-To: Install Video Codecs and DVD Support in Ubuntu/Kubuntu 8.04 'Hardy Heron'

Medibuntu is a project somewhat similar with debian-multimedia.org for Debian, providing packages which are not included in the official Ubuntu repositories due to legal issues. In order to make use of the packages included in Medibuntu (including the non-free video codecs w32codecs and libdvdcss2 for watching ecrypted DVDs), you will only need to follow several easy steps explained below.

1. Add the Medibuntu repository address to /etc/apt/sources.list
Edit as root the /etc/apt/sources.list file (e.g. sudo nano /etc/apt/sources.list or kdesu kate /etc/apt/sources.list) and add the following two lines:

deb http://packages.medibuntu.org/ hardy free non-free
deb-src http://packages.medibuntu.org/ hardy free non-free

2. Update the packages list
Issue the following command:

sudo apt-get update

3. Install the w32codecs and libdvdcss2 packages
To install those two packages, just type in the command:

sudo apt-get install w32codecs libdvdcss2

It should be done now. The codecs will be installed in /usr/lib/codecs/ and the DVD library in /usr/lib/libdvdcss2.so.2.0.8.

Another way to install libdvdcss2 is to first install the package libdvdread3:

sudo apt-get install libdvdread3

And then running the command:

sudo /usr/share/doc/libdvdread3/install-css.sh

As video players, I recommend SMPlayer and Kaffeine, the first using the MPlayer engine, while the latter uses the Xine engine. They both have subtitle support and many powerful features (like remembering video position and settings after closing the application in SMPlayer), and Kaffeine also reads DVD menus.

SMPlayer 0.6.0 running in Kubuntu 8.04

To install either of those, use one of the commands below:

sudo apt-get install smplayer
sudo apt-get install kaffeine

Updated: Sep 10, 2008 (Created: Sep 10, 2008)

July 08, 2008

How-To: Use cdparanoia to Rip Audio CDs

cdparanoia is a command line tool which reads audio CDs and allows you to rip the tracks to WAV files. You can then take those and compress them as FLAC or using a lossy format like Ogg Vorbis or MP3. The last stable release is cdparanoia III 10.0, which is included in Debian Lenny's repositories. To install cdparanoia on Debian, issue the following command as root:

apt-get install cdparanoia

The easiest way to use it is to insert an audio CD and rip all the tracks to default WAV format:

cdparanoia -B

The default output files will be located in the current working directory, under names like track01.cdda.wav, track02.cdda.wav, and so on.

Ripping an audio CD with cdparanoia

Alternately, you can rip only a single track or several tracks:

cdparanoida -B 5

Will rip only track 5, while:

cdparanoida -B 3-7

Will rip all the tracks from 3 to 7, including them. You can also rip a track starting at a certain time up to a certain time. For example, to rip track 2 from seconds 35 up to minute 2 and 30 seconds, you would issue:

cdparanoia "2[:35.00]-2[2:30.00]"

There are plenty more arguments which cdparanoia accepts and for more options see cdparanoia --help and man cdparanoia. You may also find useful the FAQ on the official website.

Updated: Jul 08, 2008 (Created: Jul 08, 2008)

How-To: Use apt-file to See What Files a Package Installs

Install apt-file

apt-file is a tool which allows you to see what files contains a package in the repositories, without the need to necessarily install it. It also allows searching for files inside packages. To get it on Debian Lenny, type as root:

apt-get install apt-file

Next, update the cache:

apt-file update

This will take a while.

Using apt-file

1. Search for a specific file in all the packages

apt-file search file_name

For example, try this:

apt-file search ogg123

ogg123 is a command line player for Ogg Vorbis included in the vorbis-tools package on Debian. However, if you don't know the exact name of the package but you know the tool's name (in this case, ogg123), you can search for it. Here's the output:

$ apt-file search ogg123
irssi-scripts: /usr/share/irssi/scripts/ogg123.pl
python-pyvorbis: /usr/share/doc/python-pyvorbis/examples/ogg123.py
vorbis-tools: /usr/bin/ogg123
vorbis-tools: /usr/share/doc/vorbis-tools/examples/ogg123rc-example
vorbis-tools: /usr/share/man/man1/ogg123.1.gz

So you can see that the package vorbis-tools contains the binary which will get installed as /usr/bin/ogg123.

Using apt-file to search for a specific file without knowing the exact package name

2. List files in a given package
Let's try to list all the files which a specific package will install. Here are the first entries from the output of the command apt-file show vorbis-tools:

$ apt-file show vorbis-tools
vorbis-tools: /usr/bin/ogg123
vorbis-tools: /usr/bin/oggdec
vorbis-tools: /usr/bin/oggenc
vorbis-tools: /usr/bin/ogginfo
vorbis-tools: /usr/bin/vcut
vorbis-tools: /usr/bin/vorbiscomment
vorbis-tools: /usr/bin/vorbistagedit

3. Purge the cache
To purge the cache generated by apt-file update, use:

apt-file purge

As root. You will have to create the cache again with apt-file update.

# apt-file purge

$ apt-file show amarok
E: The cache directory is empty. You need to run 'apt-file update' first.

For more details about apt-file, use the help and the manual page:

apt-file --help
man apt-file

Updated: Jul 08, 2008 (Created: Jul 08, 2008)

July 07, 2008

How-To: Mass-Rename Files Using an Easy Method

You may find this useful to rename MP3 or image files in a directory, so they will all look the same.

The following script will work on directories with less than 100 files of the same type, and will rename all of them to file01, file02, file03, ... and so on.
j=1; 
for i in *; do

if [[ $j -lt 10 ]]; then
mv "${i}" "file0${j}";
fi;
if [[ $j -ge 10 && $j -lt 100 ]]; then
mv "${i}" "file${j}";
fi;
j=$(($j+1));
done
You can only use it for certain types of files in a directory, like this:
j=1;
for i in *.ogg; do
if [[ $j -lt 10 ]]; then
mv "${i}" "audio0${j}.ogg";
fi;
if [[ $j -ge 10 && $j -lt 100 ]]; then
mv "${i}" "audio${j}.ogg";
fi;
j=$(($j+1));
done
This will rename all the Ogg files in a directory to audio01.ogg, audio02.ogg, audio03.ogg, and so on. You can test it for whatever files you like, however make a back-up first, since you can accidentally rename files or even directories which you don't want renamed.

Updated: Jul 07, 2008 (Created: Jul 07, 2008)

July 06, 2008

13 Command Line Tools for Audio on Linux

cmus
cmus is a music player using the ncurses interface, with a Vi-style of maneuvering it. For example, you will type :a ~/music/ to add directory ~/music/ to the playlist, and :q to quit.

For those who like the Vi editor, cmus will probably make a great CLI audio player

ogg123
Official Ogg Vorbis player included in the vorbis-tools package, this nice command line player will also read Vorbis tags and play your audio files encoded as Vorbis.

mpg123
This is the well-known command line MP3 player.

oggenc
Official tool from xiph.org capable of encoding from FLAC or WAV to Ogg Vorbis. It takes many options as arguments, like bitrate or quality.

flac
flac will encode and decode FLAC files (Free Lossless Audio Codec), and also convert FLAC to WAV and vice-versa. It has many parameters available and you can also select the compression level. FLAC is a format which lately got popular since it offers lossless audio quality at lower compression sizes than WAV, and it's completely free.

vorbiscomment
Included in the vorbis-tools package, this tool allows to edit or remove any tag(s) from an Ogg Vorbis file. You can also add any tag name and value. I use this in scripts to perform several edits on tags, like the one below, which clears all the tags in an Ogg Vorbis file:

#!/bin/bash

echo "OGG Tag Remover"
echo "Creating empty file..."
touch file

echo "Starting to remove all tags in OGG files..."
for i in *.ogg; do
echo "Executing command 'vorbiscomment -w \"$i\" -c file'..."
nice -n 15 vorbiscomment -w "$i" -c file
done

echo "Removing empty file..."
rm file

echo "Done! All tags removed."

cuebreakpoints
Used together with shnsplit, cuebreakpoints helps you split FLAC or WAV files according to a CUE file.

shnsplit
From the manual page, shnsplit "is a command‐line utility to view and/or modify WAVE data and properties". Use it with cuebreakpoints to split WAV or FLAC files like this:

cuebreakpoints audio_file.cue | shnsplit audio_file.flac

mp3blaster
mp3blaster is a popular MP3 and Vorbis player with a TUI (Text User Interface).


ogginfo
Shows detailed information about Ogg files.


mpd
The Music Player Daemon is a server that allows to play audio files, like FLAC, MP3, Ogg Vorbis, WAV and AIFF. You will also need a client, like mpc for CLI or Sonata for GUI.

ripit
According to the manual page, ripit is a 'Perl script to create .flac .ogg .mp3 or .m4a (aac) files from an audio CD.'

music123
music123 is a CLI audio player which can play Ogg, MP3, WAV and it behaves pretty much like mpg123 or ogg123.

Conclusion
As a conclusion, you may ask if these are really useful considering there are so many good-looking and full-featured GUI audio players out there. Well, yes, they are! I use oggenc, ogginfo and flac all the time, I like those over any GUI frontend. mpd can prove very useful for those who like to have a music server on their own PC or remotely connect to it from another. mp3blaster is just great if you want to use less resources, and eventually leave the player somewhere in a console window. As for mpg123 and ogg123, well I used those heavily in the past on an old AMD K6/2 with Debian 3.1, when I used to work a lot only in command line, without starting the X Window System.

Not to mention frontends like soundKonverter, where those powerful tools are used for encoding/decoding and converting between formats.

Here is a tutorial I wrote on how to use flac, oggenc, shnsplit, cuebreakpoints and vorbiscomment for manipulating audio files.

Updated: Jul 07, 2008 (Created: Jul 06, 2008)

See What Are Your Most Used Shell Commands

This script looks into history and prints up the 10 most used commands issued in the shell:

history | awk '{print $2}' | awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -n | tail | sort -nr

Example output on my system, freshly installed for about a week:

55 ls
37 cd
27 apt-cache
14 su
10 j=1;
10 file
9 ps
8 killall
8 dcop
8 clear
The script itself was taken from here. UbuntuForums is a great resource for these kinds of scripts, and there are several threads there about it too.

Updated: Jul 06, 2008 (Created: Jul 06, 2008)

July 05, 2008

5 Reasons to Use CLI Over GUI

First, I must say that using CLI is not always faster, not necessarily. There are tasks which can be done faster and easier using some GUI application rather than typing a whole bunch of commands. But, nevertheless, command line is still very powerful and it's more appropriate to use it for certain tasks. I for one use probably 90% GUI tools and applications and only in 10% of the cases CLI. So, you may ask, what's the scope of this? Well, in the first place, this article is about the reasons I believe to be noteworthy for using CLI in several situations, and what advantages it has.

Some prefer GUI, others CLI, and others (including me) prefer both. In the future I'll probably make an article listing 10 reasons to use GUI over CLI, but until then, here are the main reasons I use my share of CLI applications.

1. Complete control over the system. This may vary. What I'm trying to say is that I got used to do some task using some CLI tools instead of a graphical application. Now using that application makes me wonder whether it will pass exactly the arguments I wanted to the command line tool or use some defaults which I don't want. Not once I saw a graphical application based on some CLI tool which only implemented half of its options, so I wasn't able to make it what I actually wanted.

2. Powerful for many tasks. CLI is often more powerful than GUI applications for specific tasks. For example, consider having a directory with hundreds of different file types in it. Moving, copying, eventually renaming them would be very hard in a GUI file browser. Selecting almost each of them with the mouse while pressing CTRL is not easy for such a big number of files and it also takes up more time. While on CLI, you can use one single command in order to perform whatever task and it's done.

3. Ability to use scripts. I have several small scripts in my ~/bin/ directory, which in Debian is detected and included by default in the $PATH. So I can run specific commands over some files in just one command and a parameter. This is very useful if you have some specific need or want a specific behaviour with some tool, which is not implemented in any graphical application.

4. Less memory. For whom it matters, using command line won't make the system load additional libraries which are not already loaded for some GUI application.

5. Ability to use aliases. Aliases are a great feature implemented by shell applications which allow a user to perform one or more commands using one simple, easy to write command, called an alias. The ability to use those often makes work easier.

Please share your advantages (if any) you may think of for using CLI whenever a GUI alternative is available.

Updated: Jul 05, 2008 (Created: Jul 05, 2008)

June 21, 2008

'uname -a' Explained

uname is a command used to print the system information. uname -a will output all the available information this tool can provide regarding the system. For example, the output of uname -a will look something like:

$ uname -a
Linux debian 2.6.24-1-686 #1 SMP Thu May 8 02:16:39 UTC 2008 i686 GNU/Linux
$

What does is mean?

Linux is the kernel name, in this case, Linux
debian is the machine's hostname (not the distribution name, in this case the hostname just happens to have the same name as the Debian distribution)
2.6.24-1-686 is the kernel version
#1 SMP Thu May 8 02:16:39 UTC 2008 - SMP stands for symmetric multiprocessing, denoting that the CPU (central processing unit) is using two or more CPUs; what follows is the current system date
i686 is the CPU architecture
GNU/Linux is the operating system name

This information can also be retrieved using only certain options, like uname -r which will only return the kernel version, or uname -m for hardware architecture.

$ uname -m
i686
$

uname won't show the distribution version, but this can usually be obtained using other commands, specific for each distribution. For example, on Debian you would use cat /etc/debian_version, which will output something similar to:

$ cat /etc/debian_version
lenny/sid
$

Updated: Jun 21, 2008 (Created: Jun 21, 2008)

June 20, 2008

A Compilation of Libraries You Might Need on Debian

This post lists the necessary libraries needed to either compile or run several applications on Debian Lenny. For the applications already included in the repositories (like Amarok, Wine, Banshee and so on) use this guide. Make sure to always try apt-get build-dep application_name first, then see if you really need some other dependencies. This is not a general-purpose guide, it's mostly KDE oriented and lists dependencies for programs I need and use, yours might or might not be in this list.

build-essential - GNU Compiler Collection and several other utilities needed for compiling software (this is essential if you plan to compile from source)

kdebase-dev - headers and development libraries needed to compile most KDE applications

lsb-cxx - required by the QtCurve KDE3 style

libxpm-dev - required by KDocker

libstdc++5 - required by many programs, UT2004 among them

libqt0-ruby1.8 - required by Wiki-Lyrics Amarok script

python-qt3 - required by ConTEXT Amarok script

libboost-dev - required by Wesnoth

pyste - required by Wesnoth

konq-plugins - required by Ark for Konqueror integration

ident2 - ident daemon, required by Konversation (not essential)

ntpdate - keeps your date synchronised with an Internet server

libglib1.2-dev - required to compile XMMS

libgtk1.2-dev - required to compile XMMS

Just use apt-get install library_name as root in order to install any of the above.

Updated: Jun 19, 2008 (Created: Jun 19, 2008)

June 19, 2008

How to Get Help When X Refuses to Start

I'm sure many of us had this problem, and not only once: for some reason or another, the X Window System refuses to start and you get stuck in console. I remember an event also referred to as the 'Black Ubuntu Day', when an update crashed X. As far as I remember, I had no problem since I didn't restart my X server after the upgrade and a fix was available after a few hours, but thousands (or maybe more, can't tell the number exactly) of other users couldn't log into GUI any more.

Usually it's just a wrongly configured mouse or driver selected in the /etc/X11/xorg.conf file, but in other cases the problem seems harder to get solved at first sight.

Well, don't despair at this point: I can't tell you what exactly is the problem, but I can recommend two of the most useful applications in such a situation: a CLI (command line interface) client for IRC (internet relay chat) and a CLI web browser. There are many IRC clients out there for use in a console, like BitchX (I'm not sure if it's still maintained), Irssi or Epic4. The same goes for web browsers: some of the popular ones are w3m, lynx, elinks or links. All you need is a working internet connection. You can then install these applications using the package manager of your distribution, for example in Ubuntu this is done using sudo apt-get install lynx irssi.

All of these applications work in command line, and with an IRC connection and a web browser, your solution will be close. Well, the web browser is slower to use and can't display images, but at least you can browse for help instead of staring at the shell.

So, the two applications I recommend to always have installed are Irssi and lynx. I always have those installed even though I only use Irssi, just in case. You will also need a text editor, and nano or vim come installed by default on all the distributions I tried.

IRC is a text chat protocol used for almost 20 years. Despite its age it still remains one of the most used protocols for chatting and support out there. Every decent distribution has a channel on Freenode (or OFTC in Debian's case), with hundreds of users at any given time.

To get on IRC, just start irssi and type /connect irc.freenode.org. Next, join the channel for your distribution. For example, if you use Ubuntu, type /join #ubuntu. And start saying what your problem is, soon enough somebody will notice you and eventually offer the needed help. To quit Irssi, just type /quit. There are unwritten rules for using IRC, also known as the 'netiquette'. Usually, don't ask to ask in support channels, don't send private messages unless you first ask the person on the channel if that's OK with him, don't start flame wars, and you'll be just fine. You'd be surprised to know that most of the persons who use to read and spend a good amount of time on forums, are amazed by the fact that they learn on IRC more in 20 minutes than they learn an entire day on a forum.

As for lynx, I recommend starting it using the command lynx www.google.com. Navigate using the arrows until the search bar is focused, then try searching for terms related to your problem.

Updated: Sep 13, 2008 (Created: Jun 19, 2008)

June 16, 2008

Tutorial: Easy Minimum Debian Installation

Notice: I published an updated version of this tutorial here, for Debian Lenny.

Debian Lenny installs by default the entire X Window System and the GNOME desktop environment.

In order to have only a minimum and basic Debian installation, when the installer reaches to the window where it asks you to select which software you want to install (including Web Server, Desktop Environment, Basic System and several more options), deselect Desktop Environment and make sure Basic System remains selected (use SPACE to select/deselect options).

After Debian installs the basic system, it will ask for a reboot, then it will present you with a nice shell login. Login as user, type su, then enter your root password. Now you'll be logged on as root, so be very careful with the commands you issue.

Next, to install a desktop environment, issue one of the following commands:

For KDE:

apt-get install x-window-system-core kdm kde-core

For GNOME:

apt-get install x-window-system-core gdm gnome-core

The first one will install the X window system, the K Display Manager, and only the basic libraries and applications KDE provides, while the last one will install the GNOME Display Manager and GNOME's libraries and basic applications.

Now everything should be in place, so it's time to fire up the GUI:

/etc/init.d/kdm start

Or, for GNOME:

/etc/init.d/gdm start

Login with your username and that should be all.

Updated: Jun 16, 2008 (Created: Jun 16, 2008)

June 15, 2008

Top 10 Command Line Applications for Linux

1. irssi - IRC client
Irssi is a very powerful and highly configurable IRC client. It can be configured in any way possible and it supports Perl scripts. Documentation on the official website is abundant.

2. ttv - television application
ttv can prove useful if you have a TV-Tunner and (someway, somehow) you don't have X installed. It uses ASCII characters for the output, and the quality is increased if you use a higher console resolution.

3. emacs - IDE, text editor, email client
Emacs was developed and maintained by the GNU founder, Richard Stallman. It's a complete IDE (Integrated Development Environment), and can be also used as an email client or basic file manager.

4. lynx - web browser
Lynx is a popular CLI web browser. It displays websites with lots of text decently. Why use a CLI web browser when there are so many graphical nice ones out there? I don't, but it wasn't only once when I had no X and had to troubleshoot problems only with a command line and an internet connection available.

5. nano - user-friendly text editor
Nano is a simple and intuitive text editor. It's probably the command line text editor which every new user learns the first time. It's not Vi, but it's configurable enough if you want to do basic programming or text editing.

6. ogg123 - OGG Vorbis player
Part of the vorbis-tools package, this is a good player for those of us who like our music collection in OGG Vorbis instead of MP3. It displays information about the currently playing song and accepts parameters with wildcards (i.e. ogg123 Led_Zeppelin_-_*.ogg).

7. mpg123 - MP3 player
A very popular MP3 player, mpg123 offers many options for playing MP3 files.

8. mc - file manager
I always preferred ls, pwd, cd (and so on...) over any console file manager, but some might find the features in Midnight Commander very useful. Midnight Commander is the most popular file manager which can run without X. It's not exactly a CLI application, benefiting of a TUI (Text User Interface). Or maybe both combined, if I am to consider that it still includes a Bash prompt.

9. wget - download application
wget is an internet downloader, extremely easy to use.

10. ssh - secure remote login
ssh (secure shell) is used in order to login to remote computers and perform tasks just like you were logged at that computer as a normal user. It is very useful when you have a web server you need to maintain.

Updated: Jun 15, 2008 (Created: Jun 15, 2008)

June 10, 2008

How-To: Change Console Resolution

The standard size of the console is 80 columns and 25 lines, which is too big if you want to work easily in console and don't even use a desktop environment (or use one but also prefer to do things in console rather than an X terminal). It will also look nicer when booting up the system.

To change the resolution and colour depth of the console you need to edit the /boot/grub/menu.lst file and add one parameter to the line containing the kernel to boot. On a Debian Lenny system, this should look something like:

title Debian GNU/Linux, kernel 2.6.24-1-686
root (hd0,0)
kernel /boot/vmlinuz-2.6.24-1-686 root=/dev/hda1 ro quiet vga=791
initrd /boot/initrd.img-2.6.24-1-686

The new parameter added is vga=791, which means a resolution of 1024x768 with a colour depth of 16 bits per pixel (65,536 colours). Some other VGA modes would be:

791 - 1024x768, 16 bit
792 - 1024x768, 24 bit
794 - 1280x1024, 16 bit
795 - 1280x1024, 24 bit

After you restart the system and boot in console mode (if a graphical desktop environment is loaded, just press CTRL+ALT+F1 to go into console mode, and CTRL+ALT+F7 to go back), you'll notice the resolution is now changed, and you can see more now than the standard 80 columns and 25 lines.

Updated: June 10, 2008 (Created: June 10, 2008)

June 09, 2008

How-To: Kill a Process Using the 'pidof' Command

If a process hangs and you want to easily kill it, type in a console:

kill -9 $(pidof process_name)

And replace process_name with a currently running process. For example, to kill Amarok you would issue the following:

kill -9 $(pidof amarokapp)

Or Banshee, as another example:

kill -9 $(pidof banshee)

Or

kill -9 $(pidof banshee-1)

pidof is a command that finds the process ID (PID) of a given application. What is inside the ( and ) parenthesis is replaced with a certain PID, and the process which has that PID will be killed.

Updated: June 09, 2008 (Created: June 09, 2008)

June 02, 2008

Get Used to the Command Line in Linux, Part 3

Notice: This is the third part of the series Get Used to the Command Line in Linux. You can find the first two parts here (basic concepts) and here (basic system maintenance).

Part 3: Shell built-ins

Shell built-ins are commands included in the Bash program. Simple commands you give to the shell like cd, echo or pwd are all shell built-ins.

To see if a command is a stand-alone program or a shell built-in, use the type command:

$ type cd
cd is a shell built-in
$ type bash
bash is hashed (/bin/bash)

If the specified command is an alias, the output will be something like:

$ type ls
ls is aliased to `ls --color=auto'

You can use the help built-in to see a list of Bash commands, and help to see detailed help about each command.

The following describes several shell built-ins:

cd change current/working directory
help display helpful information about built-in commands
echo output the arguments given to it
pwd print the current working directory
bg place each job specified as argument in the background
fg place the job specified as argument in the foreground and make it the current task


Updated: June 09, 2008 (Created: June 01, 2008)

May 28, 2008

Get Used to the Command Line in Linux, Part 2

Part 2: Basic System Maintenance

Using find to search for files

The most common way of using find is:

find /path/to/search/directory -name "filename"

For example:

find /home/pink -name "*.png"

Will search for all the files with the .png extension in pink's home directory. Notice the star (*), which is a wildcard, and stands for 'any number of characters or no character'. The same result can be obtained by replacing pink with $USER, but first try:

echo $USER

Which will echo the username of the person currently logged on at the shell. Let's say you want to search for all the files in your home directory which have digits in them. You'll do:

find $HOME -name "*[0-9]*"

The [0-9] is also a wildcard, like *, and the shell will expand it into all the digits from 0 to 9. *[0-9]* practically tells find to search for any file which has one or more numbers in it.

Using tar and gzip

tar is a GNU utility for archiving files and directories, that is, it creates from many files one single file, with the .tar extension. tar doesn't compress the files, it only archives them. To archive a directory and all the contents in it, do:

tar -cf folder.tar folder_to_archive

Then, to compress the archive and obtain a .tar.gz file, use:

gzip folder.tar

To uncompress a .tar.gz file, you can do:

tar -xf folder.tar.gz

Also see the bzip2 utility (man bzip2), which is slower but provides higher compression ratios.

Using date

According to date manual page, it's an utility which can print or set the system date and time.

$ date
Wed May 28 14:25:37 EEST 2008

To change system's date and time, use:

date --set="Wed May 29 14:25:37 EEST 2008"

You have to be root in order to change system date. If you're online all the time, you won't need this. Just install ntpdate, which will synchronise the system's date and time from the internet.

Using aliases

Aliases are user-defined shortcuts for commands. For example, let's say you backup the file /home/$USER/personal_thoughts.txt very often. You would usually do a:

cd
cp personal_thoughts.txt /backup/whatever/directory

cd without parameters changes current working directory to your home directory. Instead of that command, you can add an alias to your .bashrc file like this:

alias bp='cp $HOME/personal_thoughts.txt /backup/whatever/directory; echo "Backup done"'

Save the file, log out and back in (use exit or CTRL+D) and type bp. You'll see it executes the commands specified by the alias in your .bashrc file. You can find a more detailed tutorial on aliases here.

Using nano

Nano is a simple and user-friendly, CLI (Command Line Interface) text editor. It comes installed by default on most distributions out there. To create a new file type:

nano newfile.txt

Add some stuff into your new file, save it (^O - which is CTRL+O) and then, to quit it, use ^X. For viewing files without editing them, you can use cat and less. To exit the less utility, use Q, and to navigate through it, use the Emacs shortcuts (^N for next line, ^P for previous line, ^V for next page, ALT+V for previous page). J for next line and K for previous line will work too.

Updated: Jun 14, 2008 (Created: May 28, 2008)

May 27, 2008

Get Used to the Command Line in Linux, Part 1

Part 1: The Basics

A shell is a command interpreter which allows the user to interact with the computer. Basically, it is a program which takes the commands you type, interprets them and performs the tasks you asked it to do, then it sends the results to the standard output, which usually is the screen. The most widely used shell on Linux systems is Bash, and it is also the default on most of the distributions out there, like Ubuntu or Fedora. Bash stands for Bourne-Again Shell, and is a modern implementation of the older Bourne Shell (sh), developed by the GNU Project.

Linux features several GUI (Graphical User Interface) applications which allow you to use a shell, like the GNOME Terminal or Konsole in KDE. Many more are available, and a review is available here. The next screenshot shows a typical instance of Konsole, using a transparent background and showing the output of the ls command:

Typical instance of Konsole (click to enlarge)

The ls command is used to list the files and directories in the current working directory. Here's the Gnome Terminal:

GNOME Terminal, using desktop transparency

Commands in Linux are of the form:

command option(s) filename(s)

For example, ls in the above example lists the files and directories in the current directory, but ls -a will also list the hidden files (the ones preceded by a dot).

To see which is the directory you're currently working in, use the pwd command:

$ pwd
/home/christmas/docs

pwd stands for 'print working directory'. In order to navigate through the file structure, you would use the cd (change directory) command, like this:

cd /home/christmas

which is equivalent to:

cd ..

'.' and '..' are two special types of files in Linux, the first one pointing to the current directory, while the second one points to one directory up in the file structure hierarchy. So cd .. will change the working directory from /home/christmas/docs to /home/christmas/, while the single dot can be used, for example, to copy files faster. To copy the /etc/motd file in the current directory, you would issue the command:

cp /etc/motd .

Of course, instead of '.' you could have used the full path, like this:

cp /etc/motd /home/christmas/docs

But the first one is obviously faster to type. The following is a list of basic commands, together with a short description. Try them and play with them, since they will prove themselves handy when you'll work on command line:

ls list directory contents
pwd print name of current/working directory
date print or set the system date and time
mkdir make directories
rm remove files or directories
mv move (rename) files
who show who is logged on
whoami print effective userid
cat concatenate files and print on the standard output
less file viewer

The man command offers detailed help about a specific tool or application on Linux. Usually, any application designed for Linux should have a manual accessible through the man command. For example, try:

man bash

To navigate throughout the manual use the J and K keys, or CTRL+N for next line and CTRL+P for previous line. Use Q to quit and return to the shell prompt. man is one of the most used commands in Linux when trying to get help about a specific command, and you should get used to read the manual page for a certain application before going elsewhere for help. Usually, all the GNU utilities include everything you would want to know in the manual page.

When using commands, try to use the TAB key in order to have the shell complete the commands instead of typing their full name.

Updated: Jun 20, 2008 (Created: May 27, 2008)

May 24, 2008

How-To: Create Your Own Aliases

Aliases are custom commands which can be used to make the work with the shell easier and faster. For example, if your current working directory is /usr/bin and you want to quickly go to /var/cache/apt/archives you can do a 'cd /var/cache/apt/archives'. If you want to save time, you may want to type only a command such as 'cache' or 'debs. Or you may want to update your Debian system in one command, so instead of typing 'su -c "apt-get update && apt-get upgrade"' you only type 'upgrade' or something of your choice. This is where aliases come to help.

In this How-To I will explain two ways of creating aliases.

Method 1
The first method is to add aliases directly into your ~/.bashrc file. The format should be:

alias name='command'

For example you can add something like:

alias ll='ls -l'
alias deb='cd /var/cache/apt/archives'
alias dld='cd ~/downloads'

alias upgrade='su -c "apt-get update && apt-get upgrade"'

Open a console and try your aliases. For example if you type 'deb', the current working directory will be changed to /var/cache/apt/archives.

Method 2
The second method lets you make a separate aliases file, so you won't have to put them in ~/.bashrc, but to a file of your choice. First, edit your ~/.bashrc file and add or uncomment the following lines:

if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi

Save it and close the file. After that, all you have to do is create a ~/.bash_aliases file and add your aliases there, with the same format specified at the first method.

How-To: Manipulate Audio Files Using CLI Tools in Debian

Note: This how-to may also work in Ubuntu and other Debian-based distributions.

This is a tutorial about using CLI (Command Line Interface) tools in Ubuntu and Debian to manipulate, encode and decode various audio formats, like FLAC or OGG Vorbis. It describes the packages needed to install, and some basic commands for converting audio files and working with CUE and FLAC files.The commands in this tutorial were tested in Kubuntu 7.10 Gutsy Gibbon and Debian Lenny, with all the updates to date.

Command line tools such as oggenc or flac can be used for example to convert FLAC (Free Lossless Audio Codec) files or WAV (WaveForm Audio Format) in OGG Vorbis files. Vorbis is a free audio codec offering lossy compression, and is known to have a smaller size and better quality (at least for lower bitrates) than the widely used MP3.

All the tools used in this tutorial are available through four packages, and to install them issue the following command as root (Ubuntu users must precede it with sudo, since the root account is disabled by default in Ubuntu):

apt-get install flac vorbis-tools cuetools shntool

These packages contain several programs and utilities for manipulating audio files. To convert a FLAC file into WAV do a:

flac -d file.flac

If there are several FLAC files in the same directory, use the command:

flac -d *.flac

And all the files with the .flac extension will be converted. Of course, one can include many more options, like the name of the output file. Do a man flac or a flac --help command to see detailed help and a list of options. To convert either WAV or FLAC files into OGG, execute one of the following commands:

oggenc -b 192 *.wav
oggenc -b 192 *.flac

The -b option refers to the bitrate of the resulting OGG file, in this case the average bitrate being 192 kbps. Or you can choose to use the quality option:

oggenc -q 6 *.flac

The quality is represented on a scale from 1 to 10, 10 being the highest. More details on the official website. Some albums may come as a single FLAC file and a CUE file which stores the information needed to split the former. In this case the programs cuebreakpoints and shnsplit come in handy:

cuebreakpoints album_name.cue | shnsplit album_name.flac

And the same goes with the WAV:

cuebreakpoints album_name.cue | shnsplit album_name.wav

It will result in several .flac or .wav files, split according to the lengths specified in the CUE file. You can also edit the CUE file with a text editor and change the split lengths, for concatenating two melodies or more in a single one.

Once you obtained the desired OGG Vorbis files, you may want to edit or remove their tags. To clear all the tags in an OGG Vorbis file, use the vorbiscomment tool. For example:

touch file
vorbiscomment -w song.ogg -c file

The first command will create an empty file (if it doesn't already exist). The second one will edit the tags in song.ogg with the info found in file, which is none. Here is a script to remove all the tags from all Vorbis files with OGG extensions in a directory:

#!/bin/bash

echo "OGG Tag Remover"
echo "Creating empty file..."
touch file

echo "Removing all tags in OGG files..."
for i in *.ogg; do
echo "Executing command 'vorbiscomment -w \"$i\" -c file'..."
nice -n 15 vorbiscomment -w "$i" -c file
done

echo "Removing empty file..."
rm file

echo "Done! All tags removed."

Copy this into a file of your choice, say vorbis_rm.bash, make it executable and then run it:

chmod 755 vorbis_rm.bash
./vorbis_rm.bash

All the tags in OGG files will be removed. This is useful when you have large albums and you want to clear some wrong edited tags in one command and start clear.

Some audio players like Amarok offer an easy tag editing system. However, to make your work even faster, you can use various Bash scripts which edit as much as is needed to just leave only fields like TITLE unfilled. Next is an example of a script which automatically fills the TRACKNUMBER field for each OGG file in a directory:

#!/bin/bash

echo "OGG TRACKNUMBER Edit"

n=1
for i in *.ogg; do
echo "Executing command 'vorbiscomment -a \"$i\" -t \"TRACKNUMBER=$n\"'"...
nice -n 15 vorbiscomment -a "$i" -t "TRACKNUMBER=$n"
n=$((n + 1))
done

echo "Done. TRACKNUMBER tags completed."

After running this script in a directory with OGG files, all of them will have the TRACKNUMBER field completed.

Updated: Jun 14, 2008 (Created: May 24, 2008)