Live data from Hacker News

Useful Unix commands for data science

gregreda.com

81–90 of 108 posts

Re: Useful Unix commands for data science

#81
post #80

I've been using Ubuntu for about a year now and although I feel comfortable doing a lot of things with the CL, I'm not sure if I really know enough about *nix. I wish there was a was a website with the 20-30 most useful unix commands and very clear language as to what they do with examples. Although, I've used all the tools in this post, I still enjoyed the use of example.

Software Carpentry provides a good overview with examples: http://software-carpentry.org/4_0/shell/index.html

Re: Useful Unix commands for data science

#82
post #65

One of my favorite little tools that makes all these others better is pv -- PipeViewer. Use it any place in a pipeline to see a progress meter on stderr. Very handy when grepping through a bunch of big log files looking for stuff. Here is a quick strawman example: pv /data/*.log.gz | zgrep -c 'hello world' 241MiB 0:00:15 [15.8MiB/s] [==> ] 2% ETA 0:12:12

BSD has a progress meter utility. It's called progress(1). progress -zf /data/*.log.gz grep -c 'hello world' progress -f /data/*.log.gz zgrep -c 'hello world' The second form will show the progress of the decompression process. You can also adjust buffer size, set the length for the time estimate (otherwise we have to fstat the input), and display progress to stderr instead of stdout.

Which BSD has that? I don't seem to find it in my FreeBSD installs.

Re: Useful Unix commands for data science

#84
>>Writing a script in python/ruby/perl/whatever would probably take a few minutes and then even more time for the script to actually complete.

Thankfully you can also write a Perl one liner. Which most of the times is far powerful than awk.

Re: Useful Unix commands for data science

#85
post #77
post #53

Earlier quoted context omitted.

Agree. Or actually I start with a 'head -100' so I don't handle too much data in my pipeline until it's ready.

I'm old fashioned, so use "sed 100q" instead of the newer "head -100". It saves a keystroke, too. There are enough variations in ways to do things on Unix that I've sometimes wondered about how easy it would be to identify a user by seeing how they accomplish a common task. For instance, I noticed at one place I worked that even though everyone used the same set of options when doing a "cpio -p", everyone had their o…

I sorta had this happen to me once. I have used "lsl" as an alias for long directory listings for longer than I can remember. And just out of habit it was almost always the first command I typed when logging into any box anywhere.

So one day I telnetted into a Solaris machine and immediately typed "lsl" before doing anything else. A short while later a colleague came to my cube. He had been snooping the hme1 interface and saw me login. He didn't need to trace the IP because he knew it was me when he saw 3 telnet packets with "l" "s" "l" in them.

Re: Useful Unix commands for data science

#86
post #82
post #65

Earlier quoted context omitted.

BSD has a progress meter utility. It's called progress(1). progress -zf /data/*.log.gz grep -c 'hello world' progress -f /data/*.log.gz zgrep -c 'hello world' The second form will show the progress of the decompression process. You can also adjust buffer size, set the length for the time estimate (otherwise we have to fstat the input), and display progress to stderr instead of stdout.

Which BSD has that? I don't seem to find it in my FreeBSD installs.

It's actually in FreeBSD's base, but it's part of the ftp(1) program.

   http://svnweb.freebsd.org/base/vendor/tnftp/dist/src/progressbar.c

   http://ftp.netbsd.org/pub/NetBSD/NetBSD-release-6/src/usr.bin/{Makefile,progress.c}
Not sure if you prefer binary installs or whether you compile your installs yourself... but I'm sure you could get this to compile on FreeBSD with a little work.

Re: Useful Unix commands for data science

#87

Actually useful data science tips for unix users. Make all your commands 3x faster: export LC_ALL=C Actually use the 32 CPUs you paid for: sort --parallel=32 ... xargs -P32 ...

Note that the standard Solaris versions of many commands are substantially faster than their GNU equivalents in the 'C' and multi-byte locales so this advice doesn't necessarily apply.

That's part of why Solaris continues to use them in favour of GNU alternatives (although the GNU alternatives are available easily in /usr/gnu/bin).

Re: Useful Unix commands for data science

#88
"Imagine you have a 4.2GB CSV file." "

All you need... is the sum of all values in one particular column."

In that case, if speed was paramount, I'd use Kona or kdb. Unquestionably, k is the best tool for that particular job.

Re: Useful Unix commands for data science

#89
post #25
post #14

A commenter on the article pointed out the "Useless use of cat". What most users probably don't realize is that the redirection can be anywhere on the line, not just at the beginning. Putting an input redirection at the beginning of the command can make the data flow clearer: from the input file, through the command, to stdout: (This only works for simple commands; you can't do `< file if blah; then foo; else bar; fi…

"Useless use of cat" is one of those boring pedantic comments that makes me cringe. Who cares? It's usually much more straightforward to build a pipeline from left to right, particularly for people who are just learning this stuff.

> It's usually much more straightforward to build a pipeline from left to right, particularly for people who are just learning this stuff.

True, however, people pointing out UUOC are in fact pointing out that you should not be building a pipeline at all. If you want to apply an awk / sed / wc / whatever command to a file, then you should just do that instead of piping it through a extraneous command.

Sure, as people always mention, in your actual workflow you might have a cat or grep already, and are building a pipeline incrementally; there's no reason to remove previous stuff to be "pure" or whatever. But if you're giving a canonical example, there's no reason to add unneeded commands.

Re: Useful Unix commands for data science

#90
post #80

I've been using Ubuntu for about a year now and although I feel comfortable doing a lot of things with the CL, I'm not sure if I really know enough about *nix. I wish there was a was a website with the 20-30 most useful unix commands and very clear language as to what they do with examples. Although, I've used all the tools in this post, I still enjoyed the use of example.

Software Carpentry provides a good overview with examples: http://software-carpentry.org/4_0/shell/index.html

Looks pretty solid but a bit on the simple side. Thanks for the link.
Post reply on HN