You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

264 lines
9.8 KiB

\documentclass[8pt, letter, landscape]{extarticle}
% Using this, but see other solution below
% This option works better with small font sizes
\usepackage{ragged2e} % Make right margin look better
% Define a date the way we like it
\fancyhead[L]{\textbf{A Linux Cheat Sheet}}
\fancyfoot[L]{Version 1.0.0 • \today}
\fancyfoot[R]{Page \thepage}
% Redefining headrule
% See
\renewcommand{\headrule}{\hrule height 1pt \vspace{1pt}\hrule height 0.25pt}
% Not currently used; using «menukeys» package instead
% See
drop shadow={shadow xshift=0.4ex,shadow yshift=-0.2ex,fill=black,opacity=0.35},
rounded corners=2pt,
inner xsep=3pt,
inner ysep=0.5pt,
line width=0.5pt,
](key) {#1\strut}
% See for versioning meaning
As always, check the \texttt{man} files for additional options and parameters.
\section*{Disk Usage}
\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
\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
\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[rsync -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
\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 <> <file1> <file2>] Compress files into a zip archive
\item[unzip <>] Extract zipped files from a zip archive
\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
\textbf{Note:} Many of these are not installed by default on most systems.
\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
\section*{Users, Groups, and Permissions}
\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
Permissions are always in the order: owner, group, others.
\hspace{1em} Calculate permission digits by adding these numbers:
\item 4 — read (r)
\item 2 — write (w)
\item 1 — execute (x)
\section*{Pipes and Redirection}
\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
\section*{Command Lists}
\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
\section*{Keyboard Shortcuts}
\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[\keys{ctrl + z}] Pause the command
\item[\keys{ctrl + c}] Stop and terminate the current command
\item[\keys{ctrl + s}] Freeze the terminal
\item[\keys{ctrl + q}] Unfreeze the terminal
\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