Get a filename only list of files in a folder

To get a list of all files in a folder without path, you can use the following snippet:

Example result:

Prefix files: If you want to prefix files, you can use the same command too:

Example result:

 

Base64 encode on shell

Sometimes you need to encode a string  with a base64 encoding. For example when trying to send a HTTP request with a Basic Authentication header like that:

As you can see the Basic Auth username and password are included in the request as a base64 encoded string. On the Linux shell this string can […]

Remove all files and folders including hidden files on bash

To remove all files and folders including hidden files such .gitignore, .htaccess, .git etc. on bash you can use the following command:

Is the same as:

But ever shorter. ūüėČ

GIT – reconnect remote branch

Sometimes it is necessary to remap a local git¬† branch to a remote one (reconnect remote branch). For me it was the case, because I accidentally removed all origins in a multi-origin setup. Hence I got the following error message when trying to pull without naming remote and branch, although I re-added and fetched all […]

Delete x files from folder in a for i loop

Recently I tried to remove a big bunch of files from one of my raspberry pies where ffmpeg had swamped my SD-card with too many capture images. So I had to delete x files from folder. I just tried:

But that gave me an “unable to execute /bin/rm: Argument list too long” error message. […]

Lock shellscript process under Unix based systems

Today I ran again into a common problem when dealing with cron based scipts that run concurrently. That’s why I had to lock shellscript process until it is finished before starting the next executing round. On Unix based systems like Linux you can achieve that with flock. flock binds¬†a file descriptor to a certain lock […]

Associative arrays (hash, dictionary) on bash

This is how to create associative arrays (hash, dictionary) on bash:

This script was made to¬†purge the varnish on one of my clusters. But the important stuff is the declaration of the associative array with¬† DOMAINS['LIVE']="www.ask-sheldon.com";¬†and how to access the values of the array (with¬† REQUEST_DOMAIN=${DOMAINS["$1"]};). “$1” is the array key to select the value. By the […]