Day-14 of #90DaysOfDevOps

Linux & Git-GitHub Cheat Sheet for DevOps
This cheat sheet provides a collection of essential Linux, Git, and DevOps-related commands, along with detailed explanations to help streamline your development and DevOps workflows. Whether you're new to Linux, Git, or looking to enhance your knowledge, this guide will serve as a quick reference for your day-to-day tasks.
Linux Commands
Linux commands are vital for navigating, managing files, and performing system tasks efficiently. Below is a breakdown of some of the most frequently used commands:
File and Directory Management
ls
Lists all files and directories in the current directory.lsls -l
Lists files and directories with detailed information, such as file permissions, number of links, owner, group, size, and modification date.ls -lmkdir <directory>
Creates a new directory. Replace<directory>with the name of the directory you want to create.mkdir my_directorycd <directory>
Changes the current working directory to the specified directory.cd my_directorypwd
Prints the working directory, showing the path of the current directory.pwdrm <file>
Removes a specified file.rm file.txtrmdir <directory>
Removes an empty directory.rmdir my_directoryrm -rf <directory>
Forcefully removes a directory and all its contents, including subdirectories and files.rm -rf my_directorycp -r <source> <destination>
Copies files or directories recursively from the source to the destination.cp -r folder1/ folder2/mv <source> <destination>
Moves or renames files and directories.mv file.txt new_file.txttouch <file>
Creates an empty file or updates the timestamp of an existing file.touch file.txt
Viewing and Editing Files
cat <file>
Displays the content of a file.cat file.txtless <file>
Views a file one page at a time, allowing you to scroll through the contents.less file.txthead -n <number> <file>
Displays the first<number>lines of a file.head -n 10 file.txttail -n <number> <file>
Displays the last<number>lines of a file.tail -n 10 file.txtvim <file>
Opens a file in the Vim editor for more advanced text editing.vim file.txtnano <file>
Opens a file in the Nano editor, which is simpler for beginners.nano file.txtecho "text" > <file>
Writes "text" to a file, overwriting any existing content.echo "Hello, World!" > file.txtecho "text" >> <file>
Appends "text" to a file without overwriting existing content.echo "New Line" >> file.txt
Permissions and Execution
chmod <permissions> <file>
Changes the permissions of a file or directory (e.g.,chmod 755 file).chmod 755 file.shchown <owner>:<group> <file>
Changes the owner and group of a file.chown user:group file.txt./<script>
Executes a script or program in the current directory../script.sh
System Monitoring and Information
df -h
Displays disk usage in a human-readable format (e.g., MB, GB).df -hfree -h
Shows memory usage in a human-readable format.free -htop
Displays real-time system processes, including CPU usage and memory consumption.tophtop
A more interactive and user-friendly version oftop. Install it first usingsudo apt install htop.htopuname -a
Shows detailed system information, including kernel version, machine architecture, and OS type.uname -auptime
Displays the current system uptime.uptimewho
Displays who is logged into the system.whosudo journalctl
Views system logs (requires sudo privileges).sudo journalctl
Networking
ping <host>
Checks the connectivity to a specified host.ping google.comcurl <url>
Fetches data from a specified URL.curl https://example.comwget <url>
Downloads files from a specified URL.wget https://example.com/file.zipifconfig
Displays or configures network interfaces.ifconfignetstat -tuln
Displays listening ports and associated services.netstat -tuln
Git Commands
Git is a distributed version control system commonly used in DevOps workflows for code management. Here are some essential Git commands with explanations:
Configuration
git config --global user.name "Your Name"
Sets your global username for Git commits.git config --global user.name "John Doe"git config --global user.email "your.email@example.com"
Sets your global email address for Git commits.git config --global user.email "john.doe@example.com"
Repository Management
git init
Initializes a new Git repository in the current directory.git initgit clone <repository-url>
Clones a remote repository to your local machine.git clone https://github.com/user/repo.gitgit remote add origin <url>
Adds a remote repository to your local Git configuration.git remote add origin https://github.com/user/repo.git
Basic Operations
git status
Displays the current status of your working directory, showing changes to files.git statusgit add <file>
Stages changes to a file for the next commit.git add file.txtgit commit -m "message"
Commits the staged changes with a message describing the changes.git commit -m "Added new feature"git push
Pushes committed changes to a remote repository.git pushgit pull
Fetches and merges changes from a remote repository into your local repository.git pull
Branching and Merging
git branch
Lists all local branches.git branchgit branch <branch-name>
Creates a new branch with the given name.git branch new-branchgit checkout <branch>
Switches to the specified branch.git checkout new-branchgit merge <branch>
Merges the changes from the specified branch into the current branch.git merge new-branch
Conclusion
By mastering these Linux and Git commands, you'll significantly enhance your productivity as a DevOps practitioner. For a more comprehensive understanding of these commands and advanced DevOps practices, keep experimenting with them in real-world scenarios.
For additional resources, check out the GitHub Cheat Sheet.
Visit my LinkedIn Profile
Read more on my GitHub




