by jyap · 7y ago · 0 comments
What I usually do is cat the file to inspect it, hit Control+C, then up arrow for previous command, then further pipe and head/tail/grep the file.
Starting a grep command is fine if you know that's all you're going to be doing.
grep something !$
`!$` will be replaced with the last parameter of the previous command. Crude example cat /etc/hosts
grep 12.34.56.78 $! # will be executed as grep 12.34.56.78 /etc/hosts
I find this extremely useful for when I'm cat'ing a file to get a sense of it's output then wanting to do something more meaningful with it in the next command.That all said, I have absent-mindedly done my fair share of stuff like this too:
!! | less
# eg will run as `cat /etc/hosts | less`
# if `cat /etc/hosts` was the previous command run
so I certainly wouldn't look down on people who have "abused" cat due to muscle memory.That's one of the features I miss the most when using terminals on a Mac.
Or you can check “Profiles → Keyboard → Use Option as Meta” for Terminal.app [or just press ⌥⌘O]. And then use option as meta.
Also, isn't that special variable $_ and not $! ?