Skip to main content

Command Palette

Search for a command to run...

Linux And Git Cheat Sheet

Day12

Published
5 min readView as Markdown

Linux Cheat Sheet

File and Directory Operations:

  1. ls: List files and directories

    • Usage: ls [options] [path]
  2. pwd: Print working directory

    • Usage: pwd
  3. cd: Change directory

    • Usage: cd [directory]
  4. mkdir: Make directory

    • Usage: mkdir [directory]
  5. rmdir: Remove directory

    • Usage: rmdir [directory]
  6. cp: Copy files and directories

    • Usage: cp [options] source destination
  7. mv: Move/rename files and directories

    • Usage: mv [options] source destination
  8. rm: Remove files and directories

    • Usage: rm [options] file/directory
  9. touch: Create an empty file

    • Usage: touch [file]
  10. cat: Concatenate and display file content

    • Usage: cat [file]
  11. Text editors:

    • nano: Usage: nano [file]

    • vim: Usage: vim [file]

File Viewing and Manipulation:

  1. head: Display the beginning of a file

    • Usage: head [options] [file]
  2. tail: Display the end of a file

    • Usage: tail [options] [file]
  3. less: View file content interactively

    • Usage: less [file]
  4. grep: Search for a pattern in files

    • Usage: grep [options] 'pattern' [file(s)]
  5. find: Search for files and directories

    • Usage: find [path] [expression]
  6. wc: Count lines, words, and characters in a file

    • Usage: wc [options] [file]
  7. sort: Sort lines in a file

    • Usage: sort [options] [file]
  8. cut: Remove sections from each line of a file

    • Usage: cut [options] [file]
  9. sed: Stream editor for text transformation

    • Usage: sed [options] 'command' [file]
  10. awk: Text processing tool

    • Usage: awk 'pattern { action }' [file]

File Permissions:

  1. chmod: Change file permissions

    • Usage: chmod [options] mode [file(s)]
  2. chown: Change file ownership

    • Usage: chown [options] user[:group] [file(s)]
  3. chgrp: Change group ownership

    • Usage: chgrp [options] group [file(s)]

System Information and Monitoring:

  1. uname: Print system information

    • Usage: uname [options]
  2. df: Disk space usage

    • Usage: df [options]
  3. du: Estimate file and directory space usage

    • Usage: du [options] [directory]
  4. free: Display memory usage

    • Usage: free [options]
  5. top: Monitor system processes

    • Usage: top
  6. ps: Display information about running processes

    • Usage: ps [options]
  7. htop: Interactive process viewer (if installed)

    • Usage: htop

Package Management (Debian/Ubuntu):

  1. apt-get: Command-line package handling utility

    • Usage: apt-get [options] command
  2. apt-cache: Query the package cache

    • Usage: apt-cache [options] command

Package Management (Red Hat/Fedora):

  1. yum: Package manager for RPM-based systems

    • Usage: yum [options] [command]
  2. dnf: Next-generation package manager (replacing yum)

    • Usage: dnf [options] [command]
  1. ping: Check connectivity to a host

    • Usage: ping [options] host
  2. Network interface configuration:

    • ifconfig: Usage: ifconfig [interface] [options]

    • ip: Usage: ip [options] [address]

  3. netstat: Network statistics

    • Usage: netstat [options]
  4. ssh: Secure shell client

    • Usage: ssh [options] [user@]hostname
  5. scp: Securely copy files between hosts

    • Usage: scp [options] [source] [destination]
  6. Download files from the web:

    • wget: Usage: wget [options] [URL]

    • curl: Usage: curl [options] [URL]

  7. DNS related queries:

    • nslookup: Usage: nslookup [options] domain

    • dig: Usage: dig [options] domain

Compression and Archiving:

  1. tar: Archive files

    • Usage: tar [options] [archive] [file(s)]
  2. gzip: Compress files

    • Usage: gzip [options] [file]
  3. gunzip: Decompress files

    • Usage: gunzip [options] [file]
  4. zip: Create ZIP files

    • Usage: zip [options] [archive] [file(s)]
  5. unzip: Extract ZIP files

Process Management:

  1. ps: Display information about running processes

    • Usage: ps [options]
  2. kill: Terminate processes

    • Usage: kill [options] PID
  3. Put a process in the background/foreground:

    • bg: Usage: bg

    • fg: Usage: fg

System Shutdown/Reboot:

  1. shutdown: Shutdown or reboot the system

    • Usage: shutdown [options] [time] [message]

Miscellaneous:

  1. date: Display or set the system date and time

    • Usage: date [options] [format]
  2. View command history:

    • history: Usage: history [options]
  3. Create an alias for a command:

    • alias: Usage: alias [name]=[command]
  4. Display manual pages for commands:

    • man: Usage: man [command]

Git Cheat Sheet

Configuration:

  1. git config --global user.name "Your Name": Set your global username.

  2. git config --global user.email "youremail@example.com": Set your global email.

  3. git config --global core.editor "editor": Set your preferred text editor for commit messages.

Creating and Cloning Repositories:

  1. git init: Initialize a new Git repository in the current directory.

  2. git clone <repository_url>: Clone an existing repository from a remote URL.

Basic Operations:

  1. git add <file>: Add a file to the staging area to be included in the next commit.

  2. git add .: Add all modified files to the staging area.

  3. git commit -m "Commit message": Commit the staged changes with a descriptive message.

  4. git status: Show the status of files in the repository (modified, staged, etc.).

  5. git log: View commit history.

  6. git diff: Show the changes made to files but not yet staged.

Branching and Merging:

  1. git branch: List all branches in the repository.

  2. git branch <branch_name>: Create a new branch.

  3. git checkout <branch_name>: Switch to an existing branch.

  4. git checkout -b <branch_name>: Create and switch to a new branch in one command.

  5. git merge <branch_name>: Merge the specified branch into the current branch.

Remote Repositories:

  1. git remote: List remote repositories.

  2. git remote add <name> <url>: Add a remote repository with a custom name.

  3. git push <remote_name> <branch_name>: Push the local branch to the remote repository.

  4. git pull <remote_name> <branch_name>: Fetch and merge changes from a remote repository.

Undoing Changes:

  1. git reset HEAD <file>: Unstage a file from the staging area.

  2. git reset --hard HEAD: Discard all changes and revert to the last commit.

  3. git revert <commit_hash>: Create a new commit that undoes the changes introduced by a specific commit.

Miscellaneous:

  1. git rm <file>: Remove a file from the working directory and staging area.

  2. git stash: Temporarily save changes to a stash, allowing you to switch branches without committing.

  3. git remote -v: Display URLs of remote repositories.

Keep in mind that this is a concise cheat sheet covering some common Git commands. You can always find more information and options for each command in the Git documentation or by running git --help.