Archive for the ‘bash’ Category

find command examples

October 24, 2017 Leave a comment

I needed to clean up after running tests

Using find

$ tree
├── bin
│   └── hello
├── hello
│   ├──
│   └──
├── requirements.txt
└── tests

3 directories, 7 files
$ python3 test                                            
running test
running egg_info
creating hello.egg-info
writing dependency_links to hello.egg-info/dependency_links.txt
writing top-level names to hello.egg-info/top_level.txt
writing hello.egg-info/PKG-INFO
writing manifest file 'hello.egg-info/SOURCES.txt'
reading manifest file 'hello.egg-info/SOURCES.txt'
writing manifest file 'hello.egg-info/SOURCES.txt'
running build_ext
test_print_hello (tests.test_hello.TestHello) ... ok

Ran 1 test in 0.014s


Now more files are created.

$ tree
├── bin
│   └── hello
├── hello
│   ├──
│   ├──
│   └── __pycache__
│       ├── hello.cpython-35.pyc
│       └── __init__.cpython-35.pyc
├── hello.egg-info
│   ├── dependency_links.txt
│   ├── PKG-INFO
│   ├── SOURCES.txt
│   └── top_level.txt
├── requirements.txt
└── tests
    ├── __pycache__
    │   ├── __init__.cpython-35.pyc
    │   └── test_hello.cpython-35.pyc

6 directories, 15 files

To delete the *.pyc files and the __pycache__ and hello.egg-info folders, run the following commands.

$ find . -type d -name "hello.egg-info" | xargs rm -rf
$ find . -type d -name "__pycache__" | xargs rm -rf
$ find . -name "*.pyc" | xargs rm -f


$ find --version                                                   
find (GNU findutils) 4.7.0-git
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Eric B. Decker, James Youngman, and Kevin Dalley.
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS(FTS_CWDFD) CBO(level=2) 


Categories: bash Tags: ,


August 1, 2017 Leave a comment

Well this was more like an irritant. I have a portforwarding script that I manually start. I just got tired of doing that and moved it to an upstart task.

Added the following job for upstart to handle.

$ less /etc/init/portforward.conf
description     "Portforward 3141 to devpi server"

author      "Vagrant"

start on runlevel [2345]
stop on runlevel [!2345]

    cd /home/vagrant

    export SSHPASS="vagrant"
    sshpass -e ssh -nNL 3141: -o ConnectTimeout=10 -o LogLevel=Error -o StrictHostKeyChecking=no vagrant@
end script
$ # Check the syntax
$ init-checkconf /etc/init/portforward.conf
$ # Start the job
$ sudo service portforward start


Categories: bash Tags: ,

A Powerline style prompt for your shell

July 23, 2017 Leave a comment

For a hassle free powerline like shell. Works with bash and zsh.

* Shows some important details about the git/svn/hg/fossil branch (see below)
* Changes color if the last command exited with a failure code
* If you’re too deep into a directory tree, shortens the displayed path with an ellipsis
* Shows the current Python virtualenv environment
* It’s easy to customize and extend. See below for details.

Categories: bash, zsh Tags:


July 23, 2017 Leave a comment

Git status with powerline


1. pip install –user powerline-gitstatus

Follow the instructions in on site
2. Add custom highlight groups.

vim .local/lib/python2.7/site-packages/powerline/config_files/colorschemes/default.json


  "groups": {
    "gitstatus":                 { "fg": "gray8",           "bg": "gray2", "attrs": [] },
    "gitstatus_branch":          { "fg": "gray8",           "bg": "gray2", "attrs": [] },
    "gitstatus_branch_clean":    { "fg": "green",           "bg": "gray2", "attrs": [] },
    "gitstatus_branch_dirty":    { "fg": "gray8",           "bg": "gray2", "attrs": [] },
    "gitstatus_branch_detached": { "fg": "mediumpurple",    "bg": "gray2", "attrs": [] },
    "gitstatus_tag":             { "fg": "darkcyan",        "bg": "gray2", "attrs": [] },
    "gitstatus_behind":          { "fg": "gray10",          "bg": "gray2", "attrs": [] },
    "gitstatus_ahead":           { "fg": "gray10",          "bg": "gray2", "attrs": [] },
    "gitstatus_staged":          { "fg": "green",           "bg": "gray2", "attrs": [] },
    "gitstatus_unmerged":        { "fg": "brightred",       "bg": "gray2", "attrs": [] },
    "gitstatus_changed":         { "fg": "mediumorange",    "bg": "gray2", "attrs": [] },
    "gitstatus_untracked":       { "fg": "brightestorange", "bg": "gray2", "attrs": [] },
    "gitstatus_stashed":         { "fg": "darkblue",        "bg": "gray2", "attrs": [] },
    "gitstatus:divider":         { "fg": "gray8",           "bg": "gray2", "attrs": [] }

3. Activate the Gitstatus segment.

vim .local/lib/python2.7/site-packages/powerline/config_files/colorschemes/default.json


    "function": "powerline_gitstatus.gitstatus",
    "priority": 40

4. Show most recent tag reachable in the current branch.

vim .local/lib/python2.7/site-packages/powerline/config_files/themes/shell/__main__.json


"gitstatus": {
    "args": {
        "show_tag": true

These are json files. Be careful with syntax. If editing existing files, remember to add the necessary commas where needed.



July 23, 2017 Leave a comment

Installing powerline-status

1. pip install –user powerline-status
2. Add the following to .bashrc

if [ -d "$HOME/.local/bin" ]; then

export POWERLINE_COMMAND=powerline
powerline-daemon -q

. ${REPOSITORY_ROOT}/powerline/bindings/bash/

3. Source .bashrc. It may give some errors. Open up a new terminal and see if the changes have taken effect.

$ source .bashrc
bash: /home/rodnee/.local/lib/python2.7/site-packages/powerline/bindings/bash/../../../scripts/powerline-config: No such file or directory
bash: /home/rodnee/.local/lib/python2.7/site-packages/powerline/bindings/bash/../../../scripts/powerline-config: No such file or directory


I could not get it to work with zsh. Opted for instead.

Categories: bash Tags: ,

encryption failed: Unusable public key

April 4, 2017 Leave a comment

Problem: gpg2 gives you an “Unusable public key” error when trying to encrypt a file.

gpg2 --output encrypted_file.gpg  --recipient <mykey> --recipient <other-guy's-key>  --encrypt file-being-encrypted.txt
gpg: <other-guy's-key>: skipped: Unusable public key
gpg: file-being-encrypted.txt: encryption failed: Unusable public key

In this case, the key had expired and needed to be refreshed.

A simple “gpg2 –refresh-keys” failed to run. So I opted to delete the key and try pull it down again.

gpg2 --keyserver hkp:// --recv-keys <other-guy's-key>
gpg: requesting key <other-guy's-key> from hkp server
gpgkeys: key <other-guy's-key> can't be retrieved
gpg: no valid OpenPGP data found.
gpg: Total number processed: 0
gpg: keyserver communications error: keyserver helper general error
gpg: keyserver communications error: Invalid public key algorithm
gpg: keyserver receive failed: Invalid public key algorithm

But when I tried again using an IP

gpg2 --keyserver  --recv-keys <other-guy's-key>
gpg: requesting key <other-guy's-key>8 from hkp server
gpg: key KEYID123: public key "Julius Ceasar <>" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)

Turns out that I need to update my gpg
For mac

$ brew upgrade gpg2

And now gpg2 works as expected without any issues.


Categories: bash Tags:

Ctrl + Left or Right arrow

November 17, 2016 Leave a comment

A colleague introduced me to using “Option + Left” shortcut on OSX. I’d like to set this up on my debian box.

Option/Alt + Left or Right

This shortcut allows you to move the cursor between separate words in a command line. Use Option and the left arrow to move back and use Option with the right arrow to move forward down the line.

I’ll be using “Ctl + Left” to move back and “Ctl + Right” to move forward between separate words.

For bash:
Add the following to .inputrc

"\e[1;5D": backward-word
"\e[1;5C": forward-word

For zsh:
Add this to .zshrc

bindkey '^[[1;5C' forward-word
bindkey '^[[1;5D' backward-word

To find out what is being sent by the keyboard. Type Ctrl + C to quit.

$ cat -v    
# When pressing Ctrl + Left Arrow                           

# When pressing Ctrl + Right Arrow

Source: (Look at the “How can I see what my keyboard sends?” section)

Categories: bash, Interesting, zsh Tags: