Posted in bash

Changing directories

Everyone knows the command cd – everyone uses it several times a day. (OK – not everyone, but every Linux user.) Most of us know, that we can change back to the last directory with

$ cd -

E.g.:

$ pwd
/home/maker/docs/sensors
$ cd /opt/sensors/bmp280
$ pwd
/opt/sensors/bmp280
$ cd -
$ pwd
/home/maker/docs/sensors

But what if you cd in your project directory and then need to change back into your docs directory? You have to type the whole path. Or do you?

Continue reading “Changing directories”

Advertisements
Posted in bash

Make and Change into Directory

Several times a day I have to create a directory and have immediately change into this directory. After a while I found it rather annoying to type every time

$ mkdir new_directory
$ cd new_directory

So I created a shell function to reduce the typing:

mcd ()
{
    mkdir -p "$@" && cd "$@"
}

Now I have to type only

$ mcd new_directory

and magically I’m in the newly created directory.

Posted in bash

Make a Directory with Actual Date

For different workflows I like to have directories with the actual date as name. To this end I created a little bash function called mkdd (make date directory), which I put into my .bashrc:

mkdd ()
{
    D=$(date '+%F')
    mkdir $D
    cd $D
}

This function creates the directory with the actual date in ISO format and changes into it:

$ pwd
/home/maker/tmp
$ mkdd
$ pwd
/home/maker/tmp/2017-04-09