Live data from Hacker News

Unix Tricks

cfenollosa.com

101–110 of 166 posts

Re: Unix Tricks

#101
post #42

I have for cmd in $(compgen -c); do if [[ $cmd =~ ^[0-9a-zA-Z]+$ ]]; then eval "alias $cmd?='man $cmd'"; fi; done in my .bashrc to alias command?=man command, saves some typing to get to man pages ( which I do very often )

For zsh:

  for cmd in $(compgen -c); do if [[ $cmd =~ ^[0-9a-zA-Z]+$ ]]; then eval "alias $cmd\?='man $cmd'"    ; fi; done
# had to escape the ? in the alias name

Cool trick :)

Re: Unix Tricks

#102
post #94
post #55

Earlier quoted context omitted.

In Linux with bash (and probably other shells that are bash-compatible), you can use vi to edit any of the commands in your command history, and then execute the edited version. Do this at the command prompt, or once in your ~/.bash_profile to make it permanent: set -o vi After that, you can search for any of the commands in your history, edit it, and then execute the edited command, by doing this: At the prompt, typ…

If you like that, you can put: set editing-mode vi in your ~/.inputrc (instead) and all GNU libreadline using programs will give you vi keys instead of emacs :-)

Cool :)

Re: Unix Tricks

#103

Earlier quoted context omitted.

You can also send SIGUSR1 to dd for progress info. From the manpage: Sending a USR1 signal to a running 'dd' process makes it print I/O statistics to standard error and then resume copying. $ dd if=/dev/zero of=/dev/null& pid=$! $ kill -USR1 $pid; sleep 1; kill $pid 18335302+0 records in 18335302+0 records out 9387674624 bytes (9.4 GB) copied, 34.6279 seconds, 271 MB/s

On OSX it's SIGINFO (29) in case anybody wondered

Which you can also get by hitting Ctrl-T. This works for FreeBSD too. (Not sure about the other BSDs.)

Re: Unix Tricks

#104
post #64

Missing trick: In bash, "ESC" then "." fetches the last parameter of the previous command. It's invaluable (same as typing "!$" but you get to see and edit it)

I prefer `alt+.`, which does the same thing without having to reach for the ESC key.

Re: Unix Tricks

#105
> In bash, 'ctrl-r' searches your command history

No! In emacs ctrl-r searches your command history. It happens that bash use emacs mode by default. All other emacs basic commands work too: ctrl-p, ctrl-n, ctrl-f etc...

If you are a vim user, and especially if you love venting how much you hate emacs, then please add this to your bashrc:

set -o vi

and now you can use vim command instead of emacs.

Re: Unix Tricks

#107
post #66

Earlier quoted context omitted.

TIL. As a long-time DOS user that often gets a bit lost on Unix systems I cannot stress how awesome it is to have found out about this!

Wow, DOS users still exist? Which one? FreeDOS? Back in the late 90s when I first moved to Debian from Windows, growing up with a DOS CLI made the transition far easier to me (and having some FTP exposure didn't hurt either).

There's no good way to refer to the entire DOS/Windows command shell lineage without confusion, but that's what I meant. I don't technically use DOS at all anymore. I think "that system" is easier to understand in it's entirety and find your way around than Unix, although it has been getting progressively more complex for years. I actually use OS X most of the time now (plus Linux on servers and Windows for 3D stuff).

Re: Unix Tricks

#108

> In bash, 'ctrl-r' searches your command history No! In emacs ctrl-r searches your command history. It happens that bash use emacs mode by default. All other emacs basic commands work too: ctrl-p, ctrl-n, ctrl-f etc... If you are a vim user, and especially if you love venting how much you hate emacs, then please add this to your bashrc: set -o vi and now you can use vim command instead of emacs.

'ctrl-r' is reverse-i-search in vi mode as well.

Re: Unix Tricks

#109
post #66

Earlier quoted context omitted.

Wow, DOS users still exist? Which one? FreeDOS? Back in the late 90s when I first moved to Debian from Windows, growing up with a DOS CLI made the transition far easier to me (and having some FTP exposure didn't hurt either).

There's no good way to refer to the entire DOS/Windows command shell lineage without confusion, but that's what I meant. I don't technically use DOS at all anymore. I think "that system" is easier to understand in it's entirety and find your way around than Unix, although it has been getting progressively more complex for years. I actually use OS X most of the time now (plus Linux on servers and Windows for 3D stuff)…

> I think [DOS] is easier to understand in it's entirety and find your way around than Unix

Yikes, I recently had to do a bit of development on a windows box and I found the command-line tools (not to mention CMD itself, which seems to have stopped development in 1993) to be absolutely awful. I could barely survive without Cygwin, git bash, etc giving me some semblance of a functional shell setup. I guess it's different strokes for different folks.

Re: Unix Tricks

#110

Earlier quoted context omitted.

There's no good way to refer to the entire DOS/Windows command shell lineage without confusion, but that's what I meant. I don't technically use DOS at all anymore. I think "that system" is easier to understand in it's entirety and find your way around than Unix, although it has been getting progressively more complex for years. I actually use OS X most of the time now (plus Linux on servers and Windows for 3D stuff)…

> I think [DOS] is easier to understand in it's entirety and find your way around than Unix Yikes, I recently had to do a bit of development on a windows box and I found the command-line tools (not to mention CMD itself, which seems to have stopped development in 1993) to be absolutely awful. I could barely survive without Cygwin, git bash, etc giving me some semblance of a functional shell setup. I guess it's differ…

I agree: awful tools and batch language is horrible (and largely non-portable between different versions). Getting complicated stuff to work can be tricky due to the lack of essential commands. For instance, there's no way to reliably get an ISO formatted datestamp without a 3rd party utility (although I think PowerShell supports this). Lots of odd little things like that simply don't work.

But the filesystem layout and set of built-in commands is pretty easy to understand fully. It's generally pretty easy to find things. In that sense Unix is more complex (but also more sensible, usually).

Post reply on HN