WebsiteTemplate/cheatsheets/linux.html
2026-01-25 11:33:37 -04:00

568 lines
14 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self'; font-src 'self' data:; img-src 'self' data:; connect-src 'self'; base-uri 'self'; form-action 'self' https://defcon.social https://bsky.app;">
<meta http-equiv="X-Content-Type-Options" content="nosniff">
<link rel="stylesheet" href="../assets/css/style.css">
<link rel="icon" type="image/x-icon" href="../favicon.ico">
<script>
// Apply theme immediately to prevent flash
(function() {
const theme = localStorage.getItem('theme') ||
(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
document.documentElement.setAttribute('data-theme', theme);
})();
</script>
<title>linux terminal commands Cheatsheet - Cheatsheets - Launch Pad</title>
</head>
<body>
<button class="theme-toggle" id="themeToggle" aria-label="Toggle dark mode">
<svg class="theme-icon theme-icon-moon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path></svg>
<svg class="theme-icon theme-icon-sun" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display: none;"><circle cx="12" cy="12" r="5"></circle><line x1="12" y1="1" x2="12" y2="3"></line><line x1="12" y1="21" x2="12" y2="23"></line><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line><line x1="1" y1="12" x2="3" y2="12"></line><line x1="21" y1="12" x2="23" y2="12"></line><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line></svg>
</button>
<br/><br/>
<div class="name">
__ _______________________ _________._________________________
\_ _____/ \______ \ / _ \ / _____/ / _____/ | | \_ _____/
| __) | _/ / /_\ \ / \ ___ / \ ___ | | | __)_
| \ | | \ / | \ \ \_\ \ \ \_\ \ | |___ | \
\___ / |____|_ / \____|__ / \______ / \______ / |_______ \ /_______ /
\/ \/ \/ \/ \/ \/ \/
</div>
<div class="blog-page-header">
<div class="blog-header-content">
<a href="/cheatsheets" class="back-link" title="Back to Cheatsheets">
<svg xmlns="http://www.w3.org/2000/svg" width="42" height="42" viewBox="0 0 24 24" class="home-icon"><path fill="currentColor" d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/></svg>
</a>
<h1 class="blog-page-title">linux terminal commands Cheatsheet</h1>
</div>
</div>
<div class="blog-post-container">
<div class="blog-posts-container" style="max-width: 900px; margin: 0 auto;">
<div class="blog-post">
<div class="blog-post-content">
<p><a href="index.html">← Back to cheatsheets</a></p>
<p><a href="../index.html">← Home</a></p>
<hr>
<p>Essential Linux terminal commands and shell shortcuts.</p>
<hr>
<h2>File and Directory Operations</h2>
<ul>
<li>ls - List files</li>
</ul>
<ul>
<li>ls -l - List files (long format)</li>
</ul>
<ul>
<li>ls -a - List all files (including hidden)</li>
</ul>
<ul>
<li>ls -lah - List all files with details</li>
</ul>
<ul>
<li>cd &lt;dir&gt; - Change directory</li>
</ul>
<ul>
<li>cd .. - Go to parent directory</li>
</ul>
<ul>
<li>cd ~ - Go to home directory</li>
</ul>
<ul>
<li>cd - - Go to previous directory</li>
</ul>
<ul>
<li>pwd - Print working directory</li>
</ul>
<ul>
<li>mkdir &lt;dir&gt; - Create directory</li>
</ul>
<ul>
<li>mkdir -p &lt;dir&gt; - Create directory (with parents)</li>
</ul>
<ul>
<li>rmdir &lt;dir&gt; - Remove empty directory</li>
</ul>
<ul>
<li>rm &lt;file&gt; - Remove file</li>
</ul>
<ul>
<li>rm -r &lt;dir&gt; - Remove directory recursively</li>
</ul>
<ul>
<li>rm -rf &lt;dir&gt; - Remove directory (force)</li>
</ul>
<ul>
<li>cp &lt;source&gt; &lt;dest&gt; - Copy file</li>
</ul>
<ul>
<li>cp -r &lt;source&gt; &lt;dest&gt; - Copy directory</li>
</ul>
<ul>
<li>mv &lt;source&gt; &lt;dest&gt; - Move or rename file</li>
</ul>
<ul>
<li>touch &lt;file&gt; - Create empty file or update timestamp</li>
</ul>
<hr>
<h2>File Permissions and Ownership</h2>
<ul>
<li>chmod &lt;mode&gt; &lt;file&gt; - Change file permissions</li>
</ul>
<ul>
<li>chmod +x &lt;file&gt; - Make file executable</li>
</ul>
<ul>
<li>chmod 755 &lt;file&gt; - Set permissions (rwxr-xr-x)</li>
</ul>
<ul>
<li>chmod 644 &lt;file&gt; - Set permissions (rw-r--r--)</li>
</ul>
<ul>
<li>chown &lt;user&gt;:&lt;group&gt; &lt;file&gt; - Change ownership</li>
</ul>
<ul>
<li>chown -R &lt;user&gt;:&lt;group&gt; &lt;dir&gt; - Change ownership recursively</li>
</ul>
<ul>
<li>sudo &lt;command&gt; - Execute command as root</li>
</ul>
<ul>
<li>sudo su - - Switch to root user</li>
</ul>
<hr>
<h2>User and Group Management</h2>
<h3>User Commands</h3>
<ul>
<li>useradd &lt;user&gt; - Create new user</li>
</ul>
<ul>
<li>useradd -m &lt;user&gt; - Create user with home directory</li>
</ul>
<ul>
<li>useradd -G &lt;group&gt; &lt;user&gt; - Create user with additional group</li>
</ul>
<ul>
<li>usermod -aG &lt;group&gt; &lt;user&gt; - Add user to group</li>
</ul>
<ul>
<li>usermod -L &lt;user&gt; - Lock user account</li>
</ul>
<ul>
<li>usermod -U &lt;user&gt; - Unlock user account</li>
</ul>
<ul>
<li>userdel &lt;user&gt; - Delete user</li>
</ul>
<ul>
<li>userdel -r &lt;user&gt; - Delete user and home directory</li>
</ul>
<ul>
<li>passwd &lt;user&gt; - Change password for user</li>
</ul>
<ul>
<li>passwd - Change your own password</li>
</ul>
<ul>
<li>passwd -l &lt;user&gt; - Lock password (prevent login)</li>
</ul>
<ul>
<li>passwd -u &lt;user&gt; - Unlock password</li>
</ul>
<ul>
<li>passwd -e &lt;user&gt; - Force password expiration</li>
</ul>
<ul>
<li>chage -l &lt;user&gt; - List password aging info</li>
</ul>
<ul>
<li>id &lt;user&gt; - Show user ID and groups</li>
</ul>
<ul>
<li>whoami - Show current username</li>
</ul>
<ul>
<li>who - Show logged in users</li>
</ul>
<ul>
<li>w - Show logged in users and what they&#39;re doing</li>
</ul>
<h3>Group Commands</h3>
<ul>
<li>groupadd &lt;group&gt; - Create new group</li>
</ul>
<ul>
<li>groupdel &lt;group&gt; - Delete group</li>
</ul>
<ul>
<li>groupmod -n &lt;newname&gt; &lt;oldname&gt; - Rename group</li>
</ul>
<ul>
<li>groups - Show groups for current user</li>
</ul>
<ul>
<li>groups &lt;user&gt; - Show groups for user</li>
</ul>
<ul>
<li>gpasswd -a &lt;user&gt; &lt;group&gt; - Add user to group</li>
</ul>
<ul>
<li>gpasswd -d &lt;user&gt; &lt;group&gt; - Remove user from group</li>
</ul>
<ul>
<li>getent group &lt;group&gt; - Show group information</li>
</ul>
<h3>Sudo Commands</h3>
<ul>
<li>sudo -u &lt;user&gt; &lt;command&gt; - Run command as another user</li>
</ul>
<ul>
<li>sudo -s - Start shell as root</li>
</ul>
<ul>
<li>sudo su - &lt;user&gt; - Switch to another user</li>
</ul>
<ul>
<li>visudo - Edit sudoers file safely</li>
</ul>
<hr>
<h2>Text Processing</h2>
<ul>
<li>cat &lt;file&gt; - Display file contents</li>
</ul>
<ul>
<li>less &lt;file&gt; - View file (scrollable)</li>
</ul>
<ul>
<li>more &lt;file&gt; - View file (page by page)</li>
</ul>
<ul>
<li>head &lt;file&gt; - Show first lines</li>
</ul>
<ul>
<li>tail &lt;file&gt; - Show last lines</li>
</ul>
<ul>
<li>tail -f &lt;file&gt; - Follow file (watch updates)</li>
</ul>
<ul>
<li>grep &lt;pattern&gt; &lt;file&gt; - Search for pattern</li>
</ul>
<ul>
<li>grep -r &lt;pattern&gt; &lt;dir&gt; - Search recursively</li>
</ul>
<ul>
<li>grep -i &lt;pattern&gt; &lt;file&gt; - Case insensitive search</li>
</ul>
<ul>
<li>sed &#39;s/old/new/g&#39; &lt;file&gt; - Replace text</li>
</ul>
<ul>
<li>awk &#39;{print $1}&#39; &lt;file&gt; - Print first column</li>
</ul>
<ul>
<li>wc &lt;file&gt; - Count lines, words, characters</li>
</ul>
<ul>
<li>wc -l &lt;file&gt; - Count lines</li>
</ul>
<ul>
<li>sort &lt;file&gt; - Sort lines</li>
</ul>
<ul>
<li>uniq &lt;file&gt; - Remove duplicate lines</li>
</ul>
<ul>
<li>cut -d: -f1 &lt;file&gt; - Cut by delimiter</li>
</ul>
<hr>
<h2>Process Management</h2>
<ul>
<li>ps - List processes</li>
</ul>
<ul>
<li>ps aux - List all processes</li>
</ul>
<ul>
<li>top - Show running processes (interactive)</li>
</ul>
<ul>
<li>htop - Enhanced process viewer</li>
</ul>
<ul>
<li>kill &lt;pid&gt; - Kill process</li>
</ul>
<ul>
<li>kill -9 &lt;pid&gt; - Force kill process</li>
</ul>
<ul>
<li>killall &lt;name&gt; - Kill all processes by name</li>
</ul>
<ul>
<li>pkill &lt;name&gt; - Kill processes by name</li>
</ul>
<ul>
<li>jobs - List background jobs</li>
</ul>
<ul>
<li>fg - Bring job to foreground</li>
</ul>
<ul>
<li>bg - Send job to background</li>
</ul>
<ul>
<li>nohup &lt;command&gt; - Run command immune to hangups</li>
</ul>
<hr>
<h2>System Information</h2>
<ul>
<li>df - Show disk space</li>
</ul>
<ul>
<li>df -h - Show disk space (human readable)</li>
</ul>
<ul>
<li>du - Show directory size</li>
</ul>
<ul>
<li>du -h - Show directory size (human readable)</li>
</ul>
<ul>
<li>free - Show memory usage</li>
</ul>
<ul>
<li>free -h - Show memory usage (human readable)</li>
</ul>
<ul>
<li>uname -a - Show system information</li>
</ul>
<ul>
<li>uptime - Show uptime</li>
</ul>
<ul>
<li>whoami - Show current user</li>
</ul>
<ul>
<li>id - Show user and group IDs</li>
</ul>
<ul>
<li>hostname - Show hostname</li>
</ul>
<ul>
<li>date - Show date and time</li>
</ul>
<hr>
<h2>Archiving and Compression</h2>
<ul>
<li>tar -cf &lt;archive.tar&gt; &lt;files&gt; - Create tar archive</li>
</ul>
<ul>
<li>tar -xf &lt;archive.tar&gt; - Extract tar archive</li>
</ul>
<ul>
<li>tar -czf &lt;archive.tar.gz&gt; &lt;files&gt; - Create gzipped tar</li>
</ul>
<ul>
<li>tar -xzf &lt;archive.tar.gz&gt; - Extract gzipped tar</li>
</ul>
<ul>
<li>gzip &lt;file&gt; - Compress file</li>
</ul>
<ul>
<li>gunzip &lt;file.gz&gt; - Decompress file</li>
</ul>
<ul>
<li>zip &lt;archive.zip&gt; &lt;files&gt; - Create zip archive</li>
</ul>
<ul>
<li>unzip &lt;archive.zip&gt; - Extract zip archive</li>
</ul>
<hr>
<h2>Network Operations</h2>
<ul>
<li>ping &lt;host&gt; - Ping host</li>
</ul>
<ul>
<li>wget &lt;url&gt; - Download file</li>
</ul>
<ul>
<li>curl &lt;url&gt; - Download file or fetch URL</li>
</ul>
<ul>
<li>ssh &lt;user&gt;@&lt;host&gt; - Connect via SSH</li>
</ul>
<ul>
<li>scp &lt;file&gt; &lt;user&gt;@&lt;host&gt;:&lt;path&gt; - Copy file via SSH</li>
</ul>
<ul>
<li>rsync -av &lt;source&gt; &lt;dest&gt; - Sync files</li>
</ul>
<ul>
<li>netstat - Show network connections</li>
</ul>
<ul>
<li>ifconfig - Show network interfaces</li>
</ul>
<ul>
<li>ip addr - Show IP addresses</li>
</ul>
<hr>
<h2>Shell Shortcuts</h2>
<ul>
<li>Ctrl+A - Move to beginning of line</li>
</ul>
<ul>
<li>Ctrl+E - Move to end of line</li>
</ul>
<ul>
<li>Ctrl+U - Delete from cursor to beginning of line</li>
</ul>
<ul>
<li>Ctrl+K - Delete from cursor to end of line</li>
</ul>
<ul>
<li>Ctrl+W - Delete word before cursor</li>
</ul>
<ul>
<li>Ctrl+R - Reverse search history</li>
</ul>
<ul>
<li>Ctrl+C - Cancel/terminate command</li>
</ul>
<ul>
<li>Ctrl+D - Exit shell or delete character</li>
</ul>
<ul>
<li>Ctrl+L - Clear screen</li>
</ul>
<ul>
<li>Ctrl+Z - Suspend process</li>
</ul>
<ul>
<li>Alt+F - Move forward one word</li>
</ul>
<ul>
<li>Alt+B - Move backward one word</li>
</ul>
<ul>
<li>!! - Repeat last command</li>
</ul>
<ul>
<li>!&lt;n&gt; - Repeat command number n from history</li>
</ul>
<ul>
<li>!&lt;string&gt; - Repeat last command starting with string</li>
</ul>
<hr>
<h2>Redirection and Pipes</h2>
<ul>
<li>&lt;command&gt; &gt; &lt;file&gt; - Redirect output to file (overwrite)</li>
</ul>
<ul>
<li>&lt;command&gt; &gt;&gt; &lt;file&gt; - Redirect output to file (append)</li>
</ul>
<ul>
<li>&lt;command&gt; &lt; &lt;file&gt; - Redirect input from file</li>
</ul>
<ul>
<li>&lt;command&gt; 2&gt; &lt;file&gt; - Redirect stderr to file</li>
</ul>
<ul>
<li>&lt;command&gt; | &lt;command&gt; - Pipe output to another command</li>
</ul>
<ul>
<li>&lt;command&gt; &amp; - Run command in background</li>
</ul>
<ul>
<li>&lt;command1&gt; &amp;&amp; &lt;command2&gt; - Run command2 if command1 succeeds</li>
</ul>
<ul>
<li>&lt;command1&gt; || &lt;command2&gt; - Run command2 if command1 fails</li>
</ul>
<hr>
<h2>Configuration</h2>
<h3>Config File Locations</h3>
<ul>
<li>~/.bashrc - Bash configuration</li>
</ul>
<ul>
<li>~/.zshrc - Zsh configuration</li>
</ul>
<ul>
<li>~/.config/fish/config.fish - Fish shell configuration</li>
</ul>
<ul>
<li>~/.profile - Shell profile (all shells)</li>
</ul>
<ul>
<li>~/.bash_profile - Bash profile</li>
</ul>
<h3>Example Aliases</h3>
<p>Add to your shell config:</p>
<pre><code># File operations
alias ll=&#x27;ls -lah&#x27;
alias la=&#x27;ls -A&#x27;
alias l=&#x27;ls -CF&#x27;
alias ..=&#x27;cd ..&#x27;
alias ...=&#x27;cd ../..&#x27;
# Git shortcuts
alias gs=&#x27;git status&#x27;
alias ga=&#x27;git add&#x27;
alias gc=&#x27;git commit&#x27;
alias gp=&#x27;git push&#x27;
alias gl=&#x27;git pull&#x27;
# System
alias df=&#x27;df -h&#x27;
alias du=&#x27;du -h&#x27;
alias free=&#x27;free -h&#x27;
# Editor
export EDITOR=nvim
export VISUAL=nvim</code></pre>
<hr>
<h2>Tips</h2>
<ul>
<li>Use tab completion for file names and commands</li>
</ul>
<ul>
<li>Use man &lt;command&gt; for help pages</li>
</ul>
<ul>
<li>Use &lt;command&gt; --help for command help</li>
</ul>
<ul>
<li>Use history to see command history</li>
</ul>
<ul>
<li>Use pipes to chain commands together</li>
</ul>
<ul>
<li>Use wildcards (*, ?) for pattern matching</li>
</ul>
<ul>
<li>Use quotes for strings with spaces</li>
</ul>
<ul>
<li>Use backticks or $() for command substitution</li>
</ul>
<ul>
<li>Use &amp;&amp; and || for conditional execution</li>
</ul>
<ul>
<li>Use aliases for frequently used commands</li>
</ul>
<hr>
<p><a href="index.html">← Back to cheatsheets</a></p>
<p><a href="../index.html">← Home</a></p>
</div>
</div>
</div>
</div>
<script async type="text/javascript" src="../blog/analytics.js"></script>
<script src="../theme.js"></script>
</body>
</html>