Live data from Hacker News

Unix Tricks

cfenollosa.com

91–100 of 166 posts

Re: Unix Tricks

#91

Earlier quoted context omitted.

>You know what else I hate? Typing in long commands in the Mac OS X terminal and then them wrapping weirdly. Are you escaping your color codes in PS1 correctly? Bad: PS1="\033[1;32m \w \033[m $" Good (notice the extra \[ and \]): PS1="\[\033[1;32m\] \w \[\033[m\] $"

Mine seems escaped as hell, but still gets wrapped. Anything I'm missing? edit: couldn't get UTF-8 branch symbol to be properly displayed here, but this is how it looks: http://i.imgur.com/zuq24gV.png?1 function fancyPrompt { local bgBlue="\[\033[48;5;31m\]" local fgBlue="\[\033[38;5;31m\]" local fgWhite="\[\033[38;5;231m\]" local bgDarkBlue="\[\033[48;5;24m\]" local fgDarkBlue="\[\033[38;5;24m\]" local bgDarkGray="\…

That's quite pretty. How do you get the triangles?

I've been loving a prompt which color codes git branches (which, if I understand right, would be built-in if I used zsh instead of bash) [0], though I have to edit the last line in order to get my history appendation working as well.

0: https://gist.github.com/tobiassjosten/828432

Re: Unix Tricks

#92

Another one: Use dcfldd instead of dd if you want to see how far your dd operation is progressing... dcfldd if=[infile] of=[outfile] sizeprobe=if So. Much. Better. dcfldd also has many other useful options - read the man pages - and note that you'll have to install it from your linux distro's package repo beforehand.

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

Re: Unix Tricks

#93
Ctrl+r is fine when you're looking for something recent, but this one is useful when you're looking through a long list of similar commands.

    alias hist='history  | grep'
Use it like this:

    $ hist git
      9543  git add toto
      9544  git commit
      9545  git log
      9546  git log
      9548  git add -A
      9549  git commit
      9550  git log
      9633  git pull
      9955  cd dev/git
      9957  git grep copyof
      9958  git grep copyof
      9959  git pull
By the way, do you know you can call back the 9633rd command in the history with "!9633"?

Re: Unix Tricks

#94
post #55
post #28

Earlier quoted context omitted.

> You know what else I hate? Typing in long commands in the Mac OS X terminal and then them wrapping weirdly. Yeah, keeping ctrl pressed in and pressing x followed by e (CTRL + x e) will open up the current line in $EDITOR and when you edit and save, replaces the current line with what you entered in your editor. Really a killer feature.

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 :-)

Re: Unix Tricks

#95

Another one: Use dcfldd instead of dd if you want to see how far your dd operation is progressing... dcfldd if=[infile] of=[outfile] sizeprobe=if So. Much. Better. dcfldd also has many other useful options - read the man pages - and note that you'll have to install it from your linux distro's package repo beforehand.

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

Caution: while this works great on Linux, on OSX, a USR1 will kill dd, and a SIGINFO will get you the block counts.

Re: Unix Tricks

#96
post #91

Earlier quoted context omitted.

Mine seems escaped as hell, but still gets wrapped. Anything I'm missing? edit: couldn't get UTF-8 branch symbol to be properly displayed here, but this is how it looks: http://i.imgur.com/zuq24gV.png?1 function fancyPrompt { local bgBlue="\[\033[48;5;31m\]" local fgBlue="\[\033[38;5;31m\]" local fgWhite="\[\033[38;5;231m\]" local bgDarkBlue="\[\033[48;5;24m\]" local fgDarkBlue="\[\033[38;5;24m\]" local bgDarkGray="\…

That's quite pretty. How do you get the triangles? I've been loving a prompt which color codes git branches (which, if I understand right, would be built-in if I used zsh instead of bash) [0], though I have to edit the last line in order to get my history appendation working as well. 0: https://gist.github.com/tobiassjosten/828432

It's Powerline: https://powerline.readthedocs.org/en/latest/introduction.htm...

Re: Unix Tricks

#97

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

Indeed you can :) But I prefer not to have to manually keep sending that ;)

while ; do kill -s USR1 $(pgrep '^dd$'); sleep 5; done

Re: Unix Tricks

#98
post #95

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

Caution: while this works great on Linux, on OSX, a USR1 will kill dd, and a SIGINFO will get you the block counts.

Indeed, looks like GNU coreutils dd responds to SIGUSR1 on linux and SIGINFO on linux. That's good to know. What's the reason for this discrepancy?

Re: Unix Tricks

#99
Along with the !! function you can reference the last call of a specific command like so:

    !
e.g. sometimes I forget the "ln -s" order of arguments (to which it gives me an error), so I follow it up with:

    ln -s !ln:3 !ln:2
Post reply on HN