Shell
Updated at
| Basics | Command |
|---|---|
| Diff side to side | diff file1 file2 [-q] (report only if differ), [-y] (side by side) |
| Show permissions | stat <file> (shows detailed file info, including permissions and timestamps) |
| Check group | groups (shows all groups current user belongs to) |
| Show username | whoami (prints the username of the user currently logged in) |
| User info | id (shows user ID and group IDs of current user) |
| Word count | wc [-c] (bytes), [-m] (chars), [-l] (lines), [-w] (words) |
| Determine file type | file <filename> (determines the type of file, e.g., text, binary, etc.) |
| Find files | find <path> [-iname filename] (case-insensitive match for filename) |
| Regex Search | grep -E <pattern> (extended regex) |
| Grep flags | [-h] (no filename), [-n] (line numbers), [-i] (ignore case), [-v] (invert match) |
| Access management | Command |
|---|---|
| Create a user | adduser <username> |
| Grant sudo rights | usermod -aG sudo <username> (append user to the sudo group) |
| Change permissions | chmod [+-=][rwx] file (e.g., chmod +x script.sh to make it executable) |
| Change owner | chown [username][:group] file (change owner and/or group) |
| Generate SSH key | ssh-keygen -t ed25519 [-C "comment"] (optional comment) |
| Install SSH key on host | ssh-copy-id -i ~/.ssh/id_ed25519.pub username@host |
| Disable password login | Edit /etc/ssh/sshd_config: set PasswordAutherntication no |
| Reload SSH service | sudo systemctl reload ssh |
| Check password login | ssh username@host -o PubkeyAuthentication=no |
| Host Management | Command |
|---|---|
| Set new FQDN hostname | sudo hostnamectl set-hostname <hostname> |
| Check FQDN hostname | hostname --fqdn |
| Check DNS domain | dnsdomainname |
| Set timezone | sudo timedatectl set-timezone Europe/Riga |
| Check current logged-in users | w |
| Check login history | last -a |
| Check failed login attempts | lastb -adF |
| Switch to another user | su <user> |
| Show command history | history |
| View service logs | journalctl |
| Process Management | Command |
|---|---|
| Interactive process monitor | htop |
| Process monitor | top |
| View all processes | ps -axu |
| Monitor network bandwidth | iftop |
| Network statistics | netstat -la |
| Storage Management | Command |
|---|---|
| Disk usage visualization | ncdu |
| Disk space usage | df -h |
| Directory size summary | du -hsc * |
| Stream Flow | Syntax |
|---|---|
| Redirect stdout (overwrite, append) | >, >> |
| Redirect stderr (overwrite, append) | 2>, 2>> |
| Redirect out and err | > file 2>&1 |
| Redirect stdin | < |
| Pipe left output to right input | | |
| Drop output | > /dev/null |