Command Alias For Save Typing Time

For lazy Unix user like me, it’s quite nice to have private command which short as a replacement for long command. It can be implement by adding alias to replace some commands that too long to be typed. To make the alias permanently, we must registered it in the profile file.

In my Ubuntu, I can do that by edit $HOME/.bashrc file.

tedy@tedy-laptop:~$ grep alias $HOME/.bashrc
alias dodol='uname -a'
alias ceklog='tail -100 /var/log/messages'
tedy@tedy-laptop:~$

After adding that two aliases, I can type ceklog to saving time typing long command ‘tail -100 /var/log/messages

tedy@tedy-laptop:~$ tail /var/log/messages
Apr 15 09:21:53 tedy-laptop kernel: [   58.990718] Bluetooth: Core ver 2.13
Apr 15 09:21:53 tedy-laptop kernel: [   58.991063] NET: Registered protocol family 31
Apr 15 09:21:53 tedy-laptop kernel: [   58.991068] Bluetooth: HCI device and connection manager initialized
Apr 15 09:21:53 tedy-laptop kernel: [   58.991075] Bluetooth: HCI socket layer initialized
Apr 15 09:21:53 tedy-laptop kernel: [   59.054738] Bluetooth: L2CAP ver 2.11
Apr 15 09:21:53 tedy-laptop kernel: [   59.054752] Bluetooth: L2CAP socket layer initialized
Apr 15 09:21:53 tedy-laptop kernel: [   59.089824] Bluetooth: SCO (Voice Link) ver 0.6
Apr 15 09:21:53 tedy-laptop kernel: [   59.089838] Bluetooth: SCO socket layer initialized
Apr 15 09:21:53 tedy-laptop kernel: [   59.125629] Bluetooth: BNEP (Ethernet Emu

I’ll get the same output like above using the alias command :

tedy@tedy-laptop:~$ ceklog
Apr 15 09:21:53 tedy-laptop kernel: [   58.990718] Bluetooth: Core ver 2.13
Apr 15 09:21:53 tedy-laptop kernel: [   58.991063] NET: Registered protocol family 31
Apr 15 09:21:53 tedy-laptop kernel: [   58.991068] Bluetooth: HCI device and connection manager initialized
Apr 15 09:21:53 tedy-laptop kernel: [   58.991075] Bluetooth: HCI socket layer initialized
Apr 15 09:21:53 tedy-laptop kernel: [   59.054738] Bluetooth: L2CAP ver 2.11
Apr 15 09:21:53 tedy-laptop kernel: [   59.054752] Bluetooth: L2CAP socket layer initialized
Apr 15 09:21:53 tedy-laptop kernel: [   59.089824] Bluetooth: SCO (Voice Link) ver 0.6
Apr 15 09:21:53 tedy-laptop kernel: [   59.089838] Bluetooth: SCO socket layer initialized
Apr 15 09:21:53 tedy-laptop kernel: [   59.125629] Bluetooth: BNEP (Ethernet Emu

To make the alias works for all user in the system, we must register the alias in the /etc/bash.bashrc

root@tedy-laptop:~# vi /etc/bash.bashrc
alias ceklog='tail -100f /var/log/messages'
root@tedy-laptop:~#

Remember : after add item in the .bashrc we must close the current shell first to let the alias works. Look the example below; my alias works like a charm.

We can create alias on the fly, means the alias only works for the current session. Just define alias without need to register it on the profile file.

ttirtawi@tedy-laptop:~$ tail -f /var/log/messages
Jan  5 14:40:10 tedy-laptop kernel: [676524.119390] type=1503 audit(1294213210.631:1324):  operation="open" pid=1658 parent=1 profile="/usr/bin/freshclam" requested_mask="::r" denied_mask="::r" fsuid=120 ouid=0 name="/etc/resolv.conf.speedy"
Jan  5 14:40:15 tedy-laptop kernel: [676529.125544] type=1503 audit(1294213215.640:1325):  operation="open" pid=1658 parent=1 profile="/usr/bin/freshclam" requested_mask="::r" denied_mask="::r" fsuid=120 ouid=0 name="/etc/resolv.conf.speedy"
Jan  5 14:40:20 tedy-laptop kernel: [676534.134552] type=1503 audit(1294213220.647:1326):  operation="open" pid=1658 parent=1 profile="/usr/bin/freshclam" requested_mask="::r" denied_mask="::r" fsuid=120 ouid=0 name="/etc/resolv.conf.speedy"
Jan  5 14:40:21 tedy-laptop pulseaudio[2122]: ratelimit.c: 582 events suppressed
Jan  5 14:40:33 tedy-laptop pulseaudio[2122]: ratelimit.c: 604 events suppressed
Jan  5 14:41:35 tedy-laptop pulseaudio[2122]: ratelimit.c: 379 events suppressed
Jan  5 14:43:33 tedy-laptop pulseaudio[2122]: ratelimit.c: 717 events suppressed
Jan  5 14:43:49 tedy-laptop pulseaudio[2122]: ratelimit.c: 592 events suppressed
Jan  5 14:44:08 tedy-laptop pulseaudio[2122]: ratelimit.c: 586 events suppressed
Jan  5 14:54:40 tedy-laptop pulseaudio[2122]: ratelimit.c: 595 events suppressed
^C
ttirtawi@tedy-laptop:~$ alias dodol='tail -f /var/log/messages';
ttirtawi@tedy-laptop:~$ dodol
Jan  5 14:40:10 tedy-laptop kernel: [676524.119390] type=1503 audit(1294213210.631:1324):  operation="open" pid=1658 parent=1 profile="/usr/bin/freshclam" requested_mask="::r" denied_mask="::r" fsuid=120 ouid=0 name="/etc/resolv.conf.speedy"
Jan  5 14:40:15 tedy-laptop kernel: [676529.125544] type=1503 audit(1294213215.640:1325):  operation="open" pid=1658 parent=1 profile="/usr/bin/freshclam" requested_mask="::r" denied_mask="::r" fsuid=120 ouid=0 name="/etc/resolv.conf.speedy"
Jan  5 14:40:20 tedy-laptop kernel: [676534.134552] type=1503 audit(1294213220.647:1326):  operation="open" pid=1658 parent=1 profile="/usr/bin/freshclam" requested_mask="::r" denied_mask="::r" fsuid=120 ouid=0 name="/etc/resolv.conf.speedy"
Jan  5 14:40:21 tedy-laptop pulseaudio[2122]: ratelimit.c: 582 events suppressed
Jan  5 14:40:33 tedy-laptop pulseaudio[2122]: ratelimit.c: 604 events suppressed
Jan  5 14:41:35 tedy-laptop pulseaudio[2122]: ratelimit.c: 379 events suppressed
Jan  5 14:43:33 tedy-laptop pulseaudio[2122]: ratelimit.c: 717 events suppressed
Jan  5 14:43:49 tedy-laptop pulseaudio[2122]: ratelimit.c: 592 events suppressed
Jan  5 14:44:08 tedy-laptop pulseaudio[2122]: ratelimit.c: 586 events suppressed
Jan  5 14:54:40 tedy-laptop pulseaudio[2122]: ratelimit.c: 595 events suppressed
^C
ttirtawi@tedy-laptop:~$

Sometime in UNIX environment which not using Bash shell, we can put the alias in /etc/profile.

Leave a Reply