Skip to content

Yet another programming solutions log

Sample bits from programming for the future generations.

Technologies Technologies
  • Algorithms and Data Structures
  • Java Tutorials
  • JUnit Tutorial
  • MongoDB Tutorial
  • Quartz Scheduler Tutorial
  • Spock Framework Tutorial
  • Spring Framework
  • Bash Tutorial
  • Clojure Tutorial
  • Design Patterns
  • Developer’s Tools
  • Productivity
  • About
Expand Search Form

Bash command alias

farenda 2015-05-20 0

Problem:

Bash alias is a great way to create a simple name for complex commands. Use it to make your life in Bash command line simpler!

Solution:

First, lets use alias command to see what Bash aliases are already defined:

$> alias
alias cljsbuild='lein trampoline cljsbuild '
alias la='ls -A'
alias ll='ls -lAF'

alias command just prints list of all defined aliases. It’s the same as passing -p parameter: alias -p.

Now we can define our own Bash alias for frequently used command, which in our example is listing all files in reverse order by time:

$> alias lt='ls -ltr'

Let’s verify that the alias is defined:

$> alias
alias cljsbuild='lein trampoline cljsbuild '
alias la='ls -A'
alias ll='ls -lAF'
alias lt='ls -ltr'

As you can see it’s the 4th of the aliases. From now on you can run it using the new command: lt.

So, let’s execute it:

$> lt /boot
total 122927
drwxr-xr-x 2 root root    12288 Mar 31  2013 lost+found
-rw-r--r-- 1 root root   178680 Mar 12  2014 memtest86+_multiboot.bin
-rw-r--r-- 1 root root   178176 Mar 12  2014 memtest86+.elf
-rw-r--r-- 1 root root   176500 Mar 12  2014 memtest86+.bin
-rw------- 1 root root  6412672 Apr 10 21:03 vmlinuz-3.16.0-34-generic
-rw------- 1 root root  3502413 Apr 10 21:03 System.map-3.16.0-34-generic
-rw-r--r-- 1 root root   171819 Apr 10 21:03 config-3.16.0-34-generic
-rw-r--r-- 1 root root  1207327 Apr 10 21:03 abi-3.16.0-34-generic
-rw-r--r-- 1 root root 30304372 Apr 14 16:04 initrd.img-3.16.0-34-generic
-rw------- 1 root root  6414272 Apr 14 22:48 vmlinuz-3.16.0-36-generic
-rw------- 1 root root  3502913 Apr 14 22:48 System.map-3.16.0-36-generic
-rw-r--r-- 1 root root   171808 Apr 14 22:48 config-3.16.0-36-generic
-rw-r--r-- 1 root root  1206938 Apr 14 22:48 abi-3.16.0-36-generic
-rw-r--r-- 1 root root 30311331 May  4 08:54 initrd.img-3.16.0-36-generic
-rw------- 1 root root  6416256 May  5 16:46 vmlinuz-3.16.0-37-generic
-rw------- 1 root root  3502913 May  5 16:46 System.map-3.16.0-37-generic
-rw-r--r-- 1 root root   171808 May  5 16:46 config-3.16.0-37-generic
-rw-r--r-- 1 root root  1206938 May  5 16:46 abi-3.16.0-37-generic
-rw-r--r-- 1 root root 30310319 May 11 11:20 initrd.img-3.16.0-37-generic
drwxr-xr-x 5 root root     1024 May 11 11:20 grub

It’s good idea to put frequently used aliases in ~/.bash_aliases file and include from ~/.bashrc like so:

if [ -f ~/.bash_aliases ]; then
  . ~/.bash_aliases
fi

This makes them always accessible when you use Bash command line.

Share with the World!
Categories Bash Tags bash
Next: Java “Hello world!”

Recent Posts

  • Java 8 Date Time concepts
  • Maven dependency to local JAR
  • Caesar cipher in Java
  • Java casting trick
  • Java 8 flatMap practical example
  • Linked List – remove element
  • Linked List – insert element at position
  • Linked List add element at the end
  • Create Java Streams
  • Floyd Cycle detection in Java

Pages

  • About Farenda
  • Algorithms and Data Structures
  • Bash Tutorial
  • Bean Validation Tutorial
  • Clojure Tutorial
  • Design Patterns
  • Java 8 Streams and Lambda Expressions Tutorial
  • Java Basics Tutorial
  • Java Collections Tutorial
  • Java Concurrency Tutorial
  • Java IO Tutorial
  • Java Tutorials
  • Java Util Tutorial
  • Java XML Tutorial
  • JUnit Tutorial
  • MongoDB Tutorial
  • Quartz Scheduler Tutorial
  • Software Developer’s Tools
  • Spock Framework Tutorial
  • Spring Framework

Tags

algorithms bash bean-validation books clojure design-patterns embedmongo exercises git gof gradle groovy hateoas hsqldb i18n java java-basics java-collections java-concurrency java-io java-lang java-time java-util java-xml java8 java8-files junit linux lists log4j logging maven mongodb performance quartz refactoring regex rest slf4j solid spring spring-boot spring-core sql unit-tests

Yet another programming solutions log © 2021

sponsored