251 lines
9.4 KiB
TeX
251 lines
9.4 KiB
TeX
\documentclass[8pt, letter, landscape]{extarticle}
|
|
\usepackage{extsizes}
|
|
\usepackage[
|
|
margin=0.5in,
|
|
top=2cm,
|
|
bottom=2cm
|
|
]{geometry}
|
|
|
|
\usepackage{lmodern}
|
|
|
|
\usepackage[os=win]{menukeys}
|
|
% Using this, but see other solution below
|
|
% This option works better with small font sizes
|
|
|
|
\usepackage{ragged2e} % Make right margin look better
|
|
\raggedright
|
|
|
|
\usepackage{titlesec}
|
|
\titleformat{\section}[display]
|
|
{\large\scshape}{\thesection}{}{\hrule\vspace{3pt}}{}
|
|
|
|
% Define a date the way we like it
|
|
\usepackage[en-AU]{datetime2}
|
|
|
|
\usepackage{enumitem}
|
|
\setlist[description]{
|
|
style=nextline,
|
|
font={\bfseries\ttfamily},
|
|
itemsep=1pt,
|
|
parsep=0pt
|
|
}
|
|
|
|
\usepackage{fancyhdr}
|
|
\pagestyle{fancy}
|
|
\fancyhf{}
|
|
\fancyhead[L]{\textbf{A Linux Cheat Sheet}}
|
|
\fancyhead[R]{\texttt{https://git.kjodle.net/kjodle/linux-cheat-sheet}}
|
|
\fancyfoot[L]{Version 1.0.0 • \today}
|
|
\fancyfoot[R]{Page \thepage}
|
|
|
|
\usepackage{multicol}
|
|
\setlength{\columnseprule}{1pt}
|
|
\setlength{\columnsep}{1cm}
|
|
|
|
\usepackage[T1]{fontenc}
|
|
\usepackage[utf8]{inputenc}
|
|
\usepackage{tikz}
|
|
\usetikzlibrary{shadows}
|
|
|
|
% See https://tex.stackexchange.com/questions/5226/keyboard-font-for-latex
|
|
\newcommand*\keystroke[1]{%
|
|
\tikz[baseline=(key.base)]
|
|
\node[%
|
|
draw,
|
|
fill=white,
|
|
drop shadow={shadow xshift=0.4ex,shadow yshift=-0.2ex,fill=black,opacity=0.35},
|
|
rectangle,
|
|
rounded corners=2pt,
|
|
inner xsep=3pt,
|
|
inner ysep=0.5pt,
|
|
line width=0.5pt,
|
|
font=\footnotesize\ttfamily
|
|
](key) {#1\strut}
|
|
;
|
|
}
|
|
|
|
\begin{document}
|
|
|
|
\begin{multicols*}{4}
|
|
|
|
As always, check the \texttt{man} files for additional options and parameters.
|
|
|
|
\section*{Disk Usage}
|
|
|
|
\begin{description}
|
|
\item[df] Get a report on the system's disk space usage
|
|
\item[du] Check the disk space usage of a file or directory
|
|
\item[du -ah] Show disk usage for all files and directories in human readable sizes
|
|
\item[du -sh] Show disk usage of the current directory
|
|
\item[fdisk -l] Show disk partitions, sizes, and types
|
|
\item[findmnt] Show target mount point for all filesystems
|
|
\end{description}
|
|
|
|
\section*{Files}
|
|
|
|
\begin{description}
|
|
\item[ls] List files in a directory
|
|
\item[ls -R] List all files in all subdirectories
|
|
\item[ls -a] List hidden files
|
|
\item[ls -l] List detailed information in a tabular format
|
|
\item[ls -h] List sizes in human-readable format
|
|
\item[cat] List the contents of a file on \texttt{stdout}
|
|
\item[cat <file>] Create a new file
|
|
\item[cat file1 file2 > file3] Joins two files and stores the output as a new file
|
|
\item[cat <file.txt> | tr a-z A-Z output.txt] Convert a file to upper or lower case
|
|
\item[diff] Compare the contents of two files line by line
|
|
\item[rm] Delete (permanently) a file
|
|
\item[cp] Copy files
|
|
\item[cp file1 file2] Copy the contents of the first file to the second one
|
|
\item[cp -r <directorya> <directory2>] Copy recursively the contents of the first directory into the second directory.
|
|
\item[mv] Move or rename files
|
|
\item[mv file1 file2] Rename a file
|
|
\item[ln -s <path/to/file> <link name>] Create a symbolic link to a file
|
|
\item[touch <newfile>] Create a new file
|
|
\item[touch <oldfile>] Update the modification time of an existing file
|
|
\item[more <file>] Show the contents of a file
|
|
\item[head <file>] Show the first 10 lines of a file
|
|
\item[head -<n> <file>] Show the first \texttt{n} lines of a file
|
|
\item[tail <file>] Show the last 10 lines of a file
|
|
\item[tail -<n> <file>] Show the last \texttt{n} lines of a file
|
|
\item[locate] Search for a file or directory
|
|
\item[find] Locate files within a directory
|
|
\end{description}
|
|
|
|
\section*{Directories}
|
|
|
|
\begin{description}
|
|
\item[cd] Change the current directory
|
|
\item[cd..] Move one directory up
|
|
\item[cd-] Move to your previous directory
|
|
\item[pwd] Show the current directory (relative to \texttt{\$HOME})
|
|
\item[scp <file> <server/file>] Securely copy a specific file to a server directory
|
|
\item[mkdir] Create a new directory
|
|
\item[rmdir] Delete an empty directory
|
|
\item[rsyng -a </path/to/file> </file>] Synchronize the contents of a specific direcotry with a backup directory
|
|
\item[rm -r <directory>] Remove a non-empty directory
|
|
\item[rm -ri <directory>] Remove a non-empty directory recursively, and require confirmation of each item
|
|
\end{description}
|
|
|
|
\section*{Archives}
|
|
|
|
\begin{description}
|
|
\item[tar]Archive multiple files into a common Linux file format (\textbf{Note:} \texttt{tar} files are \textit{not} compressed.)
|
|
\item[tar -xf file.tar] Extract an archived file
|
|
\item[tar -cf file.tar file1.txt file2.txt] Create an archive from one or more files
|
|
\item[tar -czf file.txt file.tar.gz] Create a gzip-compressed file (\textbf{Note:} the file extensions \texttt{.tar.gz} and \texttt{.tgz} are equivalent.)
|
|
\item[gzip file] Compress a file with the \texttt{.gz} extension
|
|
\item[gpg -c <file>] Encrypt a file
|
|
\item[gpg <file>] Decrypt a file
|
|
\item[zip <archive.zip> <file1> <file2>] Compress files into a zip archive
|
|
\item[unzip <archive.zip>] Extract zipped files from a zip archive
|
|
\end{description}
|
|
|
|
\section*{System}
|
|
|
|
\begin{description}
|
|
\item[history] Review previously entered commands
|
|
\item[uname] Print information about your Linux system
|
|
\item[uname -a] Show system and kernel
|
|
\item[head -n1 /etc/issue] Show the current system software
|
|
\item[jobs] Display currently running jobs
|
|
\item[top] Monitor system resource usage
|
|
\item[ps] Show a snapshot of active processes
|
|
\item[kill <pid>] Terminate a process with process id <pid>
|
|
\item[man <command>] Display the manual pages for a given command
|
|
\item[uname -r] Show system information
|
|
\item[timedatectl] Query and change the system clock
|
|
\item[last reboot] Show the system reboot history
|
|
\item[uptime] SHow how long the system has been running, including load average
|
|
\item[echo \$<variable>] Show the value of a variable
|
|
\item[echo \$PATH] Show the current value of the \texttt{\$PATH} variable
|
|
\end{description}
|
|
|
|
\section*{Network}
|
|
|
|
\begin{description}
|
|
\item[hostname] Display the name of your host or network
|
|
\item[ip addr show] Show IP addresses and network interfaces
|
|
\item[ping] Check connectivity to a server
|
|
\item[ifconfig] Show IP addresses of all network interfaces
|
|
\item[netstat -pnltu] Show active ports
|
|
\item[netstat -nutlp] Show more information about a domain
|
|
\item[whois <domain>] Show more information about a domain
|
|
\item[dig <domain>] Show DNS information about a domain
|
|
\item[host <domain>] Do an IP lookup for a domain
|
|
\item[hostname -i] Show the IP address of the system
|
|
\end{description}
|
|
|
|
\section*{Users, Groups, and Permissions}
|
|
|
|
\begin{description}
|
|
\item[id] Show information about the current user
|
|
\item[useradd] Create a new user
|
|
\item[passwrd] Add a password to a user's account
|
|
\item[last] Show last logins
|
|
\item[userdel <user>] Delete a user
|
|
\item[chmod] Change the read, write, and execute permissions of files and directories
|
|
\item[chmod u + x <file>] Give the user execute permissions on a file
|
|
\item[chmod u+rw,go+r <file>] Give read and write permissions to the owner, and read-only permissions to the group and others.
|
|
\item[chmod -R 755 <directory>] Change the permissions of a directory and its files recursively
|
|
\item[chown] Change or transfer file ownership
|
|
\item[chown <user> <file>] Change the ownership of a file to a given user
|
|
\item[chown :<group> <file>] Change the group of a file to a given group (\textbf{Note:} Instead of the group permissions, the user permissions will apply if the owner user is in this group.)
|
|
\item[sudo] Perform tasks as the root user
|
|
\end{description}
|
|
|
|
Permissions are always in the order: owner, group, others.
|
|
|
|
\hspace{1em} Calculate permission digits by adding these numbers:
|
|
\begin{itemize}[noitemsep]
|
|
\item 4 — read (r)
|
|
\item 2 — write (w)
|
|
\item 1 — execute (x)
|
|
\end{itemize}
|
|
|
|
\section*{Pipes and Redirection}
|
|
|
|
\begin{description}
|
|
\item[cmd1 | cmd2] Pipe the \texttt{stdout} of the first command to the second command
|
|
\item[cmd1 |\& cmd2] Pipe the \texttt{stderr} of the first command to the second command
|
|
\item[cmd1 > file.txt] Redirect the \texttt{stdout} of a command to a file
|
|
\item[cmd1 2>error.log] Redirect the \texttt{stderr} of a commmand to a log file
|
|
\end{description}
|
|
|
|
\section*{Command Lists}
|
|
|
|
\begin{description}
|
|
\item[cmd1 ; cmd2] Run \textit{cmd1} and then run \textit{cmd2}
|
|
\item[cmd1 \&\& cmd2] Run \textit{cmd2} if \textit{cmd1} is successful
|
|
\item[cmd1 || cmd2] Run \textit{cmd2} if \textit{cmd1} is not successful
|
|
\end{description}
|
|
|
|
\section*{Keyboard Shortcuts}
|
|
|
|
\begin{description}
|
|
\item[\keys{ctrl + a}] Move to the beginning of a line
|
|
\item[\keys{ctrl + e}] Move to the end of the line
|
|
\item[\keys{ctrl + w}] Cut one word before the cursor and add it to the clipboard
|
|
\item[\keys{ctrl + u}] Cut part of the line before the cursor and add it to the clipboard
|
|
\item[\keys{ctrl + k}] Cut part of the line after the cursor and add it to the clipboard
|
|
\item[\keys{ctrl + y}] Paste from the clipboard
|
|
\item
|
|
\item[\keys{ctrl + z}] Pause the command
|
|
\item[\keys{ctrl + c}] Stop and terminate the current command
|
|
\item
|
|
\item[\keys{ctrl + s}] Freeze the terminal
|
|
\item[\keys{ctrl + q}] Unfreeze the terminal
|
|
\item
|
|
\item[\keys{$uparrow$}] Review the command history
|
|
\item[\keys{ctrl + o}] Run the previously recalled command
|
|
\item[\keys{ctrl + g}] Exit the command history without running a command
|
|
\item[\keys{ctrl + r}] Recall the last command that matches the provided characters
|
|
\item[\keys{Tab}] Autofill typing
|
|
\item[\keys{!}\keys{!}] Repeat the last command
|
|
\item[\keys{alt + /}] Move to the end of the file
|
|
\item[exit] Log out of the current session
|
|
\end{description}
|
|
|
|
\end{multicols*}
|
|
|
|
\end{document} |