Showing posts with label Commands. Show all posts
Showing posts with label Commands. Show all posts

Sunday, 24 May 2015

Do mkdir and cd using a single command?

Most of the times, when you create a new directory, you may cd to it, to do some work.
chetna.chaudhari@Chetna:~$ mkdir -p /a/b/c
chetna.chaudhari@Chetna:~$ cd /a/b/c
chetna.chaudhari@Chetna:~$ pwd
/a/b/c

How about combining these two commands into a single one.? yes its doable. You
to add following snippet to your .bash_profile file and relaunch a shell.
function mkdircd () { mkdir -p "$@" && eval cd "\"\$$#\""; }
Now do mkdir and cd using a single command
chetna.chaudhari@Chetna:~$ mkdircd /x/y/z
chetna.chaudhari@Chetna:~$ pwd
/x/y/z

Thursday, 9 April 2015

How to enable date timestamp in bash history.

Many times while debugging I have a question, when did I execute this command? Here is a way to enable date and timestamp while listing your bash history.

Without date and timestamp, your history will look like
chetna.chaudhari@Chetna:~$ history
ps aux
jps
ls
clear
history

To enable date and timestamp,

chetna.chaudhari@Chetna:~$ export HISTTIMEFORMAT='%F %T '
Here, %F enables date in yyyy-mm-dd format (%Y-%m-%d) %T enables time in hour:minutes:seconds (%H:%M:%S) So now your history should look like
chetna.chaudhari@Chetna:~$ history
1  2015-04-08 19:49:35 ps aux
2  2015-04-08 19:49:35 jps
3  2015-04-08 19:49:35 ls
4  2015-04-08 19:49:35 clear
5  2015-04-08 19:49:36 ps aux | grep sshd
6  2015-04-08 19:49:37 history

To make it permanent add the export command to your .bash_profile file.