Ten Steps to Linux Survival
Explore a preview version of Ten Steps to Linux Survival right now.
O’Reilly members get unlimited access to live online training experiences, plus books, videos, and digital content from 200+ publishers.
Book description
Linux systems are everywhere today, even in companies once considered «pure Windows.» If you’re a sysadmin, network administrator, or developer in a small Windows shop, you may have to jump in and fix a system problem when your site goes down. What if you have no Linux knowledge? This short guide provides tips to help you survive.
Linux systems may appear in your shop as virtual machines or in the cloud, including web servers, databases, mobile device managers, version control, and monitoring systems. When one of them falters, this primer leads you through some diagnostic and recovery tasks so you can quickly get your site back up.
- Connect to a Linux system with OpenSSH and PuTTY secure shells
- List files and directories, and move around within the file system
- Safely inspect the file contents without changing them
- Narrow your search by using commands to locate specific files
- Use the grep command to search for error messages inside a file
- Determine real-time system state to find underlying problems
- Examine disk utilization and zero in on space-hogging files
- Transfer suspect files from Linux to Windows for later analysis
- Use commands to start, stop, restart, or even kill unresponsive services
- Know where to find help when troubleshooting isn’t enough
Источник
Ten steps to linux survival
dullroar released this Feb 27, 2016
First «production» release. Incorporates additions after doing four lunch-and-learns based on the content.
dullroar released this Jan 6, 2016
Some minor copy edits before handing it to someone else to edit it.
dullroar released this Jan 1, 2016
Index is «finished» for now, although I can see how indexes are never really finished, you just stop working on them for your sanity. Thanks to Margaret Devere for some insightful advice on the topic.
dullroar released this Dec 29, 2015
The index in the PDF is WAY better, but needs another round. That is coming up next.
dullroar released this Dec 26, 2015
Lots of cleanup in the background, especially around LaTeX output and metadata.
dullroar released this Dec 24, 2015
Shaded backgrounds finally working in the PDF. What a hassle with a lot of false starts and stops.
dullroar released this Dec 22, 2015
Added beamer PDF slides to the existing HTML reveal.js slide output types.
dullroar released this Dec 22, 2015
Another round of reformatting, addition of .mobi output, index in the PDF and trying hard to make it print-ready.
dullroar released this Oct 25, 2015
Correcting a lot of formatting issues, especially around PDFs. Hopefully a generally better layout and fewer «artifacts» as I figure out more about pandoc and getting the various output formats I want, each with their own issues and nuances. Hopefully it looks better.
Источник
Ten steps to linux survival
Most system configuration information is here
Some helpful /etc files
- fstab — file systems currently mounted
- group — security groups
- hosts — network aliases
- init.d — startup and shutdown scripts for «services.»
- mtab — list of current «mounts.»
- passwd — «shadow» file containing all the user accounts
- resolv.conf — DNS settings.
- samba — file sharing settings for CIFS-type shares
May I be of service?
- «Services» (or «daemons») are long-running processes
- Typically controlled via /etc/init.d scripts
- /etc/init.d/samba stop
- /etc/init.d/samba start
- /etc/init.d/samba restart — the above two commands combined
- Most Linux distros have a package manager
- dpkg and apt-get on Debian flavors
- rpm on Fedora flavors
- Package managers are like «Add/Remove Programs» — can install, update or delete applications
- Package managers are like «Windows Update» — can update and upgrade the OS
Package management on Debian
(. and Ubuntu, Mint and others)
- apt-get update — pull down latest package definitions
- apt-get upgrade — upgrade all packages
- apt-get install curl — install package «curl»
- apt-get is an admin command and usually requires sudo
- dpkg -i somesoftware.deb — install a package file downloaded from the web
Which which is which?
- which curl — show which curl will execute
- locate curl — show all files on system with «curl» in the path
- ./curl — regardless of $PATH , execute curl that is in current directory
Over and over and over
- cron — service that runs «cron jobs» (scheduled task)
- crontab — show cron jobs for current user
- crontab -e — edit cron jobs for current user
- sudo crontab -e -u otheruser — edit cron jobs for another user
- reboot — reboot the system (typically requires sudo )
- shutdown -h now — shut down system now
Turn on your signals
- kill — send a signal to a process
- Most «signals» allow process to cleanup
- kill -9 — does NOT allow process to cleanup, may corrupt data
- echo $? — show «return code» or exit code for last command or program
- a && b — execute a and if it is successful execute b
- a || b — execute a and then execute b regardless of a
Источник
Ten steps to linux survival
Copy raw contents
How Do You Know What You Don’t Know, man ?
man , info , apropos , Linux Documentation Project, Debian and Arch guides, StackOverflow and the dangers of searching for “ man find ” or “ man touch ” on the internet.
«You’re soaking in it.» — Palmolive commercial
The biggest issue with bootstrapping into «UNIX» is not the lack of documentation but almost the surplus of it, coupled with a severe «RTFM» attitude by most old-timers toward newbies. Besides the typical «Google» and «StackOverflow» answers, there are actually lots of very reliable places to turn to for information \index
man , is that info apropos ?
There are three commands that are the basis for reading «UNIX» documentation within «UNIX» itself — man , info and apropos . \drdoc
man is short for manual pages, and is used to display the main help for most «UNIX» commands. For example, man ls shows:
Note: man uses less as a paginator, with all that means, including the same navigation and search keys, and most important to remember — Q to quit. How do I know this? Because of course you can man man ! \drtxt
Notice the LS(1) part. The UNIX manual was originally divided into multiple sections by AT&T. Section 1 is normal user commands. Section 5 is file formats (like for config files), and section 8 is for system administration commands. You usually don’t care, and can man ls or man ifconfig to your heart’s content.
But sometimes there are duplicate names in the different sections. For example, there is both a passwd command and a passwd file format (for /etc/passwd ). By default, man passwd will show you the documentation from the lowest numbered section with a match, in this case section 1, usually referred to as passwd(1) to disambiguate which thing we’re talking about: \drsys
\drcap
To see the man page for the passwd file format, we have to explicitly specify the section, in this case by using man 5 passwd :
man pages can be long and sometimes obscure to a beginner, but it is recommended you get used to reading them, especially any warnings. There is a great quote that explains why:
«Unix will give you enough rope to shoot yourself in the foot. If you didn’t think rope would do that, you should have read the man page.» — unknown
Note: If you know who originally said the above and can send proof, let me know and I will give them credit.
Besides man , many GNU tools come with help in info format, which is originally from emacs . Here are the results of info find : \drdoc
While info is much better at enabling complex help files with navigation I am not a fan because I tend not to hold all the keystrokes in my head. The biggest thing to remember if you do something like info find is that q quits the info command.
Finally, what if you don’t know the name of the command? Well, each «man page» has a title and brief description, e.g., «passwd — change user password» in the man passwd output above. The apropos command can simply search those titles and descriptions for a word or phrase and show you all the results: \drdoc
Note the man section numbers after each command name. Also note that apropos is not sophisticated — it is simply searching for the exact string you give it in the very limited «brief descriptions» from the man pages. That’s all. But a lot of time that’s all you need to remember, «Ah, yes, nano is the other editor I was thinking about and like better than vi .»
Note: man , info and apropos are just normal «UNIX» commands like all the others, so while they may default to displaying with a paginator on an interactive terminal, you can run their output through other commands, just like any other. For example, maybe we remember only that the command had something with «edit» and was a system administration («section 8») command:
Or maybe you can’t remember whether it’s -r , -R or —recursive to copy subdirectories recursively with cp : \drfnd
What do you know, it can be any of the three.
And yes, you can man man , man info , info info and info man , for that matter!
How Do You Google, man ?
You can often search the internet for «UNIX» documentation, and the man pages have long been online. A site I like (and link to a lot here) is http://linux.die.net/man/. Often, though, you can just google «man ls» and the top hits will be what you want. \index
However, there are times you need to be careful. Searching the internet for either man touch or man tail , for example, will probably not give you the results you seek and may set off filters at work, so be careful out there and remember to bookmark a couple of actual man page sites so that you can go there directly and look up a command.
Books and Stuff
There are several consistently high-quality free sources of information on various parts of Linux and related systems on the internet.
Arch Linux Wiki — you may not think this would be useful if you are running Debian or Fedora or something else, but remember most «UNIX» systems are all very similar, and often the best documentation on a package or setting something up in Linux is in the Arch wiki. \drdis
Debian documentation — again, even if you are not running a Debian-based distro, this can be handy because it describes how to administer Linux in a way that often transcends distro specifics (and at least explains how Debian approaches the differences). The best books in the series are The Debian Administrator’s Handbook and the Debian Reference, which is a lot more formal attempt at the same type of territory this guide covers. \drdis
Ubuntu, Mint and some other distros have quite active message fora, and of course StackOverflow and its family are also very useful.
Besides the above, if you are dealing with a package that is not part of the «core» OS, such as Samba for setting up CIFS shares on Linux, you should always look at the package site’s documentation as well as any specific info you can find about the distro you are running.
Источник
Ten steps to linux survival
A Series of Pipes
stdin , stdout , stderr
- stdin — input, file descriptor 0
- stdout — output, file descriptor 1
- stderr — «error» output, file descriptor 2
- All three use the console in interactive mode by default
$ ls -l total 1 -rw-rwxr—+ 1 myuser mygroup 13 Oct 22 10:40 hw
$ cat hw Hello, world «>
«Is a directory» is an error message
$ cat /tmp/finderrors.log cat: .: Is a directory cat: ./d: Is a directory «>
This is where those «file descriptors» come in
Logging ALL output to file
$ cat /tmp/find.log cat: .: Is a directory This is a This is b This is c cat: ./d: Is a directory This is e «>
The 2>&1 trick works in CMD.EXE , too!
Rewrite vs. append
Everyone line up
- cat echos all .txt files to stdout , piped to.
- tr translates any backslash characters before sending it into.
- A while loop that reads each line into a variable called $line and then calls.
- Some custom script or program called ./mycmd passing in the value of each $line .
Two places at once
- Log output to error.log
- Monitor its progress on the console at the same time
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Источник