Live data from Hacker News

Unix Commands I Wish I’d Discovered Years Earlier

spin.atomicobject.com

251–259 of 259 posts

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

#251
post #245

Brace expansion to create a backup: cp {file,.bak} reduces to cp file file.bak

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?

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

#252
post #187
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?

du just uses the fts API, so if you want something directly equivalent (omitting options and error handling) it was only barely too long to post: http://pastie.org/8315296 Compared to the equivalent find, code #1 is much faster in this completely scientific best of several runs: $ time (find OSS/llvm -type f -or -type l | wc -l) real 0m4.681s $ time du -d0 OSS/llvm real 0m4.863s $ time ./fts OSS/llvm real 0m0.559s Os…

Your code examples were very educational, thank you!

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

#253

history | grep I use this for rsync or rdesktop when I have forgotten the long list of options & directories etc I also use ctrl R at the bash prompt but that only gives me the most recent match.

> I also use ctrl R 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.

Indeed it does! Excellent

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

#254
post #251
post #245

Brace expansion to create a backup: cp {file,.bak} reduces to cp file file.bak

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?

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

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

#255
post #189
post #177

Earlier quoted context omitted.

Isn't that the same as ls -1 ?

Mostly, yes, except that ls -1 does not turn off colours, and maybe there are a few more differences.

Color output is not on by default in 'ls'.

Your 'ls' must be an alias for the real ls with some options. For example, mine is:

    $ type ls
    ls is aliased to `ls --color=auto'
A quick way to run the original 'ls' (not the aliased version), just prefix it with backslash:

    $ \ls ...
Or:

    $ command ls ...

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

#256

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.

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.

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

#257

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…

Re: command line globbing with globstar -- is there some way to get it to cache filepaths that are frequently accessed? It's quite slow for me (I usually use aliases for that, which I was contemplating getting rid of). Thanks a lot for wising me up to the new hotness offered by bash 4+ (zsh is also pretty slow for me for some reason, even though people keep telling me to switch to that. Maybe I'm more impatient than…

Sorry for the late reply. No built in way to cache globbed filepaths as far as I know. I did a little googling but to no avail. I suspect it wouldn't be too complicated to hack something together though. Another potential option: buy an SSD.

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

#258
post #217

Earlier quoted context omitted.

tsort is one of my favorites, mostly because it's totally pointless until you need it and then it works exactly right . I love it.

Wow. I just read the man page for tsort and I am none the wiser. tsort takes a list of pairs of node names representing directed arcs in a graph and prints the nodes in topologi-cal order on standard output. It's not often I understand nothing on a man page. But this time, I'm stumped!

Me too. Then I read the info, it gives an interesting historical perspective of why tsort came about. On a system with GNU utils installed:

  info coreutils 'tsort invocation'

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

#259

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

There are free unix shells out there, google will find them. Don't expect anything fancy, but you will be able to try all the commands talked about here.

To connect to the shell from Windows, you can use the Putty program (google for it), although the shell documentation will almost certainly tell you how to do it.

Post reply on HN