The Command Line Crash Course
cli.learncodethehardway.org
cli.learncodethehardway.org
In general I found these 14 commands end up being the smallest number anyone really needs to do basic CLI work, but keep in mind that the goal of the book is to give someone just enough experience to be able to go through my other books. There are plenty of more in-depth books on managing a server, so I don't bother to duplicate their work.
If you really want to learn how to manage servers and work the CLI, then check out "UNIX and Linux System Administration Handbook (4th Edition)" by Evi Nemeth and friends. My recommendation to people is to get a crappy computer you don't want, put OpenBSD on it following their http://www.openbsd.org/faq/faq4.html guide exactly, use the Nemeth book to configure every service you can and then point a security scanner at your box (like Nessus, or whatever they use today).
Once you can setup an OpenBSD box, get services running on them, and secure those services based on known attacks, then you can pretty much do anything. More importantly, OpenBSD is very bare bones so you learn the core of how a Unix system works and how to configure it, but their docs are very thorough and complete so you can do it if you follow them accurately.
Hope that all helps.
What should an advanced user know? Everything provided by coreutils, stuff that goes in /bin etc? Also sed, awk and common tools for simple text processing?
Knowing a little bit about writing valid ksh/bash shell scripts (being at least aware of bash-isms) would certainly be useful for sys adm work.
My opinion is that the full gnu (and/or bsd) userland has grown so large over the years, that saying that you should know it all is probably overkill -- but knowing how to look things up (man, info) is a must.
As Zed's implied -- GNU documentation could stand to be improved vs bsd man pages -- although the info manuals can be quite useful.
However, I will say that learning how to effectively use grep and sed are probably the only big omissions from my list. But, those are outside the scope of this little book given those commands have whole books devoted to them.
Crash Course on Common Commands @ http://sysadmincasts.com/episodes/13-crash-course-on-common-...
Crash Course on the Filesystem Hierarchy Standard @ http://sysadmincasts.com/episodes/12-crash-course-on-the-fil...
Crash Course on Man Pages @ http://sysadmincasts.com/episodes/19-crash-course-on-man-pag...
ps. there are many great HN threads about UNIX commands, here are just a few:
https://news.ycombinator.com/item?id=6360320
https://news.ycombinator.com/item?id=6046682
I was reminded, by this comment:
https://news.ycombinator.com/item?id=7036920
by danso in this thread (who talked about cp and mv), that I learned, from the K&P book (IIRC), that the commands cp, mv and ln were actually all links to the same executable, which did the right thing based on what name it was invoked by, as found from looking at argv[0]. Checked just now in Linux with:
cd /usr/bin ls -li cp mv ln
on SuSE Linux, but they seem to be different files now ...
The -i option to ls shows the inode number.
I actually tend to do a switch on the first argument for certain shell scripts, such as this little thing for switching between single display on a couple of laptops/netbooks:
#!/usr/bin/env sh
INTERNAL=LVDS
EXTERNAL=VGA-0
for monitor in `xrandr|grep connected|awk '{ print $1 }'`
do
case "${monitor}" in
"LVDS")
INTERNAL="LVDS"
;;
"DFP1")
EXTERNAL="DFP1"
;;
"CRT1")
EXTERNAL="CRT1"
;;
"VGA-0")
EXTERNAL="VGA-0"
;;
esac
done
twoscreen()
{
xrandr --output ${EXTERNAL} --auto --rotate normal --pos 0x0 \
--output ${INTERNAL} --auto --rotate normal --pos 768x1152
}
vgaonly()
{
xrandr --output ${EXTERNAL} --auto --rotate normal --pos 0x0 \
--output ${INTERNAL} --off
}
laptoponly()
{
xrandr --output ${INTERNAL} --auto --rotate normal --pos 0x0 --output ${EXTERNAL} --off
}
fn=`basename "$0"`
case $fn in
"twoscreens")
twoscreen
;;
"onescreen")
laptoponly
;;
"vgaonly")
vgaonly
;;
*)
echo "Usage: vgaonly|onescreen|twoscreen"
echo "called as: $0 ($fn)"
;;
esac
As a side note, for those running Debian (or Ubunut, I think) there's a couple of utilities to help search for binaries/files -- namely apt-file and dlocate. Eg: apt-file search -F bin/cp #returns coreutils
# -F does a fixed string search, otherwise you'll
# get a list of all packages which contains files
# that *contain* bin/cp in their name such as:
# passwd: /usr/sbin/cpgr
Dlocate works with regular expressions and an index, so it's much faster and you can do: $ dlocate bin/cp\$
coreutils: /bin/cpDon't want or need it, just mentioned it as an interesting bit of Unix history. I guess the 3 files are not links but separate files nowadays due to much cheaper and more plentiful disk space compared to those days.
Your script is interesting.
Didn't know about apt-file or dlocate, good to know, thanks.
>Ubunut
Sort of Freudian slip? Just kidding :)
http://www.amazon.com/The-Linux-Command-Line-Introduction/dp...
http://shop.oreilly.com/product/9781593273897.do#PowerReview
Mine is the 2nd review from the top, currently; the one titled "A useful book for beginners to Linux".
What do people think of the shortness of the chapters? That is, having hem cover one command each? I would lean toward combining similar concepts, such as cp and mv, so that the higher-level capabilities, the ones that make the shell uniquely more powerful than the GUI (such as piping), stand out more...but maybe it's better to have things one at a time?
i.e.:
cd /var/log
cd /etc/ssh
cd /home/samstave/Downloads
cd -- (takes me back to /var/log/)
pushd /var/log
pushd /etc/ssh
pushd /home/samstave/Downloads
popd;
!! (takes me back to /var/log/)
You could alias cd to pushd and cd- to popd...Something like:
mkdir foo -go and mv foo ~/bar -go
... Probably simple enough to script, but I guess I'm too lazy at the moment.
Or, you could just
bash$ mkdir -p /some/dir/to/make
bash$ cd !$
Bang (!) is a history lookup with lots of variation in use. It probably works in other *nix shells too.Look under "event designators" in "man bash" for more info.
$ mkdir foo
$ cd !$
Not quite what you're asking for but it can certainly save some keystrokes -- especially if you're doing something like: $ mkdir -p foo/bar/baz/whatever # mkdir, cd into it
mkcd () {
mkdir -p "$*"
cd "$*"
}
Just copy and paste that at the end of your `.bashrc` or `.zshrc` file. You may also want to include this comment above it so you know why it’s written like that: # from http://onethingwell.org/post/586977440/mkcd-improvedmkdir some/long/path/to/a/dir cd $_
mv foo some/long/path/bar cd $_
both work for what you want, and the extra keystrokes are so few that it hardly matters. The $_ is not specific to those two commands, so works for others as well, and is typically very useful because command sequences often tend to need the last argument of the previous command in the next command; un-tar-ing a .tar file and then going to the extracted directory is another example.
up () {
if [[ $# -eq 1 && "$1" -gt 0 ]] ; then
local i d
for (( i = 0; i < $1; i++ )) ; do d="../$d" ; done
cd $d
else
echo "Usage: up N"
fi
}Looks like I wrote the tab-completion script on my work machine. I don't have access to it right now, but if I remember when I do have access I'll pastebin that as well.
Note it's the only tab completion script I've written, and it's probably a hack :P
cd .. # to go one level up
cd ... # to go two levels up (note: 3 dots, not 4, makes sense when you think of "cd ." and "cd ..")
# and so on.
I'm actually glad it's set up that way. I assume the paid version is more streamlined. I can't get too upset that I have to hit an extra button to access free content.
(I don't recall the exact tutorial or if it is representable of such tutorials in general.)