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.

10 handy Bash aliases for Linux

17 pointsby jhibbetsover 6 years ago

4 comments

BeetleBover 6 years ago
From HN Guidelines:<p>If the original title begins with a number or number + gratuitous adjective, we&#x27;d appreciate it if you&#x27;d crop it. E.g. translate &quot;10 Ways To Do X&quot; to &quot;How To Do X,&quot; and &quot;14 Amazing Ys&quot; to &quot;Ys.&quot; Exception: when the number is meaningful, e.g. &quot;The 5 Platonic Solids.&quot;
评论 #18095640 未加载
LinuxBenderover 6 years ago
Here is one that should reset your terminal after accidentally reading a binary file, in most cases. Some of these are different on linux vs. unix vs. mac. You could put these in a file in &#x2F;etc&#x2F;profile.d&#x2F; or in your ~&#x2F;.bashrc<p><pre><code> alias fix=&#x27;reset; stty sane; tput rs1; clear; echo -e &quot;\033c&quot;&#x27; </code></pre> List only directories:<p><pre><code> alias lsd=&#x27;ls -h -b --color=auto -d *&#x2F;&#x27; </code></pre> List by size:<p><pre><code> alias lss=&#x27;ls -Ao --sort=s&#x27; </code></pre> Hand dyslexia, or the alternate to installing &quot;sl&quot;<p><pre><code> alias sl=ls alias xit=exit alias moer=&quot;more&quot; alias mroe=&quot;more&quot; </code></pre> Long PS<p><pre><code> alias p=&quot;ps -Hefcwww&quot; </code></pre> Shorthand for disk and memory usage:<p><pre><code> alias f=&quot;df -Ph;free -m&quot; </code></pre> Bash function to display colors:<p><pre><code> function colors() { for fgbg in 38 48 ; do for color in {0..256} ; do echo -en &quot;\e[${fgbg};5;${color}m ${color}\t\e[0m&quot; if [ $((($color + 1) % 10)) == 0 ] ; then echo fi done echo done } </code></pre> Functions to do rot13 and rot47 to get around word filters<p><pre><code> function rot13() { if [ -r $1 ]; then cat $1 | tr &#x27;[N-ZA-Mn-za-m5-90-4]&#x27; &#x27;[A-Za-z0-9]&#x27;; else echo $* | tr &#x27;[N-ZA-Mn-za-m5-90-4]&#x27; &#x27;[A-Za-z0-9]&#x27;; fi } function rot47() { if [ -r $1 ]; then cat $1 | tr &#x27;\!-~&#x27; &#x27;P-~\!-O&#x27; ; else echo $* | tr &#x27;\!-~&#x27; &#x27;P-~\!-O&#x27;; fi } </code></pre> A couple of memory stat functions<p><pre><code> function memfree() { free|awk &#x27;&#x2F;^Mem&#x2F; {printf &quot;%4.1f&quot;,($2-$4-$6-$7)&#x2F;$2*100}&#x27; } function memperuser() { ps aux | awk &#x27;NR != 1 {x[$1] += $4} END{ for(z in x) {print z, x[z]&quot;%&quot;}}&#x27; }</code></pre>
nieveover 6 years ago
These are pretty neat, but weirdly uninformed on some things .<p>If you&#x27;re using GNU tar the alias should just be &quot;tar -xvf&quot; since it can autodetect compression (though I&#x27;m not sure if that&#x27;s suffix-based or file type). This also means you can append your own -j or whatever for different compression types if you need to do so manually.<p>Specifying &quot;wget -c&quot; does not mean you&#x27;ll be able to resume if something goes wrong, it forces resumption from a partial file you already have on a subsequent invocation. The reason to specify it on the first invocation is just so that you can be lazy and reuse that command line.<p>The shasum command is from Perl on most (all?) platforms, sha256sum from GNU coreutils or equivalent may be needed if it&#x27;s missing and may have higher performance.<p>Probably most importantly, ipconfig is OS and distro-specific. It was missing on the first linux systems I checked (Ubuntu and openSUSE). It&#x27;s useful, but it&#x27;s a bit like listing a launchctl alias without specifying it&#x27;s largely macOS-specific.
coderobeover 6 years ago
This article covers gems like `alias c=&#x27;clear&#x27;` - very handy! scnr
评论 #18093481 未加载
评论 #18093854 未加载
评论 #18093432 未加载