Random Linux Commands to Make Google Talk, Fix Wifi, Find Duplicate Files, and More



Did you know you can make Google Translate talk? Preview Unicode characters on the command line? Generate entropy with the ls command? Use md5sum hashes to find duplicate files, regardless of their names? Test speakers? Fix roaming wifi? If you didn’t before, you will after you read this article.

Google’s TTS Translator

I learned about Google’s text-to-speech translator from the wonderful @climagic on Twitter. This is Climagic’s original command that plays a scary laugh for Halloween:

$ wget -q -O- -U Mozilla http://bit.ly/SdwXD1 |mpg123 -q -w - - |play -t wav - -t wav -t alsa pitch -1200

It also works with the command-line mode of VLC, cvlc. This second example shows how to create your own message:

$ wget -q -O- -U Mozilla "http://translate.google.com/translate_tts?q=hello+,+this+is+different+than+the+previous+example&tl=en-uk" |cvlc - |play -t wav - -t wav -t alsa

This relies on the Google text-to-speech translator, which is the engine for the TTS functions on Google Play, Android, and i-Devices. You can play with it in a Web browser at Google Translate by typing some text and then clicking the listen button. But Google translate doesn’t let you play with different voices, which you get by using different locales such as en-US and en-AU. Run locale -a to see what’s installed on your system, and then try them out.



Google TTS isn’t very well-documented for users, but there is some good developer information at chrome.ttsEngine.

Preview Unicode Characters

This is a quick way to see if your system renders them correctly:

$ echo -e \u2666

That should look like a little diamond. Unicode and locale issues are a chronic sources of fun, especially when you’re writing Linux howto articles for Web publications. Unicode Characters as Named and Numeric HTML Entities is a comprehensive reference.

Unusual Tasks With File Listings

When you create a new GPG key it wants you to wiggle the mouse or pound the keyboard or do something to create enough entropy to create a well-randomized key. There is an easy way, and that is to use the ls command to recursively list every file on your system:

$ ls -R /

Do this in a separate terminal, and then you don’t have to do silly tiring things like wiggling mice. While we’re on the subject of the ls command, you can list multiple directories in a single command by using simple wildcards:

$ sudo ls -l /var/*/*/

You can skip over subdirectories, as this example shows:

$ sudo ls -l /var/.../*/

I’m sure I copied this one from somewhere– It draws a nice ASCII file tree of all subdirectories of the current directory:

$ find . -type d |sed 's:[^-][^/]*/:--:g; s:^-: |:'

Find Duplicate Files

The sure-fire way to find duplicate files is by comparing MD5 hashes. This compares only the first 20 characters of the md5sum, but it still takes a long time. It’s the most accurate method, so I don’t mind the wait:

$ find . -type f -exec md5sum '{}' ';' | sort | uniq --all-repeated=separate -w 20

You can also compare file sizes, which is a little less accurate but a lot faster:

$ find . -type f -printf "%p - %s" | sort -nr -k3 | uniq -D -f1

I use the first method when I start accumulating a lot of sloppy backups, and have too many copies of the same files littering my backup servers.

Quick Speaker Test

When you’re debugging audio problems, use ALSA’s built-in speaker test:

$ speaker-test  -c 5 -l 1 -t wav
speaker-test 1.0.25
Playback device is default
Stream parameters are 48000Hz, S16_LE, 5 channels
WAV file(s)
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 39 to 419430
Period size range from 12 to 139810
Using max buffer size 419428
Periods = 4
was set period_size = 104857
was set buffer_size = 419428
 0 - Front Left
 1 - Front Right
 2 - Rear Left
 3 - Rear Right
 4 - Center
Time per period = 9.256201

You should hear a pleasant woman’s voice saying “front left, front right” and so on. The -c parameter is how many channels you’re testing, and -l sets how many times you want the test to run.

Sometimes your sound system can get all goobered up, so try restarting ALSA:

$ sudo alsa force-reload

Empty a File

This one deletes the contents of a file without deleting the file:

$ > filename 

Foiling Bad Wifi

On my last few trips out of town I had trouble getting connected, because I couldn’t get DNS. I was getting an IP address and gateway, but still no Internet. So first I ran netstat to find my default gateway:

$ netstat -rn
Kernel IP routing table
Destination Gateway  Genmask       Flags MSS Window  irtt Iface       UG      0 0          0 wlan0 U       0 0          0 wlan0

Then I looked in /etc/resolv.conf to compare. And there was the answer– Network Manager was not updating /etc/resolv.conf. So I manually added to it, and lo! I had Internet.

So what’s up with Network Manager? I confess I have not fully analyzed this yet, but the core issue is Ubuntu, which is the upstream of my Linux Mint 13 installation, has changed how Network Manager manages dynamic DNS updates. You can read all about it at DNS in Ubuntu 12.04. Perhaps Linux Mint changed something, because it should have updated my DNS as I roamed to different networks. At any rate now you know how to make a quick manual workaround, and I’ll cover this in more detail in a future article.