Linux.com

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

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.

nerdsrule

 

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
0.0.0.0     10.0.0.1 0.0.0.0       UG      0 0          0 wlan0
10.0.0.0    0.0.0.0  255.255.255.0 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 10.0.0.1 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.

 

Comments

Subscribe to Comments Feed
  • Deltaray Said:

    Thanks for the mention. Actually, you can get different voices on Google TTS by changing the value of tl= in the URL, I found that a Brittish accent worked best for sounding scary since it started out being male. Actually at first I tried taking the female 'en' voice and making her scream in a scary way, but my sox foo isn't strong enough. Gotta leave some room for the reader to screw around with the commands themselves anyways.

  • Hans Said:

    Great article! With respect to the last point about bad wifi, I'm running Mint13 cinnamon and I just can't find a file named resolv.conf inside /etc/ nor inside /etc/resolvconf/, so I can't try your solution, and this happens on every buntu-based distro, of course. If you would give a hint, it will be much appreciated. Thanks!

  • Negred Said:

    Maybe Mint decided to place it in a different place (although that would be weird, since it has always been in /etc). You may want to do a find at the top level for resolv.conf and see where it is.

  • quib Said:

    On my Linux Mint 13 netbook, $ sudo dpkg-reconfigure resolvconf worked fine. See http://forums.linuxmint.com/viewtopic.php?f=157&t=103835

  • Jack Nash Said:

    Carla, thanks for sharing. These are the types of real world tips/tricks that should be in a book. Are you in for a new project?

  • David Wise Said:

    Hi Carla - appears to be one to many -t wav in the example. Great idea though

  • Klaus-Peter Arendt Said:

    My children and I had much fun with the Google's TTS Translator script. Initially I had an error "Cannot rewind WAV file" with play but the codeline then worked with |mpg123 -q -w - without using play. In a bash script one can use text =`php -r "echo urlencode('$1');"` with an installed php cli to convert a text input to the value for "q" Unfortunately german umlauts don't work, the voice says "unknown character" (in german) but ae,oe,ue etc. instead are pronounced correctly. Thanks!

  • S.Morris Said:

    Hi Carla,I am sorry if I bothered you,I followed the tutorial and pipe the duplicate finder to text file,it has over 25k lines,out of this how can I grep particular types such as mp3,iso,doc,xls. Or drop certain extensions I do not mind like 757e4d152145ddf824cf1af10416f53b ./.icons/Human Blue/scalable/actions/sleep.svg 757e4d152145ddf824cf1af10416f53b ./.icons/Purple/scalable/actions/sleep.svg So I would left with other file extension only to look through,such as doc,xls or mp3. Thank you very much for tutorial.

  • Carla Schroder Said:

    Hi S. Morris, The find command can do anything, if you can figure out how :) First find the files you want to compare, and then calculate the checksums. In this example I want to find JPGs in the current directory: $ find . -name *.jpg -exec md5sum '{}' ';' | sort | uniq --all-repeated=separate -w 20 This example looks for JPGs, PNGs, and TXT file extensions: find Downloads -regex ".*\.\(jpg\|png\|txt\)" -exec md5sum '{}' ';' | sort | uniq --all-repeated=separate -w 20 There are lots of escapes in the regex, which can get a little weird.

  • S.Morris Said:

    Thank you so much Carla,for your kind response.It gives me what exactly I am looking for.

  • Chris Said:

    I used to use a pipe like that to find duplicate files, but it can be a bit slow md5summing every file. Then I discovered the fdupes command - it's very fast in comparison. I use fdupes in a pipe like this: fdupes -r -n -S ~ | sed -r "s/^/#rm \"/" | sed -r "s/$/\"/" >duplicate-files.sh If you insert a shebang (#!/bin/bash) to the start of the output file, you end up with a shell script with every line escaped with a #. You can then simply un-escape any duplicate files you want to delete and execute the shell file. Fdupes should be in Debian/Ubuntu repositories.

  • dragonauta Said:

    Those commands looks like extracted from http://www.commandlinefu.com It is a command line repository. You can share your commands too

  • Yaron Said:

    I would personally recommend Wicd, This tool is much better than NetworkManager...

  • Kevin Said:

    The emptying files trick I've used a lot when trying compress a log files that is being written to good trick to ol' school log rotating: gzip -c FILE.log > FILE.log.gz && >FILE.log The '-c' has the compression go to stdout without deleting the original file, which is the reason of the redirection to 'FILE.log.gz'. The '&&' allow you to only blank the file if the compression is successful, if it fails for some reason (usally diskusage) the file will not be blanked out.

  • Richard Said:

    As for DNS I would just resolve via Google`s 8.8.8.8 public DNS server. That way you have a trustworthy high performance well administrated server.

  • Deltaray Said:

    Don't use 8.8.8.8 as your DNS server. Its ok to use it as a backup or to query against for individual queries, but if your local DNS sucks then the proper thing to do is complain to your local administrator about it or switch to another ISP, not to switch to a centralized DNS server. The DNS system was designed to be distributed, not centralized. Every person who switches their host's DNS to 8.8.8.8 or even 4.2.2.2 helps to decentralize it and put it in the hands of a single authority.

  • Gerben Welter Said:

    You do know that those Google DNS server ip addresses (8.8.8.8 and 8.8.4.4) are Anycast addresses? Although you connect to one ip address you're actually connected to another ip address based on your location.

  • Dan Stromberg Said:

    I wrote something called equivs3e, that finds duplicates using a mix of file lengths, cryptographic digests, and byte-for-byte comparisons. It's frequently faster than md5'ing everything for large inputs, and frequently doesn't need to sort at all - that is, it is almost always O(n). It's at http://stromberg.dnsalias.org/~strombrg/equivalence-classes.html . HTH

  • Spyros Tsiolis Said:

    Nice article. Thanks for that. Also on MInt 13, if you launch openvpn through a wifi connection and try to access normal internet, mint 13 seems that it looses routing and you cannot access things like a web page. Once you take down (disconnect) from OpenVPN, most of the time, things get back to their original state.

  • Anand Said:

    I was searching for How To Find Duplicate Files. But your article is the best. Thanks for sharing.

Upcoming Linux Foundation Courses

  1. LFD331 Developing Linux Device Drivers
    13 Oct » 17 Oct - Virtual
    Details
  2. LFS425 Linux Performance Tuning Crash Course
    16 Oct » 16 Oct - Düsseldorf, Germany
    Details
  3. LFS220 Linux System Administration
    20 Oct » 23 Oct - Virtual
    Details

View All Upcoming Courses

Become an Individual Member
Check out the Friday Funnies

Sign Up For the Linux.com Newsletter


Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board