Tldr
Sharing my reading notes from the book Linux Pocket Guide by Daniel J. Barrett. Check out them for practical takeaways to improve your Linux skills!
Getting help
| Command | Utility |
|---|---|
man wc | |
man -k database | less | Search by keyword |
info ls | |
wc --help | Many Linux commands respond to the option --help |
- If the output is longer than the screen, pipe it into the
lessprogram to display it in pages. - Your friend, the
echocommand:echo My name is $USER.
Linux: A first view
-
Linux has four major parts:
- The kernel
- Supplied programs
- The shell
- X
-
To determine the version of the Linux operating system:
cat /etc/*releaseuname -ahostnamectl
-
In Linux, all files and directories descend from the root (
/). -
There are several ways to locate or refer to your home directory:
cdwith no arguments$HOMEvariable~
| Directory | Description |
|---|---|
| /usr/sbin | Programs (usually binary files) intended to be run by the superuser |
| /etc | Configuration files for the system (and other miscellaneous stuff) |
| /dev | Device files for interfacing with disks and other hardware |
| /var | Files specific to this computer, created and updated as the computer runs |
| /proc | Operating system state |
- Files in
/procare used mostly by programs, but feel free to explore them.cat /proc/version
- To see the ownership and permissions of a directory, add the
-doption.ls -ld mydir-rwxr-x---means a file (-) that can be read (r), written (w), and executed (x) by the owner, read and executed by the group, and not accessed at all by other users.
- To see who’s logged into the computer, type
who. - To change password of current user, type
passwd. - To display hostname of the system, type
hostname. - To list all processes sorted by their current system resource usage, type
top.
Shell features
- Use
typecommand to tell a command is a shell builtin or a program. - Use
exportcommand to make a variable and its value available to other programs. - To run a sequence of commands, but stop execution if any of them fails, separate them with
&&symbols.command1 && command2 && command3
- Single quotes treat their contents literally, while double quotes let shell constructs be evaluated.
- Backquotes cause their contents to be evaluated as a shell command.
- A dollar sign and parentheses are equivalent to backquotes.
- A job is simply the shell’s unit of work.
- Jobs are at a higher level than Linux processes, the Linux operating system knows nothing about them.
- Type
^Zin a shell, while a job is running in the foreground, will suspend that job. It simply stops running, but its state is remembered.- Now you’re ready to type
bgto put the command into the background, orfgto resume it in the foreground. You could also leave it suspended and run other commands.
- Now you’re ready to type
- Type
^Cto kill a command running in the foreground immediately. - Type
^Dto terminate a shell, either run theexitcommand.
who | wc -l
echo $SHELL
PATH=$PATH:/usr/sbin
echo $PATH
type who
export MYVAR=3
printenv HOME
echo This year is `date +%Y`
echo This year is $(date +%Y)
history 10
history -c # Clear (delete) your history
jobs
bg %2File operations
-
Use
lsto list files in a directory.- The
-aoption displays all files - The
-loption produces a long listing - The
-Soption sorts files by their size - The
-toption sorts files by the time they were last modified
- The
-
Use
cpto copy a file.- The
-aor-roption for recursively copying directories
- The
-
Use
catto view files in their entirety. -
Use
lessto view text files one page at a time. -
Use
headto view the first lines of a text file. -
Use
tailto view the last lines of a text file.
find /var/www -name '*.css' # find files by name
grep font /var/www/html/style.css # find files containing text
grep -R font /var/www/html/ # grep recursively for a directory