News for hackers. Stuff that matters.
Re:Favorite Unix Commands by nickwoodhams on Monday January 07, 2013 @01:52PM (#5022471)
Please comment if you have a favorite not on this list.
Re:Favorite Unix Commands by cnvogel on Monday January 07, 2013 @04:58PM (#5023506)
If you use tmux (or screen) you want to use byobu!

https://launchpad.net/byobu

https://www.google.de/search?q=byobu+tmux&tbm=isch

It's a fancy statusbar that shows CPU speed, IP-address, hostname, ...

Re:Favorite Unix Commands by jsaxton86 on Monday January 07, 2013 @05:19PM (#5023610)
You can get a fancy status bar with screen, you just need a screenrc file: http://www.mbeckler.org/blog/2012/11/28/my-screenrc-file-cir...
Re:Favorite Unix Commands by vially on Monday January 07, 2013 @05:07PM (#5023550)
Another option is tmux-powerline[1]

[1] https://github.com/erikw/tmux-powerline

Re:Favorite Unix Commands by tkahn6 on Monday January 07, 2013 @06:38PM (#5023967)
I have something similar in my .tmux.conf file

Screenshot: http://i.imgur.com/u6JY0.png

Config file: https://github.com/tylerkahn/dotfiles/blob/master/.tmux.conf...

Works with OSX and Linux.

Re:Favorite Unix Commands by jlgreco on Monday January 07, 2013 @02:56PM (#5022854)
'tac'. It is 'cat', but backwards.
Re:Favorite Unix Commands by SenorWilson on Monday January 07, 2013 @04:21PM (#5023329)
Are you some kind of genius?
Re:Favorite Unix Commands by jlgreco on Monday January 07, 2013 @05:06PM (#5023546)
If you enjoy 'tac', you might also enjoy 'sponge'.

Spong 'soaks up' input an releases it all on one chunk so that you can do things like:

  cat foo | sponge foo
(`cat foo > foo` does not work)

That's neat and all, but what if you don't have sponge? Well, just use tac twice!

  cat foo | tac | tac > foo
(Obviously this is rather wasteful ;))
Re:Favorite Unix Commands by thristian on Monday January 07, 2013 @10:40PM (#5024744)
I cannot understand how this works.

"cat foo > foo" breaks, because the shell truncates the file "foo" while it's setting up the redirection, before it launches "cat foo", and so cat has nothing to read.

"cat foo | sponge foo" works because the shell is not responsible for writing to foo; it launches cat (which opens the file for reading) then launches sponge (which eventually opens the file for writing).

I would thus expect "cat foo | tac | tac > foo" to fail in the same way as "cat foo > foo" because the shell is still going to open the file foo and truncate it, but experimentation shows that it does actually work. Is it because the shell launches each pipeline one at a time, so cat has read the file before "tac > foo" truncates it? Is it a race-condition or a corner-case?

Re:Favorite Unix Commands by jlgreco on Monday January 07, 2013 @11:04PM (#5024817)
That's a good question. I had though it worked because the truncate would not actually happen until tac actually wrote something, but now that I look at it more I don't think that is actually the case. `cat > foo` immediately truncates foo before anything is written. Also `tac foo > foo` doesn't work, which discredits my hypothesis that tac's buffering was causing it.

Furthermore `cat foo | cat > foo` does not work, but `cat foo | cat | cat > foo` does work.

I suspect this behavior is actually a race condition of some sort.

Edit: definetly a race condition, shown by larger files:

  % wc -l foo
  1310720 foo
  % cat foo | cat | cat > foo
  % wc -l foo
  16384 1
Re:Favorite Unix Commands by thristian on Monday January 07, 2013 @10:29PM (#5024719)
I always get confused between "tac" and "rev", which is also "cat, but backwards" for a certain definition of "backwards".
Re:Favorite Unix Commands by cnvogel on Monday January 07, 2013 @04:34PM (#5023399)
When rewriting large amounts of ASCII text (or comments in Code), I really find "par" helpful.

    : Just use it in :
    : vi with your cursor in front of a badly wrapped block of text. :
    : Press !}par<enter> and the text will be :
    : piped to par :
    : which fixes up :
    : the :
    : formatting and keeps aligned frame markers :
    : intact magically. :


    : Just use it in vi with your cursor in front of a badly wrapped   :
    : block of text. Press !}par<enter> and the text will be piped     :
    : to par which fixes up the formatting and keeps aligned frame     :
    : markers intact magically.                                        :
http://www.nicemice.net/par/ (or apt-get install par)
Re:Favorite Unix Commands by satiani on Monday January 07, 2013 @08:35PM (#5024405)
Or you can just select the block of text and type gq. This will do what par does, and can be adjusted with vim's 'textwidth' and 'formatoptions' settings.
Re:Favorite Unix Commands by zeraholladay on Monday January 07, 2013 @08:33PM (#5024395)

    export CDPATH=.:~/projects
    export PS1="$(uname -n)$ "
    alias ltr='ls -ltr'
More of a procedure, always list file and edit the command before deleting it:

    $ ll file.txt
    -rw-r--r--  1 zera  staff  0 Jan  7 20:28 file.txt
    Ctrl-p, Ctrl-a, Ctrl-d, Ctrl-d, r,m
    $ rm file.txt
So this is a sanity check to avoid this mistake:

    $ rm *.txt
*Edit, one more:

Ensure you overwrite a file (or aren't):

    $ cp -i ~/file.config /etc/
Re:Favorite Unix Commands by codegeek on Monday January 07, 2013 @03:32PM (#5023070)

    alias lsd="ls -ltrF | grep ^d"
Helps me quickly list only directories. Any better alternatives ?
Re:Favorite Unix Commands by gav on Monday January 07, 2013 @03:38PM (#5023105)
Using `find` is nice to get just directories:

$ find . -type d -maxdepth 1

Re:Favorite Unix Commands by pnrao on Monday January 07, 2013 @07:49PM (#5024266)
I use:

% ls -d */

Re:Favorite Unix Commands by VaucGiaps on Monday January 07, 2013 @04:24PM (#5023348)
ls -al | grep ^d
Re:Favorite Unix Commands by ralph on Monday January 07, 2013 @05:50PM (#5023759)
(Fails if a directory has a linefeed in its name followed by a 'd'. :-)
Re:Favorite Unix Commands by lneves on Monday January 07, 2013 @03:43PM (#5023129)

  find . -type d
edit: for the same output as your command you can use:

  dir -l
Re:Favorite Unix Commands by williadc on Monday January 07, 2013 @03:44PM (#5023137)
Dunno what "better" means, but this also works:

find -maxdepth 1 -type d

Re:Favorite Unix Commands by mttsn on Monday January 07, 2013 @03:49PM (#5023159)
seconded. what I have always used
Re:Favorite Unix Commands by jfb on Monday January 07, 2013 @04:40PM (#5023428)
Depends on the shell. In zsh (with EXTENDED_GLOB): *(/) matches only directories.
Re:Favorite Unix Commands by super_mario on Monday January 07, 2013 @07:57PM (#5024292)
I usually

    alias lsd='ls -d */'
Re:Favorite Unix Commands by magoon on Tuesday January 08, 2013 @07:20AM (#5025881)
ls -l | grep drw

I know, it's a bad habit

Re:Favorite Unix Commands by joshbaptiste on Monday January 07, 2013 @10:48PM (#5024772)
echo */ (perfect when your unable to fork)
Re:Favorite Unix Commands by mappu on Tuesday January 08, 2013 @12:21AM (#5025016)

    sl
Re:Favorite Unix Commands by asparagui on Monday January 07, 2013 @02:29PM (#5022675)
alias emacs="nano"
Re:Favorite Unix Commands by GrumpySimon on Monday January 07, 2013 @03:36PM (#5023096)
export EDITOR=/usr/bin/nano
Re:Favorite Unix Commands by zacharystern on Tuesday January 08, 2013 @12:13PM (#5027131)
nooooooo!
Re:Favorite Unix Commands by jfb on Monday January 07, 2013 @04:34PM (#5023398)
tsort. It's pointless until you need it, but when you need it, it's totally awesome.

less. Overkill, but SO MUCH BETTER THAN tail -f. Seriously. You can toggle "follow mode" without losing your place in the incoming stream.

Re:Favorite Unix Commands by Florin_Andrei on Monday January 07, 2013 @04:56PM (#5023498)
> less. Overkill, but SO MUCH BETTER THAN tail -f. Seriously.

If you do this on my servers, I am going to find you, and then I am going to kill... um... your process.

less with SHIFT-F takes a whole CPU core to run on a busy log file. tail -f takes almost nothing to run. Now combine that information with the reality of a whole bunch of devs who don't know it or don't care about it. :(

Re:Favorite Unix Commands by alexkus on Tuesday January 08, 2013 @06:34AM (#5025782)
I prefer:-

    tail --follow=filename
to:

    tail -f filename
The former will spot inode changes and reopen the filename if the file wraps (or has something else done to it to change its inode). The latter will just sit there seeing no new input in such cases.
Re:Favorite Unix Commands by mje__ on Monday January 07, 2013 @04:57PM (#5023503)
multitail[1] is also really nice for following multiple log files. It can do highlighting of lines based on regex's, and has built-in highlighting of a wide variety of log formats

[1] http://www.vanheusden.com/multitail/features.php

Re:Favorite Unix Commands by jlgreco on Monday January 07, 2013 @05:11PM (#5023571)
Does anybody know if there is a good standalone regex highlighter? I usually use `ack --passthru`, but that has always seemed a tad.. overkillish to me.
Re:Favorite Unix Commands by cjg_ on Monday January 07, 2013 @04:51PM (#5023477)
Hm, can you start at the end of file without reading the entire file with less? Use case is tailing large logs.
Re:Favorite Unix Commands by ralph on Monday January 07, 2013 @05:47PM (#5023738)
Yes, either type G when presented with the top of the file or pass +G on the command line. It will then read all the intervening file to calculate the line numbers, and tells you it's doing this and to interrupt it to stop. To prevent it doing this in the first place use the -n option.

"less -n huge_file" and then G only reads the start and end of the file. Type G again to move to the latest end of the file if it's growing.

Re:Favorite Unix Commands by jfb on Monday January 07, 2013 @05:01PM (#5023516)
Yes. It is CPU intensive (see auntie post above).
Re:Favorite Unix Commands by lelf on Monday January 07, 2013 @03:28PM (#5023044)
dtrace :P