TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: What are some terminal tricks you wish you knew sooner?

66 点作者 aj-4将近 6 年前
Here are mine:<p>1. create aliases for everything in ~&#x2F;.bashrc to speed things up<p>2. window stacking &#x2F; multi-tasking in iTerm with cmd + (shift) + d<p>3. turn on vi(m) syntax highlighting by adding :syntax on to ~&#x2F;.vimrc<p>4. use jq to format and colorize json files &#x2F; streams with the pipe | operator (so useful!)<p>5. Generate a custom command prompt at http:&#x2F;&#x2F;bashrcgenerator.com&#x2F; (just for fun)<p>I really like this topic, so made a video going into more detail on mine, if anyone&#x27;s interested https:&#x2F;&#x2F;youtu.be&#x2F;okGN2RXFw_U

24 条评论

eb0la将近 6 年前
Using the caret (^) character to correct mistakes.<p>Imagine you write something like this:<p># moutn -o ro -o remount &#x2F;dev&#x2F;hda0 &#x2F;<p>Arg! I should have written mount, not moutn!<p>Easy fix:<p># ^moutn^mount<p>I find it better than editing the last line (with cursor). It even works at boot and without &#x27;doskey-like&#x27; arrow history.
pizza将近 6 年前
byobu and tmux are god-tier<p>vim: use :!some_shell_command --with_arguments to run a shell command from within vim quickly<p>also :set hlsearch to allow search highlighting, and use :noh to disable the current highlight once you no longer need the text to be a different color<p>tmux: Prefix-[ to scroll up console text. use &#x2F; to search down, and ? to search up (just like in vim)<p>tmux: Prefix-z to zoom current pane to full size of window<p>zsh: vi-mode plugin to quickly use vim shortcuts on terminal input text, history-substring-search plugin to quickly remember what finicky command I was using earlier<p>also shells in general: ctrl-s to pause text (eg if you want to pause log spam), ctrl-q to resume<p>ssh -XC for compressed x11 forwarding, to speed up x11 responsiveness<p>on remote server: python2 -m SimpleHTTPServer 8080 --bind localhost to quickly start a simple file&#x2F;http server from the current directory that is NOT internet accessible (ie nobody steals your shit)<p>then on local computer: ssh -L 8080:localhost:8080 to tunnel to remote server&#x27;s localhost server. then just type in localhost:8080 in firefox to access remote server&#x27;s files
评论 #20493870 未加载
评论 #20493758 未加载
jiva将近 6 年前
If your SSH session gets locked, you can kill the session without killing the terminal window by pressing Enter, ~, . (period)
sethammons将近 6 年前
Pretty sure these count:<p>ctrl+r (reverse search) on steroids: fzf (<a href="https:&#x2F;&#x2F;github.com&#x2F;junegunn&#x2F;fzf" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;junegunn&#x2F;fzf</a>)<p>put a symlink to my dot files to a dropbox folder (always backed up .bash_profile or whatnot)<p>ssh tunnel to expose a port from a remote server on my computer: ssh -L 8500:localhost:8500 $remotehost<p>expose a port on my machine to the internet (demos and such): <a href="https:&#x2F;&#x2F;ngrok.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;ngrok.com&#x2F;</a><p>git bash prompt and git completion: know at a glance the branch I&#x27;m on and if there is un-staged&#x2F;un-committed code. Allow tab complete for remotes and branch names. Lots of options here.<p>autojump (<a href="https:&#x2F;&#x2F;github.com&#x2F;wting&#x2F;autojump" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;wting&#x2F;autojump</a>): `j foo` will jump directories to my &#x2F;whatever&#x2F;foo directory. Better than popd and pushd.<p>And before I had it baked into my prompt: `echo $?` to show the exit code of my last command.
codegladiator将近 6 年前
ctrl+r for reverse searching of previous command<p>add a &quot;# tags&quot; at any commands end to use above for future.<p>so lets say you have a ssh into multiple servers<p>$ ssh -Uasfd host1 # server1<p>$ ssh -Uaiouhqe host2 # server2<p>then later, ctrl+r -&gt; and type ver1
rat_melter将近 6 年前
<p><pre><code> $ mv file.text !#:1:r.txt evaluates to: $ mv file.text file.txt (colon separated) !# means this command 1 is the position of the argument to be modified r means strip extension </code></pre> There&#x27;s tons of history modifiers and a lot to be learned reading `man bash`.
croh将近 6 年前
1. for vim - <a href="https:&#x2F;&#x2F;laymanclass.com&#x2F;vim-essential-setup-to-boost-your-productivity&#x2F;" rel="nofollow">https:&#x2F;&#x2F;laymanclass.com&#x2F;vim-essential-setup-to-boost-your-pr...</a><p>2. autojump<p>3. solarized theme<p>4. zsh and antigen(particularly <a href="https:&#x2F;&#x2F;github.com&#x2F;desyncr&#x2F;auto-ls" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;desyncr&#x2F;auto-ls</a> and <a href="https:&#x2F;&#x2F;github.com&#x2F;psprint&#x2F;zsh-navigation-tools" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;psprint&#x2F;zsh-navigation-tools</a>)
lowkey将近 6 年前
sudo !! to run the previous command as sudo (so useful when you forgot to sudo a long command)
评论 #20497753 未加载
评论 #20498750 未加载
ksaj将近 6 年前
Do you mean cmd shift t? The d exits the terminal, which is the opposite of what I assume you meant. T for Terminal, and D for Die.<p>Also in .vimrc I add: set noswapfile, set nobackup, and set nowb<p>These were probably useful when terminal sessions were conducted over flaky modem connections. I use Raspberry Pis a lot, so I&#x27;d rather not speed up the SSD card&#x27;s inevitable failure.
评论 #20495618 未加载
I_complete_me将近 6 年前
fd is a simple, fast and user-friendly alternative to find. Install from <a href="https:&#x2F;&#x2F;github.com&#x2F;sharkdp&#x2F;fd&#x2F;" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;sharkdp&#x2F;fd&#x2F;</a>. Example: to find all files with .md extension in current directory : fd -e md
znpy将近 6 年前
Ctrl-z to suspend a program, jobs to view the list of suspended programs and fg to resume a program.<p>They are the terminal equivalent of iconising a window. You can do some form of multitasking without screen&#x2F;tmux&#x2F;byobu
ktpsns将近 6 年前
Search in bash history -- CRTL+R (many people also bind this to other keys)
iraldir将近 6 年前
ctrl-r to history search commands<p>ctrl-a to go to begining of line, ctrl-e to go to end of line, ctrl-u to delete line<p>oh-my-zsh to display nice contextual info on git, navigate more easily etc.<p>If you have commands you use regularly (unit test, building, git, etc.), keep a tab for each and create a profile so that it goes directly in the folder you need, and can have a different color.
评论 #20498135 未加载
tkjef将近 6 年前
use less for safe read-only mode and to utilize vim commands still<p>esc-b to jump back a word on the terminal<p>esc-f to jump forward a word on the terminal<p>nerdcommenter (my favorite vim plugin)<p>git-gutter (my 2nd favorite vim plugin)<p>!-2 (repeats 2nd to last command)<p>practice! <a href="https:&#x2F;&#x2F;www.shortcutfoo.com&#x2F;app&#x2F;dojos&#x2F;vim" rel="nofollow">https:&#x2F;&#x2F;www.shortcutfoo.com&#x2F;app&#x2F;dojos&#x2F;vim</a>
yulaow将近 6 年前
history<p>I didn&#x27;t know that command even exists. You can just use it in pipe with grep&#x2F;sed&#x2F;... to look for specific commands used in servers you do not directly manage often (Eg last time I used them I was looking for all the docker commands in a server to understand how to startup the correct containers and in which order)
adolph将近 6 年前
Using vi for the terminal prompt and history:<p>set -o vi
评论 #20517468 未加载
thepete2将近 6 年前
fc (&quot;fix command&quot;) opens an editor with your last command and executes it when you leave the editor. fc -l lists your latest commands, fc -ln does so without line numbers. Useful if you want to write a script (fc -ln &gt; myscript.sh).
thisisrajat将近 6 年前
- CMD + A to go to front of current line.<p>- CMD + E to go to end of current line.<p>- `sudo !!` to run last command with `sudo`
评论 #20516290 未加载
znpy将近 6 年前
pushd&#x2F;popd - manipulate a stack of directory paths.<p>Useful to save the current directory, go somewhere else, do stuff and then come back to the original directory.<p>It works awesomely in bash scripts too!
aj-4将近 6 年前
hyperlink btw <a href="https:&#x2F;&#x2F;youtu.be&#x2F;okGN2RXFw_U" rel="nofollow">https:&#x2F;&#x2F;youtu.be&#x2F;okGN2RXFw_U</a>
jquast将近 6 年前
fill the screen&#x2F;DEC tube alignment sequence<p><pre><code> printf &quot;\033#8&quot;</code></pre>
gabrielblack将近 6 年前
bash disown command, particularly useful if I forget to prepend nohup
exhoez将近 6 年前
cd - to come back to your previous directory location
tmwed将近 6 年前
ctrl+r to search previously entered commands.