Archive for the ‘bash’ Category

dropbox: command-line interface

September 12, 2015 Leave a comment

I wanted to test the status of my Dropbox client from the terminal. Actually, I wanted to write a script that executes an action when my Dropbox folder is fully synced. So I wanted to test the status if it’s “working” or “synced”.

I found the solution here. It turned out that Dropbox has an official command-line script that can do this and much more. First, get it:

wget -O ~/
chmod u+x ~/
~/ status

This is a Python script, written in Python 2, thus I modified the first line to be “#!/usr/bin/env python2“.

This script can do several things for you:

Dropbox command-line interface


Note: use dropbox help  to view usage for a specific command.

 status       get current status of the dropboxd
 help         provide help
 puburl       get public url of a file in your dropbox
 stop         stop dropboxd
 running      return whether dropbox is running
 start        start dropboxd
 filestatus   get current sync status of one or more files
 ls           list directory contents with current sync status
 autostart    automatically start dropbox at login
 exclude      ignores/excludes a directory from syncing
 lansync      enables or disables LAN sync

Some years ago I wrote a simple script to get the public URL of a file in my Dropbox folder. This script can do that too with the “puburl” command.

Categories: bash, python Tags: , ,

reddit from the terminal

September 7, 2015 Leave a comment

There is a command line interface for Reddit called “rtv” (reddit terminal viewer). It’s written in Python, so you can install it with pip.

Here is a short youtube video on how to use it.

Categories: bash, linux, python Tags: , ,

[manjaro] ping needs special privileges

September 5, 2015 Leave a comment


$ ping -c 1
ping: icmp open socket: Operation not permitted


$ sudo chmod u+s `which ping`
$ ping -c 1
PING ( 56(84) bytes of data.
64 bytes from ( icmp_seq=1 ttl=45 time=38.6 ms

--- ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 38.681/38.681/38.681/0.000 ms
Categories: bash Tags: , ,

replace a string recursively in multiple files

September 4, 2015 Leave a comment

In a folder I have lots of files, and the folder also has subdirectories with further files. I want to replace a string in all of them. I want to modify the files in place.

For instance, you want to update a bunch of Python scripts from version 2 to version 3, thus you want to modify the first lines from “#!/usr/bin/env python2” to “#!/usr/bin/env python3“.

I found the solution here:

grep -rli 'old-word' * | xargs -i@ sed -i 's/old-word/new-word/g' @

WARNING! Since it modifies the files in place, be very careful! First run just the beginning of the command above:

grep -rli 'old-word' *

Refine it if necessary. If it finds exactly what you need, then proceed.

Categories: bash Tags: , , ,

check a new HDD for bad blocks

September 1, 2015 Leave a comment

You buy/get a new HDD and you want to make sure that it has no bad sectors. How to check that?

I found a solution here. In short:

sudo badblocks -wvs /dev/sdx

where /dev/sdx is the drive. WARNING! This is a destructive check, i.e. all data on the drive will be lost!

The -w option tells badblocks to write a known pattern, then read back the data to make sure it matches the pattern. It does this 4 times, using the patterns 0xaa, 0x55, 0xff, and 0x00 (alternating 0’s and 1’s, then all 1’s, then all 0’s). Note that this will overwrite all data on the drive and wipe out all the partitions, as well.” (source)

Categories: bash, linux Tags: , ,

[manjaro] compile MongoDB from source and install it manually

August 20, 2015 Leave a comment

I wanted to install MongoDB on an old 32-bit laptop of mine. After installing it from the official repository, the mongo shell died with the following error: ” Illegal instruction (core dumped)”.

The problem is that the binary file uses an instruction set that is not supported by my old 32-bit CPU:

$ cat /proc/cpuinfo | grep flags
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov clflush dts acpi mmx fxsr sse sse2 ss tm pbe nx bts est tm2

SSE3 is missing :( What to do? Uninstall the mongodb package and 1) compile it from source, 2) install it and 3) make it start at startup.

(1) Compile the source
I found an excellent blog post about it at . Here I would sum up the steps.

Download the source from here: . It’s about 35 MB. The source uses the SCons build system, so install the “scons” package too. Note that the compilation process took about 6 hours on my old laptop and the work directory where compilation was being done grew to 18 GB! I didn’t have that much free space so I had to move this work directory to an external HDD :) However, when you install the binaries, they will only occupy 90 MB.

So, if you have an old CPU, edit the file SConstruct:

        if using_gcc() or using_clang():
                myenv.Append( CCFLAGS=['-march=pentium3', '-mtune=generic'] )
                #myenv.Append( CCFLAGS=['-march=nocona', '-mtune=generic'] )

The target architecture “nocona” was replaced by “pentium3”. Again, this tip is from Karl.

After this you can start the compilation and wait :)

$ scons --disable-warnings-as-errors --32 all

The blog post at stops at this point.

(2) Install the binaries
I installed the binaries to /opt:

$ scons --prefix=/opt/mongo-3.0.5 install

Of course, replace “3.0.5” with your current version. I also put a symbolic link on this folder:

$ cd /opt
$ ln -s mongo-3.0.5 mongo

Note that the binaries are put into a “bin” folder, thus they are located in “/opt/mongo-3.0.5/bin/“.

Now put symbolic links in /usr/bin/ that point to the appropriate binaries in /opt/mongo/bin/. They look like this on my machine:

$ cd /usr/bin
$ ls -al | grep mongo
lrwxrwxrwx  1 root root         20 11.08.2015 08:30 mongo -> /opt/mongo/bin/mongo
lrwxrwxrwx  1 root root         21 11.08.2015 08:31 mongod -> /opt/mongo/bin/mongod
lrwxrwxrwx  1 root root         24 11.08.2015 08:31 mongoperf -> /opt/mongo/bin/mongoperf
lrwxrwxrwx  1 root root         21 11.08.2015 08:31 mongos -> /opt/mongo/bin/mongos
lrwxrwxrwx  1 root root         25 11.08.2015 08:31 mongosniff -> /opt/mongo/bin/mongosniff

(3) Make MongoDB start at startup
Create these two directories: /var/lib/mongodb and /var/log/mongodb . The mongo daemon shouldn’t run with root privileges, so we create a dedicated user for this purpose and set its password:

$ sudo adduser mongodb
$ sudo passwd mongodb

Now, the owner of the previously created two folders will be “mongodb“, and they will belong to the “daemon” group. Example on my machine:

$ cd /var/log
$ ls -al | grep mongodb
drwxr-xr-x  2 mongodb daemon            4096 11.08.2015 09:29 mongodb/

Use the chown and chgrp commands.

After this, you need to copy some config files as root. They are collected here.

First, create /etc/mongodb.conf . Mine looks like this:

# See for format details
# Run mongod --help to see a list of options

bind_ip =
quiet = true
dbpath = /var/lib/mongodb
logpath = /var/log/mongodb/mongod.log
logappend = true

noprealloc = true
smallfiles = true

Next, create /usr/lib/systemd/system/mongodb.service . Sample:

Description=High-performance, schema-free document-oriented database

ExecStart=/usr/bin/mongod --quiet --config /etc/mongodb.conf


Now it’s time to enable and start the mongodb service:

$ systemctl enable mongodb.service
$ systemctl start mongodb.service

Verify if it’s running:

$ systemctl status mongodb.service

If it seems OK, try to connect to it with the mongo shell using the command “mongo“.

If the service doesn’t start with the systemctl command, then try to launch the server manually:

$ mongod --quiet --config /etc/mongodb.conf

You may want to remove the “--quiet” option. If it has some problems, it will print a more detailed error message than “systemctl start...“.

I wrote this post one week after I installed MongoDB, but I hope I didn’t forget any steps. Good luck!

Categories: bash, linux Tags: , , , ,

get the UUID of a partition

July 30, 2015 2 comments

You want to figure out the UUID of a partition. For instance, you want to mount a partition upon boot and thus you want to add it to your /etc/fstab.


$ sudo blkid

The blkid program … can determine the type of content (e.g. filesystem or swap) that a block device holds, and also the attributes (tokens, NAME=value pairs) from the content metadata (e.g. LABEL or UUID fields).” (source: man)

Update (20150803)
As msx pointed out in the comments, you can also write “lsblk -f“, which doesn’t require sudo rights at all.


Categories: bash Tags: , , ,

Get every new post delivered to your Inbox.

Join 82 other followers