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.

Favorite Unix Commands

204 pointsby nickwoodhamsover 12 years ago

34 comments

aidosover 12 years ago
It took me a moment to figure out what was going on there (with the whole clippy thing). The bulk of this list is the top commands from commandlinefu which has been on HN before [0], [1].<p>You can even go meta and install a command to let you search commandlinefu [2].<p>[0] <a href="http://news.ycombinator.com/item?id=527486" rel="nofollow">http://news.ycombinator.com/item?id=527486</a><p>[1] <a href="http://news.ycombinator.com/item?id=3843373" rel="nofollow">http://news.ycombinator.com/item?id=3843373</a><p>[2] <a href="http://samirahmed.github.com/fu/" rel="nofollow">http://samirahmed.github.com/fu/</a>
评论 #5025760 未加载
jasonkostempskiover 12 years ago
Many years ago, before I ever used Linux in any serious fashion, I often used a password that ended with '!!'. One day I was playing around with setting up MySQL and was having a very hard time with something that seemed super simple. I don't remember exactly how I figured it out, I think I accidentally type my password at the wrong time in the command line and observed some odd behavior and, after hours, finally tracked it to the '!!' command. I decided to try a different root password for MySQL and it was smooth sailing from there. A few months later I was transferring a domain away from a small DNS hosting provider. After a week or so of waiting support told me they were having a hard time with my account and couldn't do what they needed to do to initiate the transfer. I don't have the support emails, must have been my old hotmail account, but something they said suggested they might be trying to run commands on my account with my password (I knew they stored it in plain text since it was in several emails from them and I knew they were Linux servers) and it reminded me about the '!!' issue I had with MySQL. I changed my password and they were able to move forward. I wish I had dug deeper into the issues at the time they occurred.
pajjuover 12 years ago
Check fasd, it will blow your mind, be prepared! :) Fasd (pronounced similar to "fast") is a command-line productivity booster.<p>I've been using this for a while, and trust me, its changed my command line workflow, and I wish, this should come as inbuilt for all POSIX shells!<p>Here is how it works -<p>If you use your shell to navigate and launch applications, fasd can help you do it more efficiently. With fasd, you can open files regardless of which directory you are in. Just with a few key strings, fasd can find a "frecent" file or directory and open it with command you specify. Below are some hypothetical situations, where you can type in the command on the left and fasd will "expand" your command into the right side. Pretty magic, huh?<p><pre><code> v def conf =&#62; vim /some/awkward/path/to/type/default.conf j abc =&#62; cd /hell/of/a/awkward/path/to/get/to/abcdef m movie =&#62; mplayer /whatever/whatever/whatever/awesome_movie.mp4 o eng paper =&#62; xdg-open /you/dont/remember/where/english_paper.pdf vim `f rc lo` =&#62; vim /etc/rc.local vim `f rc conf` =&#62; vim /etc/rc.conf </code></pre> Fasd offers quick access to files and directories for POSIX shells. It is inspired by tools like autojump, z and v. Fasd keeps track of files and directories you have accessed, so that you can quickly reference them in the command line.<p>The name fasd comes from the default suggested aliases f(files), a(files/directories), s(show/search/select), d(directories).<p>Fasd ranks files and directories by "frecency," that is, by both "frequency" and "recency." The term "frecency" was first coined by Mozilla and used in Firefox.<p>Here is the Link - <a href="https://github.com/clvv/fasd" rel="nofollow">https://github.com/clvv/fasd</a>
csmattover 12 years ago
I forgot about the DNS querying of wikipedia. Probably could've used that to entertain myself on my flights over the holidays since I'm pretty sure gogo inflight passes DNS through.<p>Anyway, I'm a big fan of piping things into xargs. xxd is a terminal-based hex editor. It can convert both to and from hex to binary. I also use 'pgrep -lf 'partial_program_name' a lot in place of 'ps aux | grep partial_program_name'. 'pkill -9 partial_program_name' searches for and kills all processes matching the string.
评论 #5023619 未加载
评论 #5024456 未加载
robblesover 12 years ago
Handy addition to the "mount | column -t" trick:<p>You can use this within Vim to pretty-format text tables, initialization of variables, etc. Just highlight the lines in question in visual line mode (V) and type<p><pre><code> !column -t&#60;CR&#62; </code></pre> to pipe the lines through the column command.
SkippyZAover 12 years ago
Ctrl+l is my most used command. I need a clean terminal
评论 #5023582 未加载
评论 #5023682 未加载
评论 #5023501 未加载
评论 #5024727 未加载
评论 #5024788 未加载
评论 #5023463 未加载
q_revertover 12 years ago
a few nice ones here too, <a href="http://www.pixelbeat.org/cmdline.html" rel="nofollow">http://www.pixelbeat.org/cmdline.html</a>, <a href="http://www.pixelbeat.org/docs/linux_commands.html" rel="nofollow">http://www.pixelbeat.org/docs/linux_commands.html</a><p>always worth looking at these types of lists imo, whilst some of the commands mightn't really fit into your workflow or seem useful immediately, they're often exactly the snippets of information that can save hours at a later stage..
loudmaxover 12 years ago
I have this in my .bashrc:<p>function lc() { if [[ "$#" -gt 1 ]]; then for DIR in "$@"; do echo -n "$DIR - " ; ls -AU1 $DIR | wc -l ; done ; else ls -AU1 "$@" | wc -l ; fi; }<p>So, "lc /dir" will count the number of files in /dir and "lc /dir/*" will count the files in subdirectories of /dir. This is useful if you're working in an environment where you may have thousands of files in a directory, and a regular "ls -l" will lock your terminal while it eats your entire scrollback buffer.
评论 #5024612 未加载
评论 #5035186 未加载
tlarkworthyover 12 years ago
grep -r . "some random debug message" (searches for the passage recursively in all files from the directory it was executed, the main reason I like developing in linux more than windows)
评论 #5023776 未加载
评论 #5025759 未加载
评论 #5024147 未加载
jcampbell1over 12 years ago
I have never understood the love for `sudo !!`. I think `ctrl+pa sudo ` is faster, explicit, and more versatile.
评论 #5025854 未加载
评论 #5043198 未加载
评论 #5025407 未加载
madaoover 12 years ago
Alt Sys Rq o - useful if you need to shut down a system and your kvm is not working.<p><a href="http://en.wikipedia.org/wiki/Magic_SysRq_key" rel="nofollow">http://en.wikipedia.org/wiki/Magic_SysRq_key</a>
评论 #5026705 未加载
bcoatesover 12 years ago
I'm a fan of using cut or sed or awk and ending it with:<p><pre><code> | sort | uniq -c | sort -n -r | head </code></pre> to get a nice top 10 whatevers in the whoosit
nickwoodhamsover 12 years ago
Please comment if you have a favorite not on this list.
评论 #5023506 未加载
评论 #5022854 未加载
评论 #5023399 未加载
评论 #5024395 未加载
评论 #5023070 未加载
评论 #5025016 未加载
评论 #5022675 未加载
评论 #5023398 未加载
评论 #5023044 未加载
crazydiamondover 12 years ago
On zsh, "print -rC2" for printing some listing in 2 column format. The number of columns (C) can be specified. (print is a builtin).<p>zsh's file globbing is awesome. Some simple ones:<p><pre><code> *(.) - only files *(/) - only dirs *(.m0) - files modified today *(.om[1,15]) - 15 recently modified files</code></pre>
drinchevover 12 years ago
faucet 80 --in cat<p>This is useful for creating a connection for receiving the input of what you get...<p>e.g. running<p>faucet 80 --in cat<p>and later<p>curl <a href="http://127.0.0.1:80" rel="nofollow">http://127.0.0.1:80</a><p>will deliver to you console :<p>GET / HTTP/1.1 User-Agent: curl/7.21.4 (i686-pc-linux-gnu) libcurl/7.21.4 OpenSSL/0.9.8n zlib/1.2.5 libidn/1.19 Host: 127.0.0.1:900 Accept: <i>/</i>
评论 #5023347 未加载
评论 #5023158 未加载
INTPenisover 12 years ago
One of my favorite aliases that wasn't listed.<p>alias easy_search="curl -s <a href="http://pypi.python.org/simple/" rel="nofollow">http://pypi.python.org/simple/</a> | perl -ne 'print if s/&#60;[^&#62;]+&#62;//g &#38;&#38; $.&#62;1'|grep"
ragmondoover 12 years ago
I like the wikipedia DNS text lookup - I work in a "firewalled" environment where the unices are only allowed DNS queries. If only wikipedia could provide central switchboard numbers in their text fields as well ...
DanBCover 12 years ago
Single user mode on an HPUX machine was, I think, the most useful to me.<p>(<a href="http://www.unixhub.com/docs/hpux/hpux_boot.html" rel="nofollow">http://www.unixhub.com/docs/hpux/hpux_boot.html</a>)<p>I wish I still had that machine, but I do not.
评论 #5029648 未加载
kungpooover 12 years ago
What a ridiculous fixed header. It's taking up 2/3 of my phone's screen.
评论 #5024957 未加载
carlesfeover 12 years ago
Here's my list, a very compact plaintext file: <a href="http://mmb.pcb.ub.es/~carlesfe/unix/tricks.txt" rel="nofollow">http://mmb.pcb.ub.es/~carlesfe/unix/tricks.txt</a>
overgun77over 12 years ago
Not really a unix command, but a vi command that has been really useful, specially if you do lots of editing protected files and want to keep your custom vim configuration:<p>!sudo tee %
评论 #5024713 未加载
评论 #5023710 未加载
amalakarover 12 years ago
I find this site handy for clever commands: <a href="http://www.commandlinefu.com/commands/browse" rel="nofollow">http://www.commandlinefu.com/commands/browse</a>
glazskunrukitisover 12 years ago
I like those un- commands for easier archive extracting, e.g.:<p>alias unbz2='tar xvjf' alias untar='tar xvfz'
评论 #5027391 未加载
评论 #5025670 未加载
评论 #5026151 未加载
dchichkovover 12 years ago
mount -t overlayfs -o lowerdir=$HOME,upperdir=/tmp/tmpHOME overlayfs $HOME
评论 #5024736 未加载
gshakirover 12 years ago
Great post! I think "lsof" should be there along with "netstat".
vogover 12 years ago
There's a typo: The command is spelled "apropos" (not apropo).
评论 #5023737 未加载
gaileesover 12 years ago
I think I might've just saved days of my life....thank you!
评论 #5023551 未加载
tzuryover 12 years ago
that's the original<p><a href="http://www.commandlinefu.com/commands/browse/sort-by-votes" rel="nofollow">http://www.commandlinefu.com/commands/browse/sort-by-votes</a>
gbogover 12 years ago
esc-#, comments the current line<p>ctrl-\, kills current process even xtail<p>xtail, tails dirs<p>tweaks in .inputrc to have up and down arrow do backward history search, like in ipython.
donquixover 12 years ago
sudo !!<p>Instant favorite
评论 #5023958 未加载
评论 #5024427 未加载
评论 #5024480 未加载
fusiongyroover 12 years ago
Remove trash Emacs leaves lying around:<p>$ find . -name \*~ -delete
re_toddover 12 years ago
alias cd5='pushd .; cd ../../../../..'<p>This lets me cd five directories at a time, and if I want to go back, I do a "popd"
Zenstover 12 years ago
in ksh set -o vi so I can use the vi editor to navigate the command line history.
t_larkover 12 years ago
grep -r . "Some random debug msg"