Ask HN: Best Unix Tricks?
71–80 of 107 posts
Re: Ask HN: Best Unix Tricks?
#72Earlier quoted context omitted.
Yes, it is. I recommend remapping the standard C-a to C-z, as C-a acts as "jump to the beginning of line" in couple of shells, Emacs and Emacs clones.
I'm not sure that C-z is a great choice as it's often used for job control. I use C-o myself. I suppose you could always use C-z C-z if you wanted to suspend your current foreground process.
Re: Ask HN: Best Unix Tricks?
#73This is more a general hint than a single tip. Years ago I tried to improve my Unix skills by doing everything at home from the command line -- burning CDs, playing music, copying trees etc. I learnt a lot but this exercise was much less convenient and more mentally demanding than using a gui. Recently I have become much more lazy.
Funny, we're pretty much opposite. I see my 'window manager' as a neccesary evil to run browser and email clients, everything else runs in terminal windows. Of course you could use 'pine' and 'lynx' but that gets old pretty quickly.
Re: Ask HN: Best Unix Tricks?
#74screen is infinitely useful.
Re: Ask HN: Best Unix Tricks?
#75 function bookmark () {
echo -n "Name of bookmark (no spaces): "
read BKNAME
if [ -e ~/.bkmarks/$BKNAME ]
then
echo -n "Overwrite? "
read CONFIRM
if [ "x$CONFIRM" != "xyes" ] && [ "x$CONFIRM" != "xy" ]
then
return 0;
fi
fi
echo -n "Description: "
read DESC
ln -s `pwd` ~/.bkmarks/$BKNAME
echo "`pwd` : $BKNAME : $DESC : `date`" >> ~/.bookmarks
}
function go () {
if [ -x ~/.bkmarks/$1 ]
then pushd ~/.bkmarks/$1; cd `pwd -P`;
else echo "~/.bkmarks/$1 not found";
fi
}Re: Ask HN: Best Unix Tricks?
#76Make sure you read about job control in your shell. It helps understanding the why's and whats of some of the other tricks.
Learn to use pipes. On the cli, I use Bash, sed, awk, and grep a lot, and with pipes you can do amazing things relative to the windows world. It's a very useful skill.
Learn a scripting language. I tend to use perl because I can pipe into it or break into a move involved script, whichever I prefer. I personally find Python less suited for this, but I've heard that Ruby is a good sysadmin language too. You don't have to learn how to be a grand wizard, but any serious unix person should know one. It helps greatly with productivity.
Edit:
Forgot to add, learn find (man find). This, in combo with xargs, is very, very useful.
Re: Ask HN: Best Unix Tricks?
#77 Host home home.example.com
HostName home.example.com
Port 12345
User dryicerx
IdentityFile ~/.ssh/somekey.pem
LocalForward 59001 localhost:5901
Host *amazonaws*
User root
IdentityFile ~/.ssh/yourawskey
now on your command line, and the settings will automatically be applied. ssh home
ssh 1-2-3-4.blah.amazonaws.something.com
I specially love the last one if you are working with EC2, as it catches any EC2 domain name and applies the key with the root user.Re: Ask HN: Best Unix Tricks?
#78Smart history-based autocompletion, advanced tab completion, optional cd, simplified syntax, among other features.
Not as hackerish as some of the other tips mentioned here, but it's a much lower barrier to entry than the other commonly used shells out there.
Also submitted it here: http://news.ycombinator.com/item?id=811113
Re: Ask HN: Best Unix Tricks?
#79 import kremvax /net /net
Plan9 doesn't need natRe: Ask HN: Best Unix Tricks?
#80cd - (Go back to previous working directory) sudo !! (Run the last command as root) :w !sudo tee % (Save a readonly file in VIM) > tmp.file (Empty a file) cmd !$ (Run cmd with previous commands arguments) They are just some of my favorites.
That should be cmd !*. !$ would only be the final argument to the previous command, which you can also insert with alt-. (and pressing alt-. again will cycle through final arguments to earlier commands). Adding :p to the end of a history expansion (like !$:p) will cause it not to be executed, but the expanded command line will be echoed and put in your history so you can check edit it.