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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Ask HN: How do I become a shell god?

35 点作者 h-1超过 4 年前
It seems many things can be done with a one-liner or short shell script, but I'm not fluent enough to recognize those patterns yet. I do know a few basic commands, but much of *nix seems like a bag of undocumented tricks; and man pages are hieroglyphic IMO. Is there a cohesive path to learning all the tricks? All of them!

21 条评论

kazinator超过 4 年前
Read the whole POSIX specification for the &quot;Shell Command Language&quot;, and in particular how input is processed by the shell through all the multiple expansion passes.<p><a href="https:&#x2F;&#x2F;pubs.opengroup.org&#x2F;onlinepubs&#x2F;9699919799&#x2F;utilities&#x2F;V3_chap02.html#tag_18" rel="nofollow">https:&#x2F;&#x2F;pubs.opengroup.org&#x2F;onlinepubs&#x2F;9699919799&#x2F;utilities&#x2F;V...</a><p>From there, you have a better background for reading the documentation of shell implementations, like Bash.<p>Also study Awk:<p><a href="https:&#x2F;&#x2F;pubs.opengroup.org&#x2F;onlinepubs&#x2F;9699919799&#x2F;utilities&#x2F;awk.html" rel="nofollow">https:&#x2F;&#x2F;pubs.opengroup.org&#x2F;onlinepubs&#x2F;9699919799&#x2F;utilities&#x2F;a...</a><p>Those who don&#x27;t know Awk do comical things with cockamamie combinations of cut, sed, grep, echo ... and clumsy loops written in shell.<p>Other than shell syntax and semantics, it&#x27;s a matter of knowing a large number of utilities.
评论 #25404496 未加载
ahawkins超过 4 年前
If you encounter a problem or task, then do it using shell commands. This will push into asking the question &quot;what command can do X?&quot; and &quot;how do I connect command X to command Y?&quot; and &quot;how do loop commands over output?&quot;. Then just keep doing that over and over again.<p>Learn the shell chainsaw: `xargs`. `xargs -L` vs `xargs` and `xargs -I` (examples will say use `{}` but I&#x27;m partial to `xargs -I @` because that works with Fish and Bash, plus it&#x27;s a single character.
评论 #25406314 未加载
评论 #25407681 未加载
m463超过 4 年前
My way is:<p>Try to write small loops and pipes on the command line. I do things like this all the time:<p><pre><code> for i in foo*.txt; do mv $i OLD-$i; done </code></pre> You&#x27;ll find this breaks sometimes, so use control-r to recall the command and fix it<p><pre><code> for i in foo*.txt; do mv &quot;$i&quot; &quot;OLD-$i&quot;; done </code></pre> if it gets too long, copy&#x2F;paste it into a file like ~&#x2F;bin&#x2F;renamer and multiple lines and indenting and make it a more permanent part of your collection.<p>Also, shell isn&#x27;t the end. I move to python when shell scripts get cumbersome. python can easily parse arguments (argparse), handle filenames with weird characters in them (os.path), walk trees of files (os.walk) and more.
评论 #25406347 未加载
评论 #25406317 未加载
评论 #25408590 未加载
ktpsns超过 4 年前
Best is to identify the shell as a solution within your daily work. The maybe obvious step 1 is to switch to an unixoid OS such as Linux or Mac OS. Step 2 is to make the shell easily reachable, for example with buttons to open a shell in your current directory or with a drop-down terminal like <a href="http:&#x2F;&#x2F;guake-project.org&#x2F;" rel="nofollow">http:&#x2F;&#x2F;guake-project.org&#x2F;</a><p>Then, whenever you have some everyday problem (frequently some &quot;batch&quot; or &quot;bulk&quot; job operating on many files), consider using the shell instead some 3rd party tools.<p>If you really are into it, consider working with suitable files. For instance, drop office files (MSO or LibreOffice&#x2F;OpenDocument) and instead switch to plain text files (Markdown or Latex). They are much easier to process in the command line. Also consider using git instead of dropbox and friends, because it is CLI-first. There is a universe waiting to be explored: There are CLI clients for almost everything (chatting, mail, web, etc.).
zcw100超过 4 年前
I’d recommend the Advanced Bash Scripting Guide <a href="https:&#x2F;&#x2F;tldp.org&#x2F;LDP&#x2F;abs&#x2F;html&#x2F;" rel="nofollow">https:&#x2F;&#x2F;tldp.org&#x2F;LDP&#x2F;abs&#x2F;html&#x2F;</a> and make peace with the fact that you’ll never know it all and enjoy the journey. Years later you’ll still be stumbling across new stuff.
评论 #25406254 未加载
contingencies超过 4 年前
Unix evolved in an age of batch processing.<p>Files were the default datastore, and text streams the default inter-process interface.<p>Although the world is changing, a surprising amount of it still operates through those tools.<p>A good way to understand the tooling is to do one of the Linux from scratch or similar projects, perhaps look at swapping out some tools for self-written alternatives, and scratching your own itch building projects that solve problems you have yourself.<p>Most people who reach a degree of proficiency in shell also have an innate understanding of the kernel&#x27;s general organization, the nature of filesystems, the boot process, database types, are capable of programming in multiple languages, comoprehend network programming and the challenges of locking and distributed state, and so on. You can&#x27;t learn all of it in one go, so just leverage that interest and enthusiasm and devote the time.
parentheses超过 4 年前
Use it a lot and find ways to learn how it works:<p>- read the manual (see other posts) - customize it (and persevere) - make it fun<p>The second is really helpful. A lot of my shell commands&#x2F;utilities [0] are simply better-for-me ergonomics on commonly available commands. These include things like `fzf` wrappers and more sophisticated aliases.<p>I specifically found the making of `fzf` based utilities to be a source of major learnings. It requires you to know quite a bit of shell mechanics to do things nicely. It&#x27;s very similar to building a UI with APIs. You invariably learn the surrounding concepts (HTTP, auth for APIs, content types, caching, etc.)
ketanmaheshwari超过 4 年前
Shameless plug:<p>I created a tutorial on Linux Terminal Tools a while ago where I covered many topics but not in too much detail. Perhaps going down the rabbit holes on these slides might help: <a href="https:&#x2F;&#x2F;ketancmaheshwari.github.io&#x2F;pdfs&#x2F;LPT_LISA.pdf" rel="nofollow">https:&#x2F;&#x2F;ketancmaheshwari.github.io&#x2F;pdfs&#x2F;LPT_LISA.pdf</a>
stakkur超过 4 年前
Getting a solid grip on bash scripting was a game changer for me. From there, you can go several directions: Perl, awk, whatever.
atmosx超过 4 年前
By reading 1 dedicated shell book e.g. &quot;Linux Command Line and Shell Scripting&quot; you&#x27;ll be at the top 10% of shell connoisseurs.<p>That said, I challenge the usefulness of deep shell knowledge.<p>If you&#x27;re planning on writing 300 lines shell scripts, you&#x27;re most likely doing it wrong, you should be using a full featured, modern programming language.
评论 #25411081 未加载
daemoncoder超过 4 年前
Unix Power Tools was a great help when I was learning shell scripting:<p><a href="https:&#x2F;&#x2F;www.oreilly.com&#x2F;library&#x2F;view&#x2F;unix-power-tools&#x2F;0596003307&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.oreilly.com&#x2F;library&#x2F;view&#x2F;unix-power-tools&#x2F;059600...</a>
nunez超过 4 年前
I love the fact that shell gods exist :)<p>Honestly? If you can think of anything that needs to be automated, then write a shell script to automate it!
porkbrain超过 4 年前
I recently built a side project using bash scripts only. That helped a lot and was very fun, except for dealing with errors.
Spooky23超过 4 年前
You need to use it.<p>I’d suggest taking any task that you would do in excel, and do it on the command line.
co_dh超过 4 年前
Read kiss linux&#x27;s source code: The kiss package manager especially.
swirepe超过 4 年前
No gods, no kings, only explainshell.com
giantg2超过 4 年前
You could write your own shell.
sqlhelpthrow超过 4 年前
Two oreilly books to give you an overview, sorta know the lie of the land.<p>Classic Shell Scripting by Arnold Robbins<p>Unix Power Tools 3rd edition<p>Two additional worthwhile books:<p>The Unix Programming Environment by Kernighan and Pike<p>Mastering Regular Expressions by Friedl.<p>All 4 are classics.<p>Also try tldr.sh website in addition to man pages. They are easier to grok.
alltakendamned超过 4 年前
man bash<p>Good starting point
chaganated超过 4 年前
The bash manual is an okay place to start:<p><a href="https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;bash&#x2F;manual&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;bash&#x2F;manual&#x2F;</a>
AntiImperialist超过 4 年前
Almost all of my shell scripts are made up of code-snippets copied from Stackoverflow.