Feeds:
Posts
Comments

Archive for the ‘Command-Line/Terminal’ Category

Introduction to the FLAC Format

The FLAC audio format is so awesome, I still can’t get my head around it! It is lossless, like WAV files, yet often less than half the size. For example, if you had an album at full-quality (320 kbps) in MP3 format (which is lossy, meaning some quality had to be sacrificed), it could well be around 140Mb. Raw, lossless audio in the form of .wav files would on the other hand take up around 1Gb, if not closer to 1.5Gb. The reason .flac files have become so popular is that while being lossless in quality like .wav files, that album would probably only take up about 450Mb – half the size or less, but the same lossless quality.

If you’re quite happy with MP3s and their much-smaller filesize, if you ever end up with an album in FLAC format, you can always convert the tracks down to MP3 with a program like Sound Converter. But what if you get the album as one, long, continuous .flac file? Well, as long as that file also came with a .cue file (which specifies the breaks between tracks), it’s really easy to split it via the command-line, as you’ll see.

How to Split a FLAC Album with CUE File

First off, you need to make sure you have the necessary packages installed, which you can do with the following command:

sudo apt-get install cuetools shntool flac

Once done, you can start splitting the album with a command like the following:

cuebreakpoints album.cue | shnsplit -o flac album.flac

… replacing the word “album” in each case with the correct name. If the 2 files have multiple words with spaces, you’ll have to enclose them in double-quotes, like in the following example:

cuebreakpoints “The Number Of The Beast.cue” | shnsplit -o flac “The Number Of The Beast.flac”

Once that’s done, all you’ll have to do is rename the tracks (unless it doesn’t worry you), and edit the tags (the info you see in your audio player) via Rhythmbox, or a dedicated tag editor.

☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻

Did this information make your day? Did it rescue you from hours of headache? Then please consider making a donation via PayPal, to buy me a donut, beer, or some fish’n’chips for my time and effort! Many thanks!

Buy Ubuntu Genius a Beer to say Thanks!

Read Full Post »

While there are ways to change the default web browser via a GUI, this command-line method is even quicker. Also, while your email program and other apps might know which browser to open URLs with, you might find that ApportUbuntu‘s bug reporting system – looks to another browser you have installed. This is especially true if the other browser was at one point the default, and most notably this happens with Opera, though could also happen with Chromium/Google Chrome, Firefox, or any other browser you’ve installed before.

While Apport generally carries on with the bug reporting silently once you’ve clicked to continue, occasionally it require you to log into Launchpad, and will fire up the wrong browser, quite often it being Opera.

But it’s easy to remedy this by entering the following into the terminal:

sudo update-alternatives --config gnome-www-browser

Change Default Browser in Ubuntu

As you’ll see, all you have to do is enter the number corresponding to the browser you want to be the default (in this case 2 for Firefox). To complete the process, enter this command:

sudo update-alternatives --config x-www-browser

Change Default Browser in Ubuntu 2

… and do the same there. That’s it – you’ll no longer have Apport or any other app open the wrong browser again.

☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻

Did this information make your day? Did it rescue you from hours of headache? Then please consider making a donation via PayPal, to buy me a donut, beer, or some fish’n’chips for my time and effort! Many thanks!

Buy Ubuntu Genius a Beer to say Thanks!

Read Full Post »

A couple of years or so ago, Ubuntu‘s file manager, Nautilus, gave you the ability to “Safely Remove Drive” when right-clicking an attached USB hard drive (or flash drive), rather than just simply “Unmount” it. The difference between the two is that when you simply unmount a drive, it is still listed as attached (but not mounted) in Nautilus‘s left-pane. For many, seeing the drive completely removed was reassuring, since it could then be unplugged safe in the knowledge there would be no data loss, or physical damage to the device.

However, in the Ubuntu 12.10 upgrade, we lost this option, and now only have “Unmount” and “Eject” (which is exactly the same as “Unmount“, except in the case of CD/DVD drives where it will eject the disc tray).

Device Context-Menu

While “Safely Remove Drive” may yet make a return (it has caused a flood of complaints about this backward move), for now you can do it via the command-line if you really prefer this to simply unmounting.

First, if you’re unsure what the drive’s address is, run the following in the terminal:

mount|grep ^'/dev'

If you only have one internal hard drive, and no other storage devices attached, it should be something like /dev/sdb. To safely unmount and totally remove the drive, enter the following command, replacing /dev/sdb with your own drive’s designation if need be:

udisks --unmount /dev/sdb1 && udisks --detach /dev/sdb

You should now see your drive disappear from the file manager’s left-pane.

Note that in the unlikely event you have a partition other than the first partition on the drive mounting, you will need to change the “1” (ie: sdb1) in the command to reflect that.

☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻

Did this information make your day? Did it rescue you from hours of headache? Then please consider making a donation via PayPal, to buy me a donut, beer, or some fish’n’chips for my time and effort! Many thanks!

Buy Ubuntu Genius a Beer to say Thanks!

Read Full Post »

PDF (Portable Document Format) documents are a handy way to present text and images to others knowing they’ll look the same no matter what word processor or operating system they use. Basically, they’re a snapshot of a document, so saving images from them can be a hassle, even if your viewer lets you right-click them and save them as files. There are a few programs around that can do this for you, but it’s actually much easier and faster doing this from the command-line.

The pdfimages command is part of poppler-utils, which should already be installed on your system (sudo apt-get install poppler-utils in the terminal if it isn’t). To extract the images from a PDF, just open a terminal in the folder with the document, and run a command like the following:

pdfimages -j Cool-Pix-of-2011.pdf cool2011

Note that when extracting from files with spaces in the name, you will need to enclose the filename in single quotes. Eg:

pdfimages -j 'Cool Pix of 2011.pdf' cool2011

The text at the end of the command is what each extracted image will begin with, so the resulting filenames will be cool2011-000.jpg onwards (note that numbering starts at 000, not 001). Once again, if you’d prefer to have spaces in the target names, for example to mirror the name of the original PDF, then enclose that in single quotes too (eg: 'Cool Pix of 2011 ' – note the space at the end, just to provide a bit more separation between '2011' and the hyphen preceding the automatic numbering; this is of course optional, and you can pretty much do what you want). Eg:

pdfimages -j 'Cool Pix of 2011.pdf' 'Cool Pix of 2011 '

Your pictures will now be extracted into the folder with names starting with Cool Pix of 2011 -000.jpg.

Also, the -j option is to save the images in the .jpg format, otherwise they will be saved in .ppm (Portable Pixmap) format, with each file being over a megabyte. This can mean, for example, that an 18Mb document with 120 images can extract to 154Mb of files, whereas exporting them as .jpg ends up with a total of 18Mb, just like the original document. Of course, if you’d prefer to save them as .ppm images, simply leave out the -j option.

If you would like to include the page numbering in the file names, add the -p option. Eg:

pdfimages -j -p 'Cool Pix of 2011.pdf' 'Cool Pix of 2011 '

Lastly, don’t worry if you see the following in the terminal for each image being extracted:

Error (18468081): Missing ‘endstream’
Error: Unknown operator ‘endstream’
Error: Unknown operator ‘endobj’

You shouldn’t see that with every PDF you try to extract from, but even when you do you should find the target images have been created without issue.

Extra Notes:

For more options for this command, run pdfimages -?. For example, you can specify a start and end page, but personally I find it easier to just extract the whole document and delete any images I don’t want afterwards. But if you need to specify a password, you will find the option here.

☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻

Did this information make your day? Did it rescue you from hours of headache? Then please consider making a donation via PayPal, to buy me a donut, beer, or some fish’n’chips for my time and effort! Many thanks!

Buy Ubuntu Genius a Beer to say Thanks!

Read Full Post »

If you find yourself trying to figure out which package contains a certain command, or any other file for that matter, apt-file is a command that will make this easy. It probably won’t be installed by default, so do so with this command:

sudo apt-get install apt-file

You will then be presented with the message:

The system-wide cache is empty. You may want to run ‘apt-file update’ as root to update the cache. You can also run ‘apt-file update’ as normal user to use a cache in the user’s home directory.

It’s probably best to run the former option (that is, as superuser), so enter the following:

sudo apt-file update

Let it update the cache, then you can search for the command or package or file. Simply use apt-file search followed by whatever it is you’re looking for. For example, we’ll search for the command ccsm, which is what runs the Compiz-Config Settings Manager, as there is no actual package of that name:

apt-file search ccsm

You might find the list presented is quite long, so it may pay to set your terminal to unlimited scrolling beforehand. In the case of the example, the line we’re looking for:

compizconfig-settings-manager: /usr/bin/ccsm

is not visible, since it is right near the top, which is beyond scrolling. If this happens to you, edit your terminal settings and run the command again.

Generally speaking, if it’s a command/program, then the line that has /usr/bin/ followed by the command (like ccsm) will be the correct one. The actual package that contains it will be listed at the beginning, in this case being compizconfig-settings-manager.

Remember, this can work with other types of files too, so if you’re looking for a specific config file or icon or whatever, just specify that at the end of the command. Eg:

apt-file search ccsm.desktop

Hopefully this is all you need to find that elusive file, or the package that installs a program you’re after.

☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻

Did this information make your day? Did it rescue you from hours of headache? Then please consider making a donation via PayPal, to buy me a donut, beer, or some fish’n’chips for my time and effort! Many thanks!

Buy Ubuntu Genius a Beer to say Thanks!

Read Full Post »

At times when using the terminal, the output from a command can be so long, you simply can’t scroll to the beginning, as it is no longer in view. But you can actually set the terminal to display as many lines as you like, or even set it to unlimited scrolling.

In the terminal, go to Edit > Profile Preferences, and in the Scrolling tab you will see there is a default amount of lines to be displayed (probably something like 512). If you have an older computer and are worried about memory, you can up the amount to 2000 or thereabouts, as that should suffice, otherwise the best option is to place no limit on the amount of lines displayed. Under that, you will see “Unlimited“, so check that, and from the next command onwards you won’t have that limitation any more.

Various terminals available might differ as to where to change that setting (like a Settings menu, or Edit > Preferences or Tools > Settings), but they all should have it, and you should find it easy enough.

☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻

Did this information make your day? Did it rescue you from hours of headache? Then please consider making a donation via PayPal, to buy me a donut, beer, or some fish’n’chips for my time and effort! Many thanks!

Buy Ubuntu Genius a Beer to say Thanks!

Read Full Post »

The terminal for running commands in Ubuntu and any other Linux distro is dull to look at, but you can easily spice it up a little with some colour.

Simply run the following command in a terminal:

gedit ~/.bashrc

When .bashrc opens, locate and uncommentforce_color_prompt=yes” (that is, remove the hash, so it no longer looks like: #force_color_prompt=yes).

Save the file, and open a new terminal window, and you should already see a change (the prompt should be Light Green, which is defined by 1;32). You can then change any colour value you like; eg: 0;35 = Purple.

To edit the colour values, locate the following section, and change the default values with some of the examples listed further down:

if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;31m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi

You can check out this Bash colour chart for a full range of colour values, but here are a few basic ones you can play around with (note that “Light” isn’t what you might think – it actually means “bold”):

Black 0;30Dark Gray 1;30Blue 0;34Light Blue 1;34Green 0;32Light Green 1;32Cyan 0;36Light Cyan 1;36Red 0;31Light Red 1;31Purple 0;35Light Purple 1;35Brown 0;33Yellow 1;33Light Gray 0;37White 1;37

For those curious about the codes used in the example pic, here’s the line from that section:

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;35m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

As you can see, 1;35 is the Light Purple user and machine name, while the 1;34 is the Light Blue tilde (~). If you want yours a bit brighter, try:

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;36m\]\u@\h\[\033[00m\]:\[\033[01;31m\]\w\[\033[00m\]\$ '

… which will give you Light Cyan and Light Red, and look like the following:

In case you’re wondering about the colon and dollar sign, you can change those as well, but you need to do more than just edit the colour values. You’ll need to insert code in the appropriate places, so the line looks like this:

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;36m\]\u@\h\[\033[01;33m\]:\[\033[01;31m\]\w\[\033[01;33m\]\$ '

You’ll notice the first highlighted code is just before the colon (:) while the second is before the dollar sign ($). In this example, both are yellow, with the result looking like:

Now, if you want to go even further, you can make the user name stand out by doing the following:

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;36m\]\u\[\033[01;35m\]@\h\[\033[01;33m\]:\[\033[01;31m\]\w\[\033[01;33m\]\$ '

That extra bit of code is specifying Light Purple for the @ and the desktop name, making it now look like:

And of course, one last bit of fiddling and you can have every element a different colour. In this last example, we’re going to make the computer name the same as the user name, and have them broken up by red, as with the yellow elements:

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;36m\]\u\[\033[01;31m\]@\[\033[01;36m\]\h\[\033[01;33m\]:\[\033[01;31m\]\w\[\033[01;33m\]\$ '

As you can see, the @ is now Light Red, while the code before \h is specifying Light Cyan, like the user name:

You’ll also notice when you type commands that the colour of the text will match that of the $, which can be preferable if using a “light” colour, since the bold text is easier to see.

Lastly, in case you’re wondering whether the prompt can end in anything other than a $, the answer is yes, and it’s as easy as opening the Character Map (sudo apt-get install gucharmap if you don’t have it), selecting a character, and pasting it over the $ at the end of the line of code:

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;36m\]\u\[\033[01;31m\]@\[\033[01;36m\]\h\[\033[01;33m\]:\[\033[01;31m\]\w\[\033[01;33m\] '

In that example, I simply selected a cool looking character from the font Runic, and replaced the $ with that. You’ll also note one other thing you’ll have to do, and that’s remove the \ before it, or else that will appear too (obviously, that doesn’t happen if using the $, but will with other characters).

Have fun experimenting!

☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻☻

Did this information make your day? Did it rescue you from hours of headache? Then please consider making a donation via PayPal, to buy me a donut, beer, or some fish’n’chips for my time and effort! Many thanks!

Buy Ubuntu Genius a Beer to say Thanks!

Read Full Post »

Older Posts »