Saturday, December 1, 2012

Linux Basics

I thought I knew something about Linux. All confident in my knowledge. But I didn't know Jack - still don't. But as I was reading the LPIC (Linux Professional Institute Certification) Study Guide I learned a lot. A LOT! Holy moly that book kicks ass. Now I just want to share a little of what I learned.

I'm still in the first chapter - where they're going over some of the command line tools. They go over cat, tac, less and more, expand and much more. Just the bash history tricks alone were worth the read.

Some of the things I didn't know: Ctrl-R  brings up a reverse search of bash history. While editing a line in bash history Ctrl-K deletes all text to the end of the line and Ctrl-X and Backspace deletes to the beginning of the line. Arguably the coolest command I came across was Ctrl-X Ctrl-E which edits the line in your editor (in my case it's vim). Cool, right!

The book describes pipes, streams and redirection, then goes on with introductions to cat, tac, head, tail, join, paste, expand, unexpand, od, sort, split, tr, uniq, fmt, tr, pr, nl, tee, more, less, wc and cut. They are just getting ready to finish off the first chapter with regular expressions using grep and sed. What a great book. Yeah, man is good and all, but man pages seem to be written for people who write man pages, not regular people. This LPIC book is written for regular people - or people like me, at least.

I think I'm going to read it again. So far, it's yielded this command: ps auxx | grep -i "$1"|grep -v 'grep\|find'| tr -s ' ' | cut -d ' ' -f 2 which I named findPID, made executable (chmod +x findPID) and stuck in my ~/bin directory (which btw is already in my $PATH). I wrote this because I was going to change my watch-emerge script to quit when emerge was done. If I know the PID of emerge - which is the end product of 'findPID emerge' - I can do: tail --pid=`ps auxx| grep -i emerge | grep -v 'grep\|watch' | tr -s ' ' | cut -d ' ' -f 2` -f /var/log/emerge.log. That's the best, most complicated command I've ever written.

And one more command that I'll write here, just so it sticks in my head a little better. You can do $cat > file.txt to send standard input to file.txt. What used to be the DOS copy con command. I'm glad I found that book.

No comments:

Post a Comment