568 lines
14 KiB
HTML
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 <dir> - 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 <dir> - Create directory</li>
|
|
</ul>
|
|
<ul>
|
|
<li>mkdir -p <dir> - Create directory (with parents)</li>
|
|
</ul>
|
|
<ul>
|
|
<li>rmdir <dir> - Remove empty directory</li>
|
|
</ul>
|
|
<ul>
|
|
<li>rm <file> - Remove file</li>
|
|
</ul>
|
|
<ul>
|
|
<li>rm -r <dir> - Remove directory recursively</li>
|
|
</ul>
|
|
<ul>
|
|
<li>rm -rf <dir> - Remove directory (force)</li>
|
|
</ul>
|
|
<ul>
|
|
<li>cp <source> <dest> - Copy file</li>
|
|
</ul>
|
|
<ul>
|
|
<li>cp -r <source> <dest> - Copy directory</li>
|
|
</ul>
|
|
<ul>
|
|
<li>mv <source> <dest> - Move or rename file</li>
|
|
</ul>
|
|
<ul>
|
|
<li>touch <file> - Create empty file or update timestamp</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>File Permissions and Ownership</h2>
|
|
<ul>
|
|
<li>chmod <mode> <file> - Change file permissions</li>
|
|
</ul>
|
|
<ul>
|
|
<li>chmod +x <file> - Make file executable</li>
|
|
</ul>
|
|
<ul>
|
|
<li>chmod 755 <file> - Set permissions (rwxr-xr-x)</li>
|
|
</ul>
|
|
<ul>
|
|
<li>chmod 644 <file> - Set permissions (rw-r--r--)</li>
|
|
</ul>
|
|
<ul>
|
|
<li>chown <user>:<group> <file> - Change ownership</li>
|
|
</ul>
|
|
<ul>
|
|
<li>chown -R <user>:<group> <dir> - Change ownership recursively</li>
|
|
</ul>
|
|
<ul>
|
|
<li>sudo <command> - 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 <user> - Create new user</li>
|
|
</ul>
|
|
<ul>
|
|
<li>useradd -m <user> - Create user with home directory</li>
|
|
</ul>
|
|
<ul>
|
|
<li>useradd -G <group> <user> - Create user with additional group</li>
|
|
</ul>
|
|
<ul>
|
|
<li>usermod -aG <group> <user> - Add user to group</li>
|
|
</ul>
|
|
<ul>
|
|
<li>usermod -L <user> - Lock user account</li>
|
|
</ul>
|
|
<ul>
|
|
<li>usermod -U <user> - Unlock user account</li>
|
|
</ul>
|
|
<ul>
|
|
<li>userdel <user> - Delete user</li>
|
|
</ul>
|
|
<ul>
|
|
<li>userdel -r <user> - Delete user and home directory</li>
|
|
</ul>
|
|
<ul>
|
|
<li>passwd <user> - Change password for user</li>
|
|
</ul>
|
|
<ul>
|
|
<li>passwd - Change your own password</li>
|
|
</ul>
|
|
<ul>
|
|
<li>passwd -l <user> - Lock password (prevent login)</li>
|
|
</ul>
|
|
<ul>
|
|
<li>passwd -u <user> - Unlock password</li>
|
|
</ul>
|
|
<ul>
|
|
<li>passwd -e <user> - Force password expiration</li>
|
|
</ul>
|
|
<ul>
|
|
<li>chage -l <user> - List password aging info</li>
|
|
</ul>
|
|
<ul>
|
|
<li>id <user> - 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're doing</li>
|
|
</ul>
|
|
<h3>Group Commands</h3>
|
|
<ul>
|
|
<li>groupadd <group> - Create new group</li>
|
|
</ul>
|
|
<ul>
|
|
<li>groupdel <group> - Delete group</li>
|
|
</ul>
|
|
<ul>
|
|
<li>groupmod -n <newname> <oldname> - Rename group</li>
|
|
</ul>
|
|
<ul>
|
|
<li>groups - Show groups for current user</li>
|
|
</ul>
|
|
<ul>
|
|
<li>groups <user> - Show groups for user</li>
|
|
</ul>
|
|
<ul>
|
|
<li>gpasswd -a <user> <group> - Add user to group</li>
|
|
</ul>
|
|
<ul>
|
|
<li>gpasswd -d <user> <group> - Remove user from group</li>
|
|
</ul>
|
|
<ul>
|
|
<li>getent group <group> - Show group information</li>
|
|
</ul>
|
|
<h3>Sudo Commands</h3>
|
|
<ul>
|
|
<li>sudo -u <user> <command> - Run command as another user</li>
|
|
</ul>
|
|
<ul>
|
|
<li>sudo -s - Start shell as root</li>
|
|
</ul>
|
|
<ul>
|
|
<li>sudo su - <user> - Switch to another user</li>
|
|
</ul>
|
|
<ul>
|
|
<li>visudo - Edit sudoers file safely</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Text Processing</h2>
|
|
<ul>
|
|
<li>cat <file> - Display file contents</li>
|
|
</ul>
|
|
<ul>
|
|
<li>less <file> - View file (scrollable)</li>
|
|
</ul>
|
|
<ul>
|
|
<li>more <file> - View file (page by page)</li>
|
|
</ul>
|
|
<ul>
|
|
<li>head <file> - Show first lines</li>
|
|
</ul>
|
|
<ul>
|
|
<li>tail <file> - Show last lines</li>
|
|
</ul>
|
|
<ul>
|
|
<li>tail -f <file> - Follow file (watch updates)</li>
|
|
</ul>
|
|
<ul>
|
|
<li>grep <pattern> <file> - Search for pattern</li>
|
|
</ul>
|
|
<ul>
|
|
<li>grep -r <pattern> <dir> - Search recursively</li>
|
|
</ul>
|
|
<ul>
|
|
<li>grep -i <pattern> <file> - Case insensitive search</li>
|
|
</ul>
|
|
<ul>
|
|
<li>sed 's/old/new/g' <file> - Replace text</li>
|
|
</ul>
|
|
<ul>
|
|
<li>awk '{print $1}' <file> - Print first column</li>
|
|
</ul>
|
|
<ul>
|
|
<li>wc <file> - Count lines, words, characters</li>
|
|
</ul>
|
|
<ul>
|
|
<li>wc -l <file> - Count lines</li>
|
|
</ul>
|
|
<ul>
|
|
<li>sort <file> - Sort lines</li>
|
|
</ul>
|
|
<ul>
|
|
<li>uniq <file> - Remove duplicate lines</li>
|
|
</ul>
|
|
<ul>
|
|
<li>cut -d: -f1 <file> - 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 <pid> - Kill process</li>
|
|
</ul>
|
|
<ul>
|
|
<li>kill -9 <pid> - Force kill process</li>
|
|
</ul>
|
|
<ul>
|
|
<li>killall <name> - Kill all processes by name</li>
|
|
</ul>
|
|
<ul>
|
|
<li>pkill <name> - 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 <command> - 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 <archive.tar> <files> - Create tar archive</li>
|
|
</ul>
|
|
<ul>
|
|
<li>tar -xf <archive.tar> - Extract tar archive</li>
|
|
</ul>
|
|
<ul>
|
|
<li>tar -czf <archive.tar.gz> <files> - Create gzipped tar</li>
|
|
</ul>
|
|
<ul>
|
|
<li>tar -xzf <archive.tar.gz> - Extract gzipped tar</li>
|
|
</ul>
|
|
<ul>
|
|
<li>gzip <file> - Compress file</li>
|
|
</ul>
|
|
<ul>
|
|
<li>gunzip <file.gz> - Decompress file</li>
|
|
</ul>
|
|
<ul>
|
|
<li>zip <archive.zip> <files> - Create zip archive</li>
|
|
</ul>
|
|
<ul>
|
|
<li>unzip <archive.zip> - Extract zip archive</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Network Operations</h2>
|
|
<ul>
|
|
<li>ping <host> - Ping host</li>
|
|
</ul>
|
|
<ul>
|
|
<li>wget <url> - Download file</li>
|
|
</ul>
|
|
<ul>
|
|
<li>curl <url> - Download file or fetch URL</li>
|
|
</ul>
|
|
<ul>
|
|
<li>ssh <user>@<host> - Connect via SSH</li>
|
|
</ul>
|
|
<ul>
|
|
<li>scp <file> <user>@<host>:<path> - Copy file via SSH</li>
|
|
</ul>
|
|
<ul>
|
|
<li>rsync -av <source> <dest> - 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>!<n> - Repeat command number n from history</li>
|
|
</ul>
|
|
<ul>
|
|
<li>!<string> - Repeat last command starting with string</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Redirection and Pipes</h2>
|
|
<ul>
|
|
<li><command> > <file> - Redirect output to file (overwrite)</li>
|
|
</ul>
|
|
<ul>
|
|
<li><command> >> <file> - Redirect output to file (append)</li>
|
|
</ul>
|
|
<ul>
|
|
<li><command> < <file> - Redirect input from file</li>
|
|
</ul>
|
|
<ul>
|
|
<li><command> 2> <file> - Redirect stderr to file</li>
|
|
</ul>
|
|
<ul>
|
|
<li><command> | <command> - Pipe output to another command</li>
|
|
</ul>
|
|
<ul>
|
|
<li><command> & - Run command in background</li>
|
|
</ul>
|
|
<ul>
|
|
<li><command1> && <command2> - Run command2 if command1 succeeds</li>
|
|
</ul>
|
|
<ul>
|
|
<li><command1> || <command2> - 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='ls -lah'
|
|
alias la='ls -A'
|
|
alias l='ls -CF'
|
|
alias ..='cd ..'
|
|
alias ...='cd ../..'
|
|
|
|
# Git shortcuts
|
|
alias gs='git status'
|
|
alias ga='git add'
|
|
alias gc='git commit'
|
|
alias gp='git push'
|
|
alias gl='git pull'
|
|
|
|
# System
|
|
alias df='df -h'
|
|
alias du='du -h'
|
|
alias free='free -h'
|
|
|
|
# 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 <command> for help pages</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use <command> --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 && 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> |