Live data from Hacker News

Unix Commands I Wish I’d Discovered Years Earlier

spin.atomicobject.com

71–80 of 259 posts

Re: Unix Commands I Wish I’d Discovered Years Earlier

#71
post #6

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?

There really isn't any way around this. The first pass over your data is going to be slow while the inode data is examined, but it will be cached for the next pass. If you do this before that data gets removed from the cache it will be much faster. imac:~ $ time find . | wc -l 419191 real 0m37.865s user 0m0.385s sys 0m2.611s imac:~ $ time find . | wc -l 419195 real 0m10.503s user 0m0.330s sys 0m1.430s

This is a nasty hack where it is counting the output from find.

What do you do when find cannot handle the sheer number of files, argument too long from the linux hardcoded MAX_ARG_PAGES

We need a dedicated utility that counts inodes.

Re: Unix Commands I Wish I’d Discovered Years Earlier

#72

I really love pushd/popd.

Ok, that is pretty freaking awesome. Thanks.

For others who don't know it: http://en.wikipedia.org/wiki/Pushd_and_popd. It essentially is a stack for the working directory, so you can get back to where you were previously quickly and easily.

Re: Unix Commands I Wish I’d Discovered Years Earlier

#73
post #71

Earlier quoted context omitted.

There really isn't any way around this. The first pass over your data is going to be slow while the inode data is examined, but it will be cached for the next pass. If you do this before that data gets removed from the cache it will be much faster. imac:~ $ time find . | wc -l 419191 real 0m37.865s user 0m0.385s sys 0m2.611s imac:~ $ time find . | wc -l 419195 real 0m10.503s user 0m0.330s sys 0m1.430s

This is a nasty hack where it is counting the output from find. What do you do when find cannot handle the sheer number of files, argument too long from the linux hardcoded MAX_ARG_PAGES We need a dedicated utility that counts inodes.

[deleted]

Re: Unix Commands I Wish I’d Discovered Years Earlier

#74
post #58
post #28

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.

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

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.

Re: Unix Commands I Wish I’d Discovered Years Earlier

#75
post #66
post #50

Earlier quoted context omitted.

Sorry, that was a typo when posting on here. I did originally run it as xxd: root@primus:/usr/ports # xxd xxd: Command not found. edit: It doesn't show up in my ports either: root@primus:/usr/ports # make search name=xxd Port: textproc/xxdiff Moved: Date: 2013-07-26 Reason: Has expired: Depends on Qt 3.x Port: textproc/xxdiff-scripts Moved: Date: 2013-07-26 Reason: Has expired: Depends on Qt 3.x Obviously xxdiff is a…

$ whereis xxd xxd: /usr/local/bin/xxd /usr/local/man/man1/xxd.1.gz I don't see xxd anywhere in my ports tree. Haha... What a trip. This is the sort of thing that I'll end up wasting half a day trying to get an answer to.

You wont see it in your ports tree because it's part of vim:

    $ grep xxd /usr/ports/editors/vim/pkg-plist
    bin/xxd

Re: Unix Commands I Wish I’d Discovered Years Earlier

#77
post #22
post #6

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?

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

alas it does not show file count per subdirectory

Re: Unix Commands I Wish I’d Discovered Years Earlier

#78
post #11
post #7

Earlier quoted context omitted.

you can even look up `cal sept 1752`

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

This was the best thing I learned today

Re: Unix Commands I Wish I’d Discovered Years Earlier

#79
post #48
post #28

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.

Still about ssh : "typing a password on your local machine once, then using a secure identity to login to several remote machines without having to retype your password by using an ssh key agent. This is awesome. " Sounds awesome, but I really didn't understand what he means. Is he talking about using a certificate (-i option) to log in ?

Yeah, you have a cert set up and put the public cert in the identities file for each server you want to connect to. Then just SSH into each box with agent forwarding ('-a' I think, but you're best to check that).

So you'll need to create an SSH cert first:

    ssh-keygen -b 4096 -t rsa -C "$USER created on $(hostname)" -f $USER.key
Keep the private key, that's essential you keep this safe as it's literally your key to access any servers you do the next step for.

On each server SSH, append your public key to the of /home/$USER/.ssh/authorized_keys (creating the file if it doesn't exist). It must be the public key!

There'll be better guides online for this stuff so I suggest you have a read through them before blindly pasting the stuff I've posted into your terminal. But it's all quite simple stuff once you've grasped the difference between a public and private key (if you weren't already aware - you may well be)

Re: Unix Commands I Wish I’d Discovered Years Earlier

#80

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

Hmm, the day is already highlighted for me (inverted color).
Post reply on HN