Remove/replace line break in bash output

Sometimes it’s much more convenient (or required) to feed a list as one line with separated elements instead of one item per line. Example:

You have this (just a random list of files):

You want this:

Tools like ls and echo have their own parameters to handle this individually, but I found two simple solutions that work for ALL bash output: one makes use of tr and the other of xargs. The latter makes sense if you want the list of elements as command line parameters for another tool (i.e. open all *.c files in this directory in a text editor) while tr is useful if you want to pipe the list to another program or into a file.



ls | grep “\.c$” | tr ‘\n’ ‘ ‘

In this example tr takes the input and replaces each new line character ('\n') with a space character (' '). tr has a few interesting options to manipulate output. The description from the man page pretty much sums it up:

“Translate, squeeze, and/or delete characters from standard input, writing to standard output.”

Found in this reply on Ask Ubuntu by user roadmr.

One py to extract them all!

I wrote about a neat bash function before to extract the popular archive types without having to remember the right programs and options. Today I stumbled over a Python script that does exactly that and even more! It’s called dtrx – Do The Right Extraction. Created by Brett Smith.

Why would you want to install and use a Python script when there is a bash function? One or more of the following features:

  • Handles many archive types: You only need to remember one simple command to extract tar, zip, cpio, deb, rpm, gem, 7z, cab, lzh, rar, gz, bz2, lzma, xz, and many kinds of exe files, including Microsoft Cabinet archives, InstallShield archives, and self-extracting zip files. If they have any extra compression, like tar.bz2 files, dtrx will take care of that for you, too.
  • Keeps everything organized: dtrx will make sure that archives are extracted into their own dedicated directories.
  • Sane permissions: dtrx makes sure you can read and write all the files you just extracted, while leaving the rest of the permissions intact.
  • Recursive extraction: dtrx can find archives inside the archive and extract those too.

HikiPlayer – A Lighweight Android Music Player

I finally found a great lightweight folder-based (not a library player like iTunes and such) music player for my Android phone. The phone is not the newest so I was looking for something lean.

HikiPlayer is a mere 162kB download but is customizable and can scrobble your songs on On top of that it’s free, doesn’t have ads, displays album covers and can also fetch them from the web. Video playback, lyrics …


How to highlight output with grep instead of filtering

Looking for bits of information swirling past you on the screen can be tiring. Thanks to grep one can filter out unneeded text. But what if you want to display everything and just highlight text that you think is relevant? Image ping for some information and an error gets filtered out since you didn’t explicitly search for it (because all YOUR code free from errors, right? 😉 ). Well, turns out grep can do just that:

An example that I just used:

Credit goes to user holygeek on stack overflow.

UPDATE: One function to extract them all!

UPDATE: There is a Python script that has some extra features (like extraction into a dedicated directory and changing of permissions).

I seriously fail to remember all those tar options for each of the supported archives 🙂 So I’m happy to have found a bash function that will simply chose the right command based on the file extension:

Simply put the function at the bottom of your .bashrc file. Either close and re-open the terminal you’re using or type source ~/.bashrc to refresh the changes of your bash environment.

Now you can just type extract and the function will extract the archive and cd into it. Super time-and-brain-energy-saver! 😛 I found this function on the Ubuntu forums in a post by user graysky.

USB-BT4LE Bluetooth 4.0 USB Adapter by Plugable on Ubuntu 12.04

This is my experience with the USB-BT4LE Bluetooth 4.0 USB Adapter by Plugable. I bought it since it claims to have Linux support out-of-the-box. Well – the chipset IS supported but I needed to fiddle some to make it work 🙂 Of course I can only speak for the device I got and my computer (Ubunu 12.04 LTS, kernel 3.8). So here we go.

After inserting the dongle into the USB port I only got the following message in dmesg:

So I began some digging. A search for the product code and the device id gave me the Bluetooth chip that is used: BCM20702. The last line of the dmesg output suggests that a firmware is needed. Some more searching on the web confirmed this and this Ubuntu bug report suggests a tool called hex2hcd by Jesse Sung to convert the firmware image that comes with the windows driver into a hcd file. So I booted Windows, installed the driver and checked which firmware is being used:


These are the build instructions I found in a comment on the same bug report:

When the Bluetooth adapter gets plugged into the PC the kernel will look for a proper firmware in the /lib/firmware folder. For this to work the filename of the firmware must have the following format: fw-<manufacturer_id>_<device_id>.hcd

After removing the Bluetooth adapter and plugging it in again I got the following messages:

So far so good. However, I encountered another problem:

It turns out that there’s a program called rfkill that will acticate/deactivate your bluetooth and/or WLAN devices. In my case this was probably triggered by the hardware switch for wireless communication on my Thinkpad. I found solution on the Ubuntu forums: