30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X


#1

Originally published at: https://www.cyberciti.biz/tips/bash-aliases-mac-centos-linux-unix.html


An alias is nothing but shortcut to commands. The alias command allows user to launch any command or group of commands (including options and filenames) by entering a single word. Use alias command to display list of all defined aliases. You can add user defined aliases to ~/.bashrc file. You can cut down typing time with these aliases, work smartly, and increase productivity at the command prompt.

Could not add comment to article 30 Handy Bash Shell scripts
#2

I wanted to gift back to the author and the community, but could not add a comment to the article directly so here is my 2 cents worth of Bashery

for creating a backup file if a file is overwritten by cp
I use \cp to make sure I do not use the aliase verson of cp

    alias cp='cp -i'
    alias cpk='\cp --backup=numbered'

    function bak()   # will create a .bak copy of 1 or n files, safe even if created within a second
    {
        for file ; do
            \cp --backup=numbered "$file" "$file".bak-`date +%y%m%d-%H:%M:%S`;
        done
    }

to test:

    echo >1 "test" . echo >2 "test"
    bak 1 2; bak 1 2; bak 1; 2 
    ll

Outputs:

-rw-r--r--  1 root root    5 Nov 15 18:18 1.bak-181115-18:18:58
-rw-r--r--  1 root root    5 Nov 15 18:18 1.bak-181115-18:18:58.~1~
-rw-r--r--  1 root root    5 Nov 15 18:18 1.bak-181115-18:18:58.~2~

-rw-r--r--  1 root root    5 Nov 15 18:18 2.bak-181115-18:18:58
-rw-r--r--  1 root root    5 Nov 15 18:18 2.bak-181115-18:18:58.~1~
-rw-r--r--  1 root root    5 Nov 15 18:18 2.bak-181115-18:18:58.~2~

#3

Hi,

It is my fault as I forget to add comments url in WP. You can continue discussion here. Thanks!