From 7c7571dca9e074060a4220b3409c8da98d274e6f Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Mon, 1 May 2017 12:20:19 -0500 Subject: [PATCH] Add Change To That New Directory as a unix til --- README.md | 3 ++- unix/change-to-that-new-directory.md | 31 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 unix/change-to-that-new-directory.md diff --git a/README.md b/README.md index d44c05d..3385666 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/). For a steady stream of TILs from a variety of rocketeers, checkout [til.hashrocket.com](https://til.hashrocket.com/). -_529 TILs and counting..._ +_530 TILs and counting..._ --- @@ -454,6 +454,7 @@ _529 TILs and counting..._ - [All The Environment Variables](unix/all-the-environment-variables.md) - [Cat A File With Line Numbers](unix/cat-a-file-with-line-numbers.md) - [Change Default Shell For A User](unix/change-default-shell-for-a-user.md) +- [Change To That New Directory](unix/change-to-that-new-directory.md) - [Check If A Port Is In Use](unix/check-if-a-port-is-in-use.md) - [Check The Current Working Directory](unix/check-the-current-working-directory.md) - [Clear The Screen](unix/clear-the-screen.md) diff --git a/unix/change-to-that-new-directory.md b/unix/change-to-that-new-directory.md new file mode 100644 index 0000000..8cb1d1c --- /dev/null +++ b/unix/change-to-that-new-directory.md @@ -0,0 +1,31 @@ +# Change To That New Directory + +The `$_` variable provided by bash is always set to the last argument of the +previous command. One handy use of this is for changing directories into a +newly created directory. + +```bash +$ mkdir new_dir && cd $_ +``` + +This command will leave you in your newly created directory, `new_dir`. + +We can imagine using this bash variable in a number of similar scenarios as +well. What if we are using some language specific command that creates a +directory? Will it work with create a new Phoenix or Rails project? + +It sure will. + +Give it a try with Phoenix: + +```bash +mix phx.new my_app && cd $_ +``` + +or with Rails: + +```bash +rails new app && cd $_ +``` + +[source](http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_02.html)