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 Linux, I can do that by edit $HOME/.bashrc
file.
tedy@tedy-laptop:~$ tail $HOME/.bashrc .... 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'
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.
tedy@tedy-laptop:~$ ceklog .... .... Apr 15 14:46:07 tedy-laptop kernel: [19512.722594] usb 1-2: new full speed USB device using uhci_hcd and address 2 Apr 15 14:46:07 tedy-laptop kernel: [19512.910427] usb 1-2: configuration #1 chosen from 1 choice Apr 15 14:46:07 tedy-laptop kernel: [19513.477569] Bluetooth: Generic Bluetooth USB driver ver 0.3 Apr 15 14:46:07 tedy-laptop kernel: [19513.477666] usbcore: registered new interface driver btusb Apr 15 14:46:10 tedy-laptop kernel: [19516.500204] usb 1-2: USB disconnect, address 2 Apr 15 14:47:29 tedy-laptop kernel: [19595.184588] sky2 eth0: disabling interface Apr 15 14:47:29 tedy-laptop kernel: [19595.221700] iwlagn 0000:0c:00.0: PCI INT A disabled Apr 15 14:47:34 tedy-laptop kernel: [19600.563508] sky2 eth0: enabling interface Apr 15 14:47:34 tedy-laptop kernel: [19600.568480] ADDRCONF(NETDEV_UP): eth0: link is not ready Apr 15 14:47:34 tedy-laptop kernel: [19600.575494] iwlagn 0000:0c:00.0: PCI INT A -> GSI 18 (level, low) -> IRQ 18 Apr 15 14:47:34 tedy-laptop kernel: [19600.575836] iwlagn: Radio disabled by HW RF Kill switch Apr 15 14:47:34 tedy-laptop kernel: [19600.583516] ADDRCONF(NETDEV_UP): wlan0: link is not ready Apr 15 14:47:36 tedy-laptop kernel: [19602.249848] sky2 eth0: Link is up at 100 Mbps, full duplex, flow control both Apr 15 14:47:36 tedy-laptop kernel: [19602.250324] ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
You can see that the alias give me the same output when I execute tail -100 /var/log/messages
:
tedy@tedy-laptop:~$ tail -100 /var/log/messages .... .... Apr 15 14:46:07 tedy-laptop kernel: [19512.722594] usb 1-2: new full speed USB device using uhci_hcd and address 2 Apr 15 14:46:07 tedy-laptop kernel: [19512.910427] usb 1-2: configuration #1 chosen from 1 choice Apr 15 14:46:07 tedy-laptop kernel: [19513.477569] Bluetooth: Generic Bluetooth USB driver ver 0.3 Apr 15 14:46:07 tedy-laptop kernel: [19513.477666] usbcore: registered new interface driver btusb Apr 15 14:46:10 tedy-laptop kernel: [19516.500204] usb 1-2: USB disconnect, address 2 Apr 15 14:47:29 tedy-laptop kernel: [19595.184588] sky2 eth0: disabling interface Apr 15 14:47:29 tedy-laptop kernel: [19595.221700] iwlagn 0000:0c:00.0: PCI INT A disabled Apr 15 14:47:34 tedy-laptop kernel: [19600.563508] sky2 eth0: enabling interface Apr 15 14:47:34 tedy-laptop kernel: [19600.568480] ADDRCONF(NETDEV_UP): eth0: link is not ready Apr 15 14:47:34 tedy-laptop kernel: [19600.575494] iwlagn 0000:0c:00.0: PCI INT A -> GSI 18 (level, low) -> IRQ 18 Apr 15 14:47:34 tedy-laptop kernel: [19600.575836] iwlagn: Radio disabled by HW RF Kill switch Apr 15 14:47:34 tedy-laptop kernel: [19600.583516] ADDRCONF(NETDEV_UP): wlan0: link is not ready Apr 15 14:47:36 tedy-laptop kernel: [19602.249848] sky2 eth0: Link is up at 100 Mbps, full duplex, flow control both Apr 15 14:47:36 tedy-laptop kernel: [19602.250324] ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
To make the alias works for all user in the system, we must register the alias in the /etc/bash.bashrc
root@tedy-laptop:~/bin# vi /etc/bash.bashrc .... alias ceklog='tail -100 /var/log/messages' ....
Other UNIX/Linux distro maybe have different global profile definition file. Solaris for example, use /etc/profile
to store all global profile parameters.
Pingback: Blognya Tedy Tirtawidjaja