
Unix Commands I Wish I’d Discovered Years Earlier - micahalles
http://spin.atomicobject.com/2013/09/09/5-unix-commands/
======
WestCoastJustin
If anyone is interested there were several great posts on Hacker News a while
about about useful UNIX commands [1, 2, 3]. I have also created several
screencasts about command commands like the following [4], and one about the
Filesystem Hierarchy Standard [5].

    
    
      ls man pwd cd top ps df du cp mv rm mkdir rmdir less cat vi
    

[1]
[https://news.ycombinator.com/item?id=6046682](https://news.ycombinator.com/item?id=6046682)

[2]
[https://news.ycombinator.com/item?id=5022457](https://news.ycombinator.com/item?id=5022457)

[3]
[https://news.ycombinator.com/item?id=4985393](https://news.ycombinator.com/item?id=4985393)

[4] [http://sysadmincasts.com/episodes/13-crash-course-on-
common-...](http://sysadmincasts.com/episodes/13-crash-course-on-common-
commands)

[5] [http://sysadmincasts.com/episodes/12-crash-course-on-the-
fil...](http://sysadmincasts.com/episodes/12-crash-course-on-the-filesystem-
hierarchy-standard)

~~~
Goladus
Great links, though I admit when I saw the OP I was expecting content like
that and was pleasantly surprised that they really were "Unix commands I wish
I'd discovered years earlier", and not the standard array of unix tips+tricks
that you can get by without for awhile but as you become more advanced become
second-nature.

"Man ascii." The number of times that I wound up generating my own ascii table
from whatever language I was working with...

"xxd" I always either used search in emacs hex-mode (which I find cumbersome
and annoying but haven't taken the time to customize), or rolled my own search
using a programming language. This would have come in handy SO many times back
when I used to muck around with videogame save files and the like. I never
even knew it existed nor how to discover that it did.

'cal' I learned about early on so never missed it and the 'ssh' stuff kind of
fits into the regular "unix tips and tricks" category.

~~~
WestCoastJustin
re: ascii tables

You reminded me of something. There is actually a really cool and simple site
called asciiflow [1], which I use all the time to draw diagrams for explaining
things in email, etc. It's pretty cool, and was even submitted several times
to HN [2, 3].

[1] [http://www.asciiflow.com/#Draw](http://www.asciiflow.com/#Draw)

[2]
[https://news.ycombinator.com/item?id=2847177](https://news.ycombinator.com/item?id=2847177)

[3]
[https://news.ycombinator.com/item?id=3598177](https://news.ycombinator.com/item?id=3598177)

~~~
hobs
Wow. This is really cool! Not only can you make the ascii drawings, but there
is an integration with a service called ditaa (unaffiliated) that then turns
your ascii drawings into actual images. I am keeping these.
[http://ditaa.sourceforge.net/](http://ditaa.sourceforge.net/)

------
vectorpush
Command line globbing! For the uninitiated:

Let's say my pwd is `/home/projects` and i want to edit
`/home/projects/a_huge_sprawling_app/940j_394/lol/flight_controller.rb`

    
    
      `vim **/flight_controller.rb` 

opens our flight_controller.rb straight away. In terms of effort, this allows
you to basically omit a `find -name` when you're in a rush to edit some damn
file where the hell is it again damn we need to reevaluate this directory
str...

\----

Double bang to re-use your last terminal entry. One great use, taking all the
pain out of forgetting your sudos

    
    
      `rm -rf /var/log`
      rm: cannot remove `/var/log': Permission denied
      `sudo !!`
    

All evidence of wrongdoing is now destroyed.

\-----

Ok, here is an awesome one for users of the ultimate cloud IDE: Vim.

In your local ~/.ssh/config:

    
    
      `ForwardX11 yes`
      `SendEnv WINDOWID`
    

In your remote server's /etc/ssh/sshd_config:

    
    
      `AcceptEnv WINDOWID`
    

In your vimrc:

    
    
      `set clipboard=unnamedplus`
    

This has the effect of seamless yank and paste between local and remote vim
sessions, no need for ctrl+shift+v.

I love linux.

~~~
ilikepi
FWIW, the double-star recursive globbing was added in Bash 4.0. My reading of
the manual[1] suggests it is disabled by default, and can be enabled by
setting the 'globstar' shell option. I believe it's enabled by default in zsh.

[1]: [https://www.gnu.org/software/bash/manual/bash.html#The-
Shopt...](https://www.gnu.org/software/bash/manual/bash.html#The-Shopt-
Builtin)

~~~
Typhon
I just tried it on bash 4.2.25, and it worked, even though I just learned
about it. Maybe not every OS enables the same default options for Bash (I'm
using Lubuntu 12.10 at the moment)

~~~
ilikepi
Yep, that is a fair point. I should have qualified my statement about bash's
defaults, since many OSs include their own custom start-up files that may
modify the defaults.

------
csense
My favorite is the parallel jobs feature of xargs. For example, say you want
to run a script you wrote called process-video.sh to do some processing on all
the video files in a directory (extracting audio to MP3, converting format,
etc.). You want to use all 8 of your cores. You could write a Makefile and run
it with -j9, or you can do this:

    
    
       find . -name "*.flv" | xargs -n 1 -P 9 ./process-video.sh
    

This immediately forks 9 instances of process-video.sh on the first 9 .flv
files in the current directory, then starts a new instance whenever a running
instance completes, so 9 instances are always in flight. (I usually set to
number of cores plus one for CPU-bound tasks, hence 9 for my i7 with eight
cores [1].)

If you add -print0 to the find command and -0 to the xargs command, it uses
null-terminated filenames (which does the right thing when filenames contain
whitespace).

[1] Logical cores. Most i7's have four physical cores which become eight
logical cores through the magic of hyperthreading.

~~~
whitlock
If you like xargs, but want more flexibility, I'd highly suggest GNU parallel.
Such flexibility includes running jobs on multiple computers, running
intensive command using all available CPU's (like xargs -P), and creating
unique scripts to handle multiple parameters.

[http://www.gnu.org/software/parallel/man.html](http://www.gnu.org/software/parallel/man.html)

~~~
dagw
Parallel also lets you transparently run stuff on remote servers,
automatically handling stuff like copying files back and forth. When I have
some heavy ad-hoc data processing to do my new favorite trick is spinning up
50-100 ec2 spot instances, point GNU parallel at them and just fire and
forget.

------
grimgrin
Replaces the current day of the month with []:

    
    
         $ cal | sed "s/.*/ & /;s/ $(date +%e) / [] /"
    
            September 2013
         Su Mo Tu We Th Fr Sa
          1  2  3  4  5  6  7
          8  9 [] 11 12 13 14
         15 16 17 18 19 20 21
         22 23 24 25 26 27 28
         29 30

~~~
nawitus
Hmm, the day is already highlighted for me (inverted color).

~~~
ape4
You can turn that off with:

    
    
      cal | cat

~~~
aeon10
can you please explain how this works?

~~~
shabble
it's quite a common pattern in commandline apps to check if the stdout is a
tty or not, and do things differently if so. So when you pipe it through
`cat', it does the no-fancy-included output, much like the colouring that `ls'
will apply interactively, but not when piped/redirected.

~~~
ajuc
It's important for grepping and sedding - the colors are escape codes and
would mess with your regular expressions otherwise (you want to find foobar ,
but bar was blue so you got foo\e[1;34mbar\e[0m instead, and it doesn't match
with foobar).

~~~
jlgreco
On the other hand, if you _want_ colors displayed you can force grep/ack to
display the color 'always' and then pipe the output into 'less -R'. The -R (or
--RAW-CONTROL-CHARS) flag has less display output such that color escape
sequences work as you might expect, coloring the output displayed by less.

------
fsckin
One of the more useful bits of ssh is not mentioned: remotely running
commands.

Example:

ssh username@host "echo $HOSTNAME && sudo somecommand && cat somecommand.log"

There's probably a better way to do this, but in a pinch I can fix a problem
on dozens of machines just by altering the host string.

~~~
jfb
The single most useful thing about ssh to me is that it connects stdout/in
across the channel (this is behavior inherited from rsh). This allows for
e.g.:

    
    
      % (cd /foo; tar cpf - .) | ssh bar \(cd /baz\; tar xpf -\)
    

Or:

    
    
      % cat ~/.ssh/id_rsa.pub | ssh bar tee -a .ssh/authorized_keys

~~~
sopooneo
Forgive my ignorance, but I don't know what what it means to connect "across
the channel", but it sounds important. Do you know a link that explains the
concept? I've failed to Google it.

~~~
arnsholt
It means that whatever you put into the ssh process's STDIN gets sent to the
STDIN of the remote process. For example you can do this:

    
    
        tar cj $bigdir | ssh host 'tar xj'
    

That creates a tar.bz2 archive on your machine, sends it over ssh to the
remote host, where it's unpacked. Ad hoc compressed and encrypted file
transfers made easy.

~~~
mturmon
That's a good illustration, but rsync, if available, would generally be
preferred for that use case:

    
    
      rsync -az $bigdir host:$bigdir

~~~
jfb
Sure, of course. But I've used that tar|ssh combination so much that it was
the first example of using the rsh-like stdout/in pairing that came to mind.
As much as I bitch about Unix and POSIX and horrific shell brain damage, I
still reach for crazy shell pipelines when I have data manipulation tasks up
to some pretty large scale _n_.

------
kibwen
I recently used xxd to illustrate the concept of text encoding, and put
together a little vimscript to make it easier to visualize:

    
    
      "Toggle hex edit mode
      nmap <Leader>h :call ToggleHex()<CR>
      
      let g:hex_mode_on = 0
      
      function! ToggleHex()
          if g:hex_mode_on
              execute "%!xxd -r"
              let g:hex_mode_on = 0
          else
              execute "%!xxd"
              let g:hex_mode_on = 1
          endif
      endfunction
    

Stick this in your .vimrc, type something, use \h to convert it to hex, change
a value, then \h to convert it back and observe how the text has changed. Not
super useful, but a neat party trick.

------
salgernon
Mac OS: pbpaste & pbcopy

For instance:

pbpaste | fgrep -i "`pbpaste -pboard find`"

To search the copy clipboard with the find clipboard.

~~~
greyfade
On X11 systems, there's also xclip:

    
    
        xclip -o -selection clipboard

~~~
deathanatos
There's also xsel, which seems to be installed by default more often than
xclip.

    
    
      … | xsel -b  # Copy.
      xsel -b | …  # Paste.

------
dredmorbius
Rather than 'man 7 ascii', there's the 'ascii' command itself.

It will also provide encodings for single characters: $ ascii a ASCII 6/1 is
decimal 097, hex 61, octal 141, bits 01100001: prints as `a' Official name:
Miniscule a Other names: Small a, Lowercase a

    
    
        ASCII 0/10 is decimal 010, hex 0a, octal 012, bits 00001010: called ^J, LF, NL
        Official name: Line Feed
        Other names: Newline, \n

~~~
clarry
Which Unix includes that command?

~~~
dredmorbius
Debian GNU/Linux. It's the 'ascii' package.

------
PuercoPop
Protip, you can make emacs use mdfind with (setq locate-command "mdfind")[1]

[1]:
[http://emacsredux.com/blog/2013/07/05/locate/](http://emacsredux.com/blog/2013/07/05/locate/)
(setq locate-command "mdfind")

------
Kurtz79
I know it's not exactly an unknown command, but I didn't know about "sort"
until last week.

It's freaking fast and convenient, sorts hadoop reduce results like a champ.

~~~
WestCoastJustin
One of my favorite things about unix is that you can chain commands together
with pipe (|). Say for example that you have a example data file that looks
like this:

    
    
      # Deflection    Col-Force       Beam-Force 
      0.000              0              0    
      0.001            104             51
      0.002            202            101
      0.003            298            148
      0.0031           104            149
      0.004            289            201
      0.0041           291            209
      0.005            104            250
      0.010            311            260
      0.020            104            240
      

You can chain commands together to quickly get ball park figures. I do this
all the time when reviewing log data to get simple counts and look for
anomalies.

    
    
      $ cat data.txt | grep -v '#' | awk '{print $2}' | sort | uniq -c
          1 0
          4 104
          1 202
          1 289
          1 291
          1 298
          1 311
    

Let me break this down a little. I _cat_ data.txt, which just prints the
contents to the console, I use _grep_ to remove the _#_ header, then use _awk_
to print the second data column, the _sort_ the values for my next procedure,
and lastly I use _uniq -c_ , which takes the input and counts all the unique
values. So you can see that "4 104" means that 4 instances of 104 were found.
I use this often to look at httpd logs for IP addresses or to review sudo
commands, etc. Very handy!

ps. there are optimizations that could be done here, but that what is great
about unix and "one function" utilities. There are many ways to the same
destination!

~~~
oftenwrong
Yes, there are some ways to simplify. You can get rid of the "UUOC". Instead
of

    
    
         cat data.txt | grep -v '#'
    

you can do:

    
    
         grep -v '#' data.txt
    

or you can simplify further by moving the grepping into awk, so that the full
command becomes

    
    
          awk '!/#/{print $2}' data.txt | sort -n | uniq -c
    

sort -n is good to use for sorting numbers. You could probably pull the sort |
uniq -c into awk somehow, but I have already demonstrated the full extent of
my awk knowledge. One of these days I will get around to actually learning it.

~~~
greyfade
You can also pre-sort if you have GNU utils:

    
    
        sort -n -f 2 <data.txt | awk '!/#/ ...

------
why-el
`cd -` to go back to the previous directory. Saved me LOTS of time over the
past few months.

~~~
nja
Wow. Thanks for this. I always cursed myself for forgetting to pushd, and now
it turns out I didn't need to!

~~~
jamie_ca
I recently found out that zsh lets you magically popd as well, as long as
you're cding deeper into the tree. If you jump to a different subtree it will
pop its internal stack until it finds a parent of the target dir.

------
happywolf
I recommend Quicksilver on mac, free and powerful. It lets you to find a lot
of stuff (application, contact, email, etc.) and manipulate them (send,
forward, print, etc.)

[http://qsapp.com/](http://qsapp.com/)

~~~
jentulman
Also in that vein on Mac it's worth having a look at Alfred
[http://alfredapp.com](http://alfredapp.com)

~~~
actionscripted
Alread rocks. You can develop workflows for common groups of tasks and it
integrates well with iTunes, 1Password, Terminal and other system
actions/apps.

~~~
adamnemecek
It really does. My computer would be like 30% less usable without it. The file
search is particularly amazing.

------
ben0x539
bash(?) thing I wish I'd discovered years earlier: diff <(command1)
<(command2) instead of command1 > file1; command2 > file2; diff file1 file2;
rm file1 file2

~~~
gnaritas
Yup, cool use of named pipes.

~~~
tripa
Named pipes are filesystem objects you create with mkfifo.

What's in use here is more widely known as “process substitution”.

~~~
gnaritas
Which works by creating two named pipes and feeding them to diff and pumping
your processes data into them. Process substitution is built on named pipes,
they are the enabling mechanism that makes it work. Try this in a terminal:

    
    
      echo <(true)
    

And you'll see the anonymous named pipe created by the subshell and passed to
echo.

------
tptacek
Do yourself a favor: unzip the source for ascii.7 and change the order of the
tables: hex, then decimal, then octal.

You'll thank me later.

~~~
jlgreco
I kind of like how the hex and char columns are next to each other though.
Makes it easier to read those two columns together quickly.

------
bndr
I recently discovered ncdu
([http://dev.yorhel.nl/ncdu/scr](http://dev.yorhel.nl/ncdu/scr)) as an
alternative to du. Quite handy.

~~~
webreac
baobab ?

~~~
jlgreco
baobab is nice when you have X around, but ncdu has allowed me to get back up
and running on more than one occasion.

------
ja27
xargs. Can't tell you how many times I wrote quickie C programs and awk
scripts to do what xargs does.

[http://sidvind.com/wiki/Xargs_by_example](http://sidvind.com/wiki/Xargs_by_example)

~~~
marcosdumay
And find, that's a nice alternative to xargs when your args are a huge set of
files.

~~~
smagch
You can also use parallel instead of xargs when files are huge.

------
dagw
GNU Parallel. My new favorite command. I have probably written at least two or
three ad-hoc, buggy, feature poor versions of that command before discovering
it.

------
brown9-2
I'm unreasonably excited about discovering xxd.

~~~
Luyt
xxd is on OSX, but not on FreeBSD. Under FreeBSD, I always use 'hd
somefile.bin'.

~~~
D9u
I have xxd on my FreeBSD setup.

    
    
        uname -rms
        FreeBSD 9.1-RELEASE-p19 amd64
    

Although the xxd man page doesn't have the BSD label, and is from 1996, so I'm
not sure if xxd only recently found its way into FBSD.

    
    
        This manual page documents xxd version 1.7
    
        AUTHOR
           (c) 1990-1997 by Juergen Weigert

~~~
laumars
It maybe in ports, but it's not part of the base install:

    
    
        $ xxd
        xxd: Command not found.
        $ uname -rms
        FreeBSD 9.1-RELEASE amd64
    

edit: fixed typo where I put _xdd_ instead of _xxd_

~~~
D9u
I didn't add xxd on my local FBSD (installed last night) setup, and my remote
FBSD shell has xxd installed by default...

    
    
        $ uname -rms
        FreeBSD 9.1-RELEASE-p7 amd64
    
        $ xxd -v
        xxd V1.10 27oct98 by Juergen Weigert
    

Perhaps different builds have different things included?

~~~
laumars
No, it installs as part of _vim_ :
[https://news.ycombinator.com/item?id=6361210](https://news.ycombinator.com/item?id=6361210)

~~~
D9u
[http://vim.wikia.com/wiki/Improved_hex_editing](http://vim.wikia.com/wiki/Improved_hex_editing)

You're right, xxd is included with vim, but as an external program.

 _Vim provides this capability through the external program xxd, which is
included by default in standard distributions of Vim._

My pedantic nature was hung up on the release dates of the respective
programs, as xxd predates vim on Unix.

------
casca
TL;DR: man ascii, cal, xxd, ssh, mdfind

~~~
chrisdotcode
`mdfind' in non-Mac UNIXs is spelled `locate' (and the corresponding
`updatedb' updates the indexing db, obviously (although you don't have to do
this often, as it runs as a cron job)).

~~~
Camillo
mdfind is incomparably more powerful than locate.

------
malkia
I have the bad habit of trying out everything in /usr/bin (linux, OX) and in
c:\windows\system32 (and further on, digging Program Files / Applications /
etc.).

This is how I discovered myself "fsutil" (Windows) :)

------
JimmaDaRustla
I'm always surprised at the lack of general knowledge of Regular Expressions,
so egrep would be a huge one for newcomers.

------
ck2
I want a command that counts files in a tree like du does sizes but without
having to pipe _find_ through _wc_ which is crazy for hundred thousand files.

Can't they just directly access inodes for high speed counting?

~~~
bendaid
tree does this, don't know about suppressing the actual tree, but it tells you
number of files and dirs printed at the end.

~~~
laumars
A regex match will do that easily enough:

    
    
        tree | egrep -o "[0-9]+ file(s|)"
    

edit: or you could just tail the output (should have thought of this first!)

    
    
        tree | tail -n1

------
wpietri
A personal favorite: the file command. Through deep magic(5), it can describe
the content of a lot of files.

------
foobeer
Never knew about the "cal" command. I especially like that you can quickly
look up a previous or future month/year. >> cal 3 1973 quickly shows a
calendar of March 1973

~~~
Shish2k
you can even look up `cal sept 1752`

~~~
quchen
Funny, 3-13 are missing here.

    
    
      > cal sep 1752
         September 1752     
      Su Mo Tu We Th Fr Sa  
             1  2 14 15 16  
      17 18 19 20 21 22 23  
      24 25 26 27 28 29 30
    

Edit: Oh, colour me surprised.
[https://en.wikipedia.org/wiki/September_14](https://en.wikipedia.org/wiki/September_14)

~~~
ghotli
This was the best thing I learned today

------
joshcorbin
One of my favorites: column -t

Examples include: $ df -h | column -t $ column -t -s: /etc/passwd

------
shawkinaw
I really love pushd/popd.

~~~
guard-of-terra
zsh has AUTO_PUSHD, guess what it does.

~~~
mafro
jump just made it into oh-my-zsh:

[http://jeroenjanssens.com/2013/08/16/quickly-navigate-
your-f...](http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-
filesystem-from-the-command-line.html)

------
helloTree
My biggest improvement was about finding out about .inputrc and configuring
the Bash to use VIM-keybindings which is pretty handy if you are used to the
editor. Also the following mapping from ESC to pressing jf via

imap jf <ESC>

was very nice as I find it much more ergonomic. And to use it in Bash I have

set editing-mode vi set keymap vi

$if mode=vi set keymap vi-insert "jf": vi-movement-mode $endif

set show-all-if-ambiguous on

~~~
aikinai
I have my Bash set to vi keybindings, but I had no idea it was possible to
remap them. Now I can finally stop hitting escape in Bash too. Thank you so
much!

~~~
helloTree
Yeah it is great if you can use similar commands across applications. Btw.
there is also a nice history inside VIM (implemented as a separate buffer)
that can be accessed using q: so you can scroll through the history with jfkl.
E.g. I use that for accessing files: If you are working on a project you will
probably edit similar files. If you use one "programming" vim sessions where
you always edit files via :tabe you will find all the recent edited files in
your history and using q:/ you can search for them pretty fast. So over time
you have automatically a working environment adapted to your current project.

------
rfatnabayeff
There are some other useful commands for organizing the stream of datas for
pretty printing:

column - columnify the incoming stream into columns

pr - set up incoming stream for pretty printing including columnification
along or across the screen

tr - sanitize input, collapse several delimiters into one

~~~
epsylon
I use tr all the time when I want to check $PATH:

echo $PATH | tr : '\n'

------
thejosh
One of my favourite traceroute replacements, that is installed by default on
Ubuntu: mtr !

------
codegeek
I love "tail -f" to see realtime updates on a file that I am writing to!!

~~~
shawkinaw
If you don't want to clog up your terminal, try 'less' and then hit 'F' to
follow.

~~~
zipperhead
Better yet use 'less +F'. It's as easy to remember as tail -f.

The advantage of using less here is that you can easily interrupt the tailing
(ctrl-c). For example, to search. Then just hit 'F' again to restart tailing.
But now your search pattern will be highlighted as the data streams by.

~~~
reuven
I have been using both "tail -f" and less for years, and never knew about
this. Thank you. In three lines of text, you have made my logfile-centric life
oh-so-much easier to deal with.

------
mpyne
I believe xxd is actually part of vim and not a Unix command itself. It's used
to support hex-editing binary files, but you can see why it's useful in other
roles as well.

~~~
D9u
The origins of xxd seem to be a bit murky, as I've seen others say the same
thing about xxd being available only if vim is installed, but I've never seen
a Unix system that didn't have vi(m) included.

    
    
        $ man xxd | grep vi
           Use xxd as a filter within an editor such as vim(1) to hexdump a	region
           Use xxd as a filter within an editor such as vim(1) to recover a	binary
           Use xxd as a filter within an editor such as vim(1) to recover one line
    

[http://grail.cba.csuohio.edu/~somos/xxd.c](http://grail.cba.csuohio.edu/~somos/xxd.c)

From what I've been able to find, vim was released in 1991, and xxd has been
around since at least 1990, whereas vi was written by Bill Joy in 1976.
(according to Wikipedia)

Interesting bit of trivia, perhaps someone with a good memory can clear it up
for us?

~~~
clarry
There are no hits for xxd on the Unix Tree ([http://minnie.tuhs.org/cgi-
bin/utree.pl](http://minnie.tuhs.org/cgi-bin/utree.pl)) so it's definitely not
a traditional Unix tool. I'm sitting in front of a BSD system which includes
nvi. I don't have xxd.

------
wildmXranat
Less +F with search highlighting mentioned in comments is my new fave command.
I was beholden to 'tail -f', not that it sucked.

------
ruok0101
One little known, but very handy tip:

At any password prompt, if you knowingly mis-keyed your password, rather than
pressing return, getting the "your an idiot" message (often after an annoying
1 - 2 second delay), and having to retype the command, you can actually press
ctrl-U, which is the "Clear the line" bash command, and start over typing your
password again.

~~~
rockybutler
For those of us using emacs-style bash keybinds. For vi-style keybinds, it's
something more like "esc dd".

PS if you are a Vim user, you owe it to yourself to try the vim-style
keybinds. They make a world of difference.

------
cheese1756
For the ssh section, I'd also include sshfs. It's super handy when you want to
use local (or GUI) applications for a file on a server, or just to mount your
home computer as a drive while you are away. I personally use it to mount my
backup server's drive on my Chromebook, effectively giving myself a 500GB hard
drive whenever I need it.

------
jbaiter
A great one I found out about recently is 'watch'. Periodically calls a
command and refreshes the screen with its stdout.

------
DavidWanjiru
I'm feeling rather good about myself because although I'm a complete novice at
linux, I knew the cal command. Yay me! I read about it here:
[http://linuxcommand.org/tlcl.php](http://linuxcommand.org/tlcl.php)

------
keithpeter

        history | grep <keyword>
    

I use this for <keyword> rsync or rdesktop when I have forgotten the long list
of options & directories etc

I also use ctrl R <keyword> at the bash prompt but that only gives me the most
recent match.

~~~
pbhjpbhj
> _I also use ctrl R <keyword> at the bash prompt but that only gives me the
> most recent match._ //

Are you sure, I'm using BASH on Kubuntu and I get previous matches by repeated
use of ctrl+R.

Actually inspired by a previous post here I made a script "hs" that searches
archived history files and shows me all past match lines. Before that I did
what you do now.

~~~
keithpeter
Indeed it does! Excellent

------
acheron
ctrl-R in bash was mine.

~~~
claudius
Try C-x C-e – especially helpful if you want to paste stuff from websites.

------
mncolinlee
Along with the SSH recommendations, I would include some of the great helpers
for ssh agent like keychain.

[https://wiki.gentoo.org/wiki/Keychain](https://wiki.gentoo.org/wiki/Keychain)

------
simonreed
man units

------
tmcb
I'm quite impressed no one mentioned 'fg', 'bg', and 'jobs'. Since I got used
to them, the number of open ptys in my screen dropped drastically.

------
Kiro
When do you need man ascii and xxd? I'm a front-end developer so I have no
clue about these low-level things but I'm interested and would like to learn.

~~~
F30
There are a lot of usecases for bot of them, mostly debugging I's say. So I'm
gonna tell you what I used them for in the past months:

The ASCII table might be useful when you're dealing with encoding problems and
want to know e.g. what exactly happened in a broken URL encoding. I used both
of them for binary exploitation in the security class I took at university:
When utilizing buffer overflows, it's important to get every byte at the right
place of your payload. Sometimes, you also need to treat it as a string and
that's where ASCII comes in.

These are only two specific usecases. As I said, there are a lot more.
Development of binary file parsers could be another.

------
social_monad
look at: man utf8 man syscalls

... and the best hint imo to process malformed filenames per 'find -print0'
is:

find ... -print0 | { while read -d $'\0' fil ... # use variable fil }

Regards

------
rabino
I recently discovered whatis and I love it.

~~~
peterwwillis
Yup, it's a great way to review a lot of commands without reading every man
page.

Want to find all the tools on your system that use the curses library (for
user-friendly interfaces)? Try this:

    
    
      for i in `\ls /bin/* /sbin/* /usr/bin/* /usr/sbin/* | sort -u` ; do ldd $i 2>/dev/null | grep -q curses && whatis `basename $i` ; done | grep -v 'nothing appropriate'
    

Don't know how your current path finds a program? Use which:

    
    
      pwillis@zippy:~$ which df
      /usr/bin/df
      pwillis@zippy:~$ which mount
      /bin/mount
    

Annoyed that /sbin and /usr/sbin aren't in your path? Use whereis:

    
    
      pwillis@zippy:~$ which ifconfig
      which: no ifconfig in (/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/lib64/kde4/libexec:/usr/kerberos/bin:/usr/lib64/java/bin:/usr/lib64/java/jre/bin:/usr/lib64/qt/bin:/usr/share/texmf/bin:.)
      pwillis@zippy:~$ whereis ifconfig
      ifconfig: /sbin/ifconfig /usr/man/man8/ifconfig.8.gz /usr/share/man/man8/ifconfig.8.gz /usr/X11/man/man8/ifconfig.8.gz

~~~
Wicher
Apropos 'which', let me show 'type -a':

    
    
      % type -a which
      which is a shell builtin
      which is /usr/bin/which
    

Convenient if you really want to know what you'll be calling.

------
ngcazz
Brace expansion to create a backup:

    
    
        cp {file,.bak}
    

reduces to

    
    
        cp file file.bak

~~~
qu4z-2
Brace expansion is great! My understanding, though, is that you'd need to
write:

    
    
      cp file{,.bak}
    

Was it a typo, or is there some feature/special-case I don't know about?

~~~
ngcazz
Oh, you're right. Thanks. (Can't edit the original comment anymore)

------
sebnukem2
How can one use a Unix/Linux system without knowing SSH? How to login remotely
without it?

~~~
jfb
There are a large percentage of people who first encounter unix on single-
interactive-user machines.

------
general_failure
my favorite is apt-file

~~~
Toenex
Thank you.

------
doktorn
strings - find the printable strings in a object, or other binary, file. Good
command to know of if you want to snoop around in binary files.

------
talles
Didn't know about the ascii one.

------
guard-of-terra
xmlstarlet is a very nice obscure utility which you will love if you touch
moderate amounts of XML.

~~~
gnaritas
Yes it is!

------
gajomi
Glad to learn of cal!

------
hannibal5
Unix and Common Lisp are similar in many ways:

1\. Both are operating systems

2\. Both are conceptually simple.

3\. There is always nice command that does what you want but you somehow
forget it. I can't believe that Common Lisp has just 900+ symbols but I
routinely forget some of them when programming.

~~~
Keyframe
My favorite part is when you implement something you could've had running in a
minute or so, but instead developed it for hours or days and it's still not as
good as the existing solution. I often get that with C and libraries. There
has to be a better way to search through existing stuff which is good and
proven, not just for C of course.

~~~
philsnow
Haskell has hoogle [0], that lets you search by type signature. If you already
know roughly what kind of function you want, it's a lot easier to sift through
a tiny handful of (or even a single) functions that match a given type
signature.

ISTR Forth had something similar, or maybe I'm just thinking that in Forth,
words are almost uniquely defined by their stack annotations.

[0] [http://www.haskell.org/hoogle/](http://www.haskell.org/hoogle/)

------
mpu
ssh, come on...

