diff --git a/linux-cheat-sheet.tex b/linux-cheat-sheet.tex index f244c42..a6360a5 100644 --- a/linux-cheat-sheet.tex +++ b/linux-cheat-sheet.tex @@ -8,15 +8,25 @@ \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=0pt, + itemsep=1pt, parsep=0pt } @@ -25,6 +35,7 @@ \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} @@ -57,18 +68,7 @@ \begin{multicols*}{4} -\section*{Directory} - -\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 ] Securely copy a specific file to a server directory - \item[mkdir] Create a new directory - \item[rmdir] Delete an empty directory - \item[rsyng -a ] Synchronize the contents of a specific direcotry with a backup directory -\end{description} +As always, check the \texttt{man} files for additional options and parameters. \section*{Disk Usage} @@ -81,37 +81,169 @@ \item[findmnt] Show target mount point for all filesystems \end{description} -\section*{File} +\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 ] Create a new file + \item[cat file1 file2 > file3] Joins two files and stores the output as a new file + \item[cat | 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 ] 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 ] Create a symbolic link to a file + \item[touch ] Create a new file + \item[touch ] Update the modification time of an existing file + \item[more ] Show the contents of a file + \item[head ] Show the first 10 lines of a file + \item[head - ] Show the first \texttt{n} lines of a file + \item[tail ] Show the last 10 lines of a file + \item[tail - ] 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 ] Securely copy a specific file to a server directory + \item[mkdir] Create a new directory + \item[rmdir] Delete an empty directory + \item[rsyng -a ] Synchronize the contents of a specific direcotry with a backup directory + \item[rm -r ] Remove a non-empty directory + \item[rm -ri ] 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 ] Encrypt a file + \item[gpg ] Decrypt a file + \item[zip ] Compress files into a zip archive + \item[unzip ] Extract zipped files from a zip archive \end{description} \section*{System} \begin{description} - \item[] + \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 ] Terminate a process with process id + \item[man ] 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 \$] 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[] + \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 ] Show more information about a domain + \item[dig ] Show DNS information about a domain + \item[host ] Do an IP lookup for a domain + \item[hostname -i] Show the IP address of the system \end{description} -\section*{User} +\section*{Users, Groups, and Permissions} \begin{description} - \item[] + \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 ] Delete a user + \item[chmod] Change the read, write, and execute permissions of files and directories + \item[chmod u + x ] Give the user execute permissions on a file + \item[chmod u+rw,go+r ] Give read and write permissions to the owner, and read-only permissions to the group and others. + \item[chmod -R 755 ] Change the permissions of a directory and its files recursively + \item[chown] Change or transfer file ownership + \item[chown ] Change the ownership of a file to a given user + \item[chown : ] 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[\keystroke{ctrl} + \keystroke{e}]Move to the end of the line + \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*}