Some bash tips (1)

Here are some bash tips that might be useful to you for a better and more efficient use of the bash shell.

The variable CDPATH

This variable expands the scope of the cd command.
By default, cd looks for a possible subdirectory in the current working directory.
Let us take an example :

fool@localhost:~$ cd cron

If CDPATH is not set, cd will look for a subdirectory named cron. If it does not exist, cd will look through the directories added to CDPATH. As we want to display the content of the directory /var/spool/cron, here is what we have to do :

fool@localhost:~$ export CDPATH=/var/spool/cron

Then, cd cron will work well and the current working directory will be /var/spool/cron

The bash builtin fc

fc displays a list of all the latest commands typed. It is like the command history.

To list the 16 lastest commands typed :

fool@localhost:~$ fc -l

To list a range of commands typed :

fool@localhost:~$ fc -l 495 501

The numbers 495 and 501 refers to the lines numbers displayed by the command history.

To reexecute the command number 495

fool@localhost:~$ fc -s 495


One thought on “Some bash tips (1)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.