3 ms·
Yet another time saver: if you need to execute only a single command in another directory, use: (cd /path; command) This will cd to /path, run command, but
by julian37 16y ago
Yet another time saver: if you need to execute only a single command in another directory, use:
(cd /path; command)
This will cd to /path, run command, but return you to your original working directory. This works because the parens create a sub-process, and the cd command only affects that sub-process.
- technomancy 16y agoAppending ";cd -" on the end will have the same effect.
- semanticist 16y agoI prefer (cd /path && command), since that way if the cd fails for some reason (like you've typo'd the path), it won't still attempt to run the command.
- julian37 16y agoOf course! I actually do always use double-ampersand for chaining commands in bash, not sure what made me use a semicolon in that example. Thanks for the correction, a small but important distinction.