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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Linux shell tips and tricks

95 点作者 Ashuu超过 11 年前

13 条评论

lucb1e超过 11 年前
&gt; Extract tar.gz in new directory: tar zxvf package.tar.gz -C new_dir<p>For quick reference, since it seems to be hard[1], these are the flags you&#x27;ll most need in tar:<p><pre><code> c = create x = extract v = verbose z = gzipped; compressed. f = file </code></pre> So for example `tar xf example.tar` will extract that tar file. Or `tar cf example.tar .` will pack all files in the current directory to example.tar. For compression and verbosity, it would be `tar zvcf example.tar.gz .`. The .gz at the end is optional, but now others can see what kind of archive it is. Extract .tar.gz files with `tar xzf example.tar.gz`.<p>For bonus points, here is a poor man&#x27;s version of scp&#x2F;rsync:<p><pre><code> # sending computer tar czf - . | openssl aes-128-cbc -k &#x27;secret&#x27; | nc -l 1 # receiving computer nc 192.168.1.102 1 | openssl aes-128-cbc -d -k &#x27;secret&#x27; | tar xf - </code></pre> [1] Obligatory xkcd <a href="https://xkcd.com/1168/" rel="nofollow">https:&#x2F;&#x2F;xkcd.com&#x2F;1168&#x2F;</a><p>Edit: replaced all asterisks with a period (.) since it would become italics. Tar is recursive by default, so it should work the same.
评论 #6790019 未加载
评论 #6789681 未加载
评论 #6789950 未加载
评论 #6789610 未加载
评论 #6789772 未加载
weland超过 11 年前
&gt; I’m using Linux shell on daily basis, but I often forgot some useful command or shell tip.<p>I hate to be overly pedantic, but <i>what shell</i> would that be? There is no such thing as the Linux shell.
评论 #6790252 未加载
评论 #6789596 未加载
olog-hai超过 11 年前
This is incorrect and misleading right off the bat. Ctrl+Z does not &quot;send process to background.&quot; You will almost always need to use the bg command for that after suspending the running program.
评论 #6790211 未加载
评论 #6789539 未加载
yeukhon超过 11 年前
I also recommend <a href="http://explainshell.com/" rel="nofollow">http:&#x2F;&#x2F;explainshell.com&#x2F;</a>. It does its best to break down what a shell command like tar vxf file.gz does.
clarry超过 11 年前
So, a random assortment of commands, most of which have nothing to do with Linux.<p>I&#x27;m sure somebody will find something useful here though.
hpaavola超过 11 年前
&quot;Error establishing a database connection&quot; :(<p>Here&#x27;s a Google Cache link: <a href="http://webcache.googleusercontent.com/search?q=cache:5z9gUWvIH40J:www.techbar.me/linux-shell-tips/+&amp;cd=1&amp;hl=en&amp;ct=clnk&amp;gl=fi" rel="nofollow">http:&#x2F;&#x2F;webcache.googleusercontent.com&#x2F;search?q=cache:5z9gUWv...</a><p>Content is typical blog style content and even comments come from Disqus, so ther should not be any reason to connect to a database with every request.
评论 #6791050 未加载
rtpg超过 11 年前
Nice list of stuff, especially for people relatively new to command line stuff<p>there&#x27;s a cool twitter account called &quot;Command Line Magic&quot; (<a href="https://twitter.com/climagic" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;climagic</a>) that does some fun stuff, and is pretty shell-agnostic.<p>Also, for those willing to, I&#x27;d strongly suggest checking out fish. it&#x27;s not bash-compatible, but there&#x27;s a lot of good usability aspects to it (especially compared to vanilla bash), I love it.<p>Out of curiosity though, this command : tar zxvf package.tar.gz -C new_dir<p>it&#x27;s always intrigued me that the tar command (I imagine it is mainly used to &quot;unzip&quot; things) does not make it very simple to do this. I&#x27;ve started to memorize the 4-letter combo but for a while I had to google it everytime (man pages are not useful for learning things for a lot of unix cl tools).
评论 #6789902 未加载
评论 #6790609 未加载
评论 #6791079 未加载
评论 #6789837 未加载
WizzleKake超过 11 年前
Any discussion of Linux shell tricks&#x2F;tips is incomplete without a mention of the readline shortcuts: <a href="http://www.bigsmoke.us/readline/shortcuts" rel="nofollow">http:&#x2F;&#x2F;www.bigsmoke.us&#x2F;readline&#x2F;shortcuts</a>
评论 #6790560 未加载
onosendai超过 11 年前
The quick &#x27;n dirty recipe to test the disk write speed isn&#x27;t ideal, since there&#x27;s the buffer cache which significantly skews the results. A much better way would be:<p>&gt; sync &amp;&amp; time sh -c &quot;dd if=&#x2F;dev&#x2F;zero of=foo bs=1M count=10000 &amp;&amp; sync&quot;<p>Then just divide 10000 (or whatever value you choose) by the number of seconds elapsed and you should get a much closer approximation of the sequential write speed, taking into account completely flushing the buffer to disk.
评论 #6789592 未加载
评论 #6790648 未加载
mrmaloke超过 11 年前
A friend of mine made a presentation on tips and tricks on bash (and more). I learned some really helpful shortcuts from it. <a href="http://joschi.github.io/shell-for-developers-presentation/#contents" rel="nofollow">http:&#x2F;&#x2F;joschi.github.io&#x2F;shell-for-developers-presentation&#x2F;#c...</a>
评论 #6790551 未加载
nu2ycombinator超过 11 年前
Here is the cached version of this page <a href="http://webcache.googleusercontent.com/search?q=cache:5z9gUWvIH40J:www.techbar.me/linux-shell-tips/+&amp;cd=1&amp;hl=en&amp;ct=clnk&amp;gl=us" rel="nofollow">http:&#x2F;&#x2F;webcache.googleusercontent.com&#x2F;search?q=cache:5z9gUWv...</a>
meacco超过 11 年前
Can be useful, but I found this more interesting on same website: <a href="https://news.ycombinator.com/item?id=6789252" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=6789252</a>
noselasd超过 11 年前
CTRL-x CTRL-e to bring up editor in bash, often helpful
评论 #6794466 未加载
评论 #6790694 未加载