Shell-Scripts

Utility Scripts

`better-cd

Wrapper for cd, but it creates parent directories specified in the target.

Usage

You can save the file as /usr/local/bin/bcd (short for better change directory) to run it as a command.

bcd this/path/doesnt/exist

Just like cd, but creates parents. May not have some cd features. Doesn’t support flags.

Because cd doesn’t work in scripts unless you use source, you need to add this to ~/.bashrc (or equivalent):

alias bcd='source /usr/local/bin/bcd'

Then run:

source ~/.bashrc

To reload

better-cp

Wrapper for cp, but it creates parent directories specified in the target.

Usage

You can save the file as /usr/local/bin/bcp (short for better copy) to run it as a command.

bcp /path/to/source /path/to/destination

Just like cp, but creates parents. May not have some cp features. Doesn’t support flags.

better-mv

Wrapper for mv, but it creates parent directories specified in the target.

Usage

You can save the file as /usr/local/bin/bmv (short for better move) to run it as a command.

bmv /path/to/source /path/to/destination

Just like mv, but creates parents. May not have some mv features. Doesn’t support flags.

cat-dir

Runs cat on each file in the given directory. Best use-case is to read a bunch of small files quickly.

Usage

./cat-dir <dir1> [dir2] [dir3]

Example:

./cat-dir ~/GitHub/ ~/GitHub/NikoboiNFTB/Shell-Scripts/
bash cat-dir ~/GitHub/ ~/GitHub/NikoboiNFTB/Shell-Scripts/

Or if placed in /usr/local/bin/cat-dir (recommended):

cat-dir ~/GitHub/ ~/GitHub/NikoboiNFTB/Shell-Scripts/

find-file

Simple to use tool to find a file or folder anywhere in the current directory, while allowing you to ignore directories.

Usage

Simply save the script in any folder and run:

bash find-file file1 file2 -i dir1 dir2

For example, if I want to find all README* files, except from my repositories:

bash find-file README* -i NikoboiNFTB

Much easier than running;

find . \( -name "README.md" -o -name "README.txt" -o -name "README" \) | grep -Ev "NikoboiNFTB"

find-string

Similar to find-file but for file contents. Supports -b | --begin to find strings only at the beginning of lines.

linkify

Filter out everything except for links in a given file.

Usage

./linkify <file1> [file2] [file3]

Works with many files.

repeat

Repeat any command every given seconds. Optionally also clear the terminal between each command.

Usage

bash repeat [--clear] <command_in_quotes> <interval_in_seconds>

Any order

Example:

repeat --clear "docker ps" 1

In this case the script has been placed in `/usr/local/bin/

Will run “ls -l” every five seconds, while clearing the terminal before each run.

This script is equivalent to running;

while true; do [clear &&] <command> && sleep <interval>; done

sort

Sort any file alphabetically.

Usage

Save the script and run it anywhere:

bash sort <file>

This is a general use version of the sort file from NikoboiNFTB/DeSlop/block/sort