TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Level Up Your Shell Game

91 pointsby dceover 11 years ago

17 comments

agscalaover 11 years ago
I didn&#x27;t see Ctrl-r, but I&#x27;ve found that to be the most insanely useful shortcut.<p>Ctrl-r = reverse history search. Type a partial command after Ctrl-r and it&#x27;ll find the most recent executed command with that substring in it.<p>Press Ctrl-r again, jump to the next oldest command containing your substring. Did you accidentally press too many Ctrl-r? Press backspace to move forward in history.
评论 #6608603 未加载
评论 #6609235 未加载
评论 #6610679 未加载
评论 #6607173 未加载
bstpierreover 11 years ago
IMO the aliases for git should be in ~&#x2F;.gitconfig instead. I have a bunch of these, like:<p><pre><code> [alias] br = branch co = checkout ci = commit -v sci = svn dcommit --interactive cp = cherry-pick l = log --pretty=oneline --abbrev-commit l3 = log --pretty=oneline --abbrev-commit -n3 lm = log --pretty=oneline --abbrev-commit master.. rc = rebase --continue st = status -sb squash = !git rebase -i --autosquash $(git merge-base master HEAD) </code></pre> Also, I prefer to set aliases in my ~&#x2F;.functions instead of in ~&#x2F;.bash_profile or ~&#x2F;.bashrc. I find that this makes it easier to move the .functions file from one machine to another, especially on a lab&#x2F;test machine with a shared account where I shouldn&#x27;t be modifying things in the shared ~&#x2F;.bashrc. To make this work, you can add this to your ~&#x2F;.bashrc or ~&#x2F;.bash_profile:<p><pre><code> if [ -f ~&#x2F;.functions ]; then . ~&#x2F;.functions; fi </code></pre> This will source your .functions file if it exists when your .bashrc is run.<p>A tweak to the &quot;editbash&quot; suggested alias will make it so that you don&#x27;t have to reopen your terminal. My equivalent alias is &quot;vif&quot;, for &quot;vi .functions&quot;:<p><pre><code> alias vif=&#x27;vi ~&#x2F;.functions; . ~&#x2F;.functions&#x27; </code></pre> Note that the second command (after the semicolon) sources the modified .functions file.<p>Lastly: brevity is king. I love &#x27;alias psgrep=&quot;ps aux | grep&quot;&#x27;, since I use it several times a day, but to &quot;level up your shell game&quot;, keep it short. My alias for this command is &quot;psg&quot;. The other alias that I use all the time is &quot;d&quot; -- &quot;alias d=&#x27;ls -lFh --color --group-directories -v&#x27;&quot;.
评论 #6610685 未加载
评论 #6608382 未加载
评论 #6608641 未加载
rwl4over 11 years ago
My favorite shell trick (not in the link) is this: ~-<p>Tilde-hyphen expands to the previous directory you were in, and of course &quot;cd -&quot; returns you to your previous directory, so I put them together all the time.<p>Here&#x27;s an example workflow (with a fake PS1):<p><pre><code> mac:&#x2F;Users&#x2F;me&#x2F;Projects&#x2F;my_new_app$ cd ~&#x2F;.pow mac:&#x2F;Users&#x2F;me&#x2F;.pow$ ln -s ~- . mac:&#x2F;Users&#x2F;me&#x2F;.pow$ cd - mac:&#x2F;Users&#x2F;me&#x2F;Projects&#x2F;my_new_app$ </code></pre> Now I can continue working on my app.<p>&lt;disclaimer&gt;<p>That&#x27;s bit of a contrived example above. Here&#x27;s a more realistic way to do a symlink for pow:<p><pre><code> mac:&#x2F;Users&#x2F;me&#x2F;Projects&#x2F;my_new_app$ ln -s `pwd` ~&#x2F;.pow&#x2F; </code></pre> &lt;&#x2F;disclaimer&gt;
评论 #6607885 未加载
patrickmayover 11 years ago
The command line navigation commands are just what any Emacs user would expect. vi users can set their $EDITOR to &#x27;vi&#x27; to get those commands.<p>What do you mean you&#x27;ve never used Emacs? <i>mumble whippersnappers mumble</i>
评论 #6607573 未加载
dmouratiover 11 years ago
Everything you ever wanted to know about SSH keys but were afraid to ask:<p><a href="http://www.ibm.com/developerworks/opensource/library/l-keyc/index.html" rel="nofollow">http:&#x2F;&#x2F;www.ibm.com&#x2F;developerworks&#x2F;opensource&#x2F;library&#x2F;l-keyc&#x2F;...</a><p><a href="http://webcache.googleusercontent.com/search?q=cache:n5M47jV8tSkJ:www.ibm.com/developerworks/library/l-keyc2/+&amp;cd=1&amp;hl=en&amp;ct=clnk&amp;gl=us" rel="nofollow">http:&#x2F;&#x2F;webcache.googleusercontent.com&#x2F;search?q=cache:n5M47jV...</a><p><a href="http://webcache.googleusercontent.com/search?q=cache:BzFiI_7zLoMJ:www.ibm.com/developerworks/library/l-keyc3/+&amp;cd=1&amp;hl=en&amp;ct=clnk&amp;gl=us" rel="nofollow">http:&#x2F;&#x2F;webcache.googleusercontent.com&#x2F;search?q=cache:BzFiI_7...</a><p>(pt2&#x2F;pt3 borked on IBMs site)
yonaguskaover 11 years ago
It&#x27;s probably worth mentioning that all the delete functions he points out(all of them for that matter, ctrl-k, etc) are actually cut&#x27;s, so you can paste them back as well. I find Ctrl-u especially useful when I&#x27;m halfway through with a command, then I realize I wanted to do something else before executing said command, so I cut it- then paste it back when I need it. * Ctrl + y to paste anything back
评论 #6608086 未加载
adamnemecekover 11 years ago
&gt; Note: you’ll need to open a new Terminal window for changes in ~&#x2F;.bash_profile to take place.<p>Alternatively, you can just do &#x27;. ~&#x2F;.bash_profile&#x27; or &#x27;source ~.&#x2F;bash_profile&#x27;.
评论 #6609065 未加载
goshxover 11 years ago
When you execute a command that takes a long time to run and you want to send it to the background you can do:<p>ctrl + z<p>then, to send it to the background:<p>bg<p>and, to get it back from the background:<p>fg<p>Also, I really like to use &quot;for&quot;, like:<p>&#x2F;&#x2F; get the size of each file or directory in the current directory<p>for i in `ls -1`; do du -hs $i; done;
评论 #6610485 未加载
deckiedanover 11 years ago
Interestingly, relatedly, a lot of the emacs style keybindings (ctrl-a, ctrl-e, ctrl-k, etc) are system-wide in OSX. I prefer vim as my daily editor, but it is often useful. You can also make the bindings even more emacsy if you want.<p><a href="http://irreal.org/blog/?p=2063" rel="nofollow">http:&#x2F;&#x2F;irreal.org&#x2F;blog&#x2F;?p=2063</a>
评论 #6608493 未加载
moleculeover 11 years ago
aliasing git shortcuts seems more appropriate for git config:<p><a href="https://git.wiki.kernel.org/index.php/Aliases" rel="nofollow">https:&#x2F;&#x2F;git.wiki.kernel.org&#x2F;index.php&#x2F;Aliases</a><p>...after aliasing git to &#x27;g&#x27; in your shell config, of course :)<p><pre><code> alias g=&#x27;git&#x27;</code></pre>
评论 #6607933 未加载
grnover 11 years ago
I prefer to use inputrc instead of aliases. Put the following into your .inputrc<p><pre><code> &quot;\C-gs&quot;: &quot;git status -sb &quot; </code></pre> Then, for example, after pressing Ctrl-g, s &quot;git status -sb &quot; will appear in your prompt. Much more readable than lots of two or three letter aliases. You can see the complete list of my shortcuts on my GitHub - <a href="https://github.com/grn/dotfiles/blob/master/inputrc" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;grn&#x2F;dotfiles&#x2F;blob&#x2F;master&#x2F;inputrc</a>
评论 #6610694 未加载
dbboltonover 11 years ago
They should really mention which shell and terminal emulator they are using. Not everyone is using the same &quot;Unix command line&quot;.
评论 #6608867 未加载
robrenaudover 11 years ago
Here is a rule for how to level up your shell&#x2F;editing game. If you ever touch your arrow keys, you are doing something wrong.<p>&gt; ctrl + left arrow Moves the cursor to the left by one word &gt; ctrl + right arrow Moves the cursor to the right by one word<p>Alt + b and Alt + f are also aliases for the same action.
评论 #6610055 未加载
bglazerover 11 years ago
I like the commands, especially the ssh one, which I didn&#x27;t know before and will certainly use in the future.<p>I also enjoyed the format of the article. A whole dev team each contributing their own piece to a blog post provides a lot of different voices and styles in a concise way.
enahsover 11 years ago
I knew about the sudo !! but the sudo !$ will come in handy! thanks!
kronbsyover 11 years ago
Ctrl-t will flip two words. Not very useful but pretty cool.
评论 #6609789 未加载
goshxover 11 years ago
ctrl + l<p>to clear the screen, instead of typing &quot;clear&quot; is pretty useful too.