Bash Quick Tip - Subshells

RustyRazorblade Consulting RustyRazorblade Consulting
1 min read

terminal-icon-512x512.png When you’re in a shell, and you want to do 1 or 2 commands in another brand new shell, but don’t feel like opening a new window, try using a subshell.

Here’s an example:

~ jhaddad$ pwd
/Users/jhaddad
~ jhaddad$ ( cd /tmp/; touch bacon.txt )
~ jhaddad$ pwd
/Users/jhaddad
~ jhaddad$ ls -lah /tmp/bacon.txt
-rw-r--r--  1 jhaddad  wheel     0B Apr 15 13:09 /tmp/bacon.txt

Why I like it: I can very quickly fire off a command that involves changing directories without having to switch back to my pwd.

terminal-icon-512x512.png When you’re in a shell, and you want to do 1 or 2 commands in another brand new shell, but don’t feel like opening a new window, try using a subshell.

Here’s an example:

~ jhaddad$ pwd
/Users/jhaddad
~ jhaddad$ ( cd /tmp/; touch bacon.txt )
~ jhaddad$ pwd
/Users/jhaddad
~ jhaddad$ ls -lah /tmp/bacon.txt
-rw-r--r--  1 jhaddad  wheel     0B Apr 15 13:09 /tmp/bacon.txt

Why I like it: I can very quickly fire off a command that involves changing directories without having to switch back to my pwd.

RustyRazorblade Consulting

RustyRazorblade Consulting

Apache Cassandra Consultant and Distributed Systems Expert

Related Posts

Need Expert Help with Apache Cassandra?

Get professional consulting for your distributed systems challenges. Performance optimization, architecture design, and troubleshooting.