Category Archives: quickies

Bash Function to find files with a certain extension

ls_ext () { find . -type f -iname '*.'${1}'' -exec ls -l {} \; ; }


ls_ext ()
 find . -type f -iname '*.'${1}'' -exec ls -l {} \; ;

then type “ls_ext pdf” or “ls_ext txt”

use unset -f function-name in this case “unset -f ls_ext” to clear the function.

Function to test multiple commands.

function mytest {
    local status=$?
    if [ $status -ne 0 ]; then
        echo "error with $1" >&2
    return $status

mytest $command1
mytest $command2

Renaming Lists of Files

list of current files “test-file1.txt test-file2.txt  test-file3.txt  test-file4.txt”

change .txt to .html with rename

rename .txt .html *.txt

new list “test-file1.html  test-file2.html  test-file3.html  test-file4.html”

or use a for loop

for i in *.txt; do mv "$i" "$(basename $i .txt).html"; done OR for i in *.txt; do mv "$i" "`basename $i .txt`.html"; done

Add a prefix to every filename

for f in *.txt ; do mv "$f" "PREFIX_$f" ; done

new list “PREFIX_test-file1.txt  PREFIX_test-file2.txt  PREFIX_test-file3.txt  PREFIX_test-file4.txt”

Add a suffix

for f in *.txt ; do mv "$f" "$f_SUFFIX" ; done

Remove the PREFIX_ from every filename, adjust the cut command accordingly

for name in PREFIX_* ; do newname="$(echo "$name" | cut -b8-)"; mv "$name" "$newname" ; done

new list “test-file1.txt  test-file2.txt  test-file3.txt  test-file4.txt”

Remove the extension from file names

for i in $(ls); do mv $i ${i%.*}; done

Remove a prefix from file names

for i in $(ls *.txt); do mv $i ${i#*-};done

using a for loop and mv

for file in $(ls); do mv -i "${file}" "${file/Disc_1_-_/}"; done





Get the light to flash on an external drive

If you have multiple external drives connected and you need to know which one’s which you can use either of these commands to get it to flash the activity light.

The reason I needed to do this was because I have 3 external usb drives configured as a raid 5. No hot spare so if I see drive error’s they need to be addressed immediately.

X = the drive letter in question.

for i in {1..5}; do hdparm -tT /dev/sdX; done


for i in {1..10}; do dd if=/dev/sdX of=/dev/null bs=10M count=20; done

Installing Vim Pathogen


Manage your 'runtimepath' with ease. In practical terms, pathogen.vim makes it super easy to install plugins and runtime files in their own private directories.


Install to ~/.vim/autoload/pathogen.vim. Or copy and paste:

mkdir -p ~/.vim/autoload ~/.vim/bundle && \
curl -LSso ~/.vim/autoload/pathogen.vim

If you’re using Windows, change all occurrences of ~/.vim to ~\vimfiles.

Runtime Path Manipulation

Add this to your vimrc:

execute pathogen#infect()

If you’re brand new to Vim and lacking a vimrc, vim ~/.vimrc and paste in the following super-minimal example:

execute pathogen#infect()
syntax on
filetype plugin indent on

Now any plugins you wish to install can be extracted to a subdirectory under ~/.vim/bundle, and they will be added to the 'runtimepath'. Observe:

cd ~/.vim/bundle && \
git clone git://

Now sensible.vim is installed. If you really want to get crazy, you could set it up as a submodule in whatever repository you keep your dot files in. I don’t like to get crazy.

If you don’t like the directory name bundle, you can pass a runtime relative glob as an argument:

execute pathogen#infect('stuff/{}')

The {} indicates where the expansion should occur.

You can also pass an absolute path instead. I keep the plugins I maintain under ~/src, and this is how I add them:

execute pathogen#infect('bundle/{}', '~/src/vim/bundle/{}')

Normally to generate documentation, Vim expects you to run :helptags on each directory with documentation (e.g., :helptags ~/.vim/doc). Provided with pathogen.vim is a :Helptags command that does this on every directory in your 'runtimepath'. If you really want to get crazy, you could even invoke Helptags in your vimrc. I don’t like to get crazy.

Finally, pathogen.vim has a rich API that can manipulate 'runtimepath' and other comma-delimited path options in ways most people will never need to do. If you’re one of those edge cases, look at the source. It’s well documented.

change from booting graphical mode to multiuser with systemd

With systemd you can switch from graphical mode to multiuser by typing init 3 as root

or systemctl isolate

If you want to permanently change and save resources

systemctl set-default <name of target>.target

The full list of targets can be accessed with systemctl list-units –type=target

or do

rm /etc/systemd/system/

then do

ln -s /lib/systemd/system/ /etc/systemd/system/

when you reboot your machine it should start up with a nice black screen and login: