Home > Bash, Tip > A few useful BASH shortcuts

A few useful BASH shortcuts

Here are some of the shortcuts that I use quite often:

$_ ( $_ is the last argument of the last command )
Example 1:
ls /a/very/deep/and/not/easy/to/find/folder/
(once confirm that’s the folder I want, I might want to go there, so I use the following command, right after the ls command)
cd $_
(it’ll take me right to the folder /a/very/deep/and/not/easy/to/find/folder/)

Example 2:
vi ~/work/html/todaysnote.html
cp $_ ~/public_html/pub

(In the above example, $_ is actually ~/work/html/todaysnote.html)

cd – (dash)
when working between two different pwd’s, cd – makes toggling between current and last visited folders a lot easier

cd (without arguments)
will change to ~ (home folder)

empty a file from command line
cat /dev/null > somefile
note this command will be equivalent to the following if somefile doesn’t already exist:
touch somefile
Ref: http://lifehacker.com/#!270790/empty-a-text-file-from-the-command-line

Categories: Bash, Tip
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: