Day 12 of #90DaysOfDevOps

Day 12 of #90DaysOfDevOps

Table of contents

Linux Git Cheat Sheet

File System Navigation:

  • sudo - Super User Do. The sudo command allows you to run commands with the superuser privileges.

  • whoami - Displays currently logged-in user.

  • pwd: Print the current working directory.

  • ls: List files and directories in the current directory.

    • ls -l: List files and directories in long format.

    • ls -a: List all files and directories, including hidden ones.

  • cd: Change the current directory.

    • cd ~: Change to the home directory.

    • cd ..: Move up one directory level.

  • touch: Create an empty file.

  • mkdir: Create a new directory.

  • rm: Remove files or directories.

    • rm -r: Remove directories recursively.
  • mv: Move or rename files and directories.

  • cp: Copy files and directories.

  • find: Search for files and directories.

  • grep: Search for text within files.

  • cat: Display the contents of a file.

  • echo - displaying lines of text or string which are passed as arguments on the command line. Can be used to create a file or empty a file.

    echo "Hello" - prints Hello

    echo "Hello" > hello.txt - Creates a file hello.txt with Hello as content in it.

    echo "World" >> hello.txt - appends the content(World) to the file hello.txt

    echo > hello.txt - Empties the content from hello.txt file.

  • stat - Display file or file system status.

  • more or less: View file content page by page.

  • head and tail: Display the beginning or end of a file.

  • sort - The sort command sorts the contents of a file, in numeric or alphabetic order, and prints the results to standard output.

    -h, --human-numeric-sort compare human readable numbers (e.g., 2K 1G)

    -n, --numeric-sort compare according to string numerical value

    -r, --reverse reverse the result of comparisons

  • file: Determine file type.

File Permissions:

  • chmod: Change file permissions.

  • chown: Change file ownership.

  • chgrp: Change group ownership.

  • umask: Set default permissions for new files and directories.

ACL file permissions:

  • getfacl - Get file ACL. This command shows the permission of the file in detailed manner.

  • setfacl- set file permission using ACL.

    setfacl -m u:jack:r-- test.txt

    -m - modify, u-user, jack-username, r---read permission, test.txt- file name

    setfacl -x u:jack:r test.txt

    To remove permission for a file from all the user and groups which were added using ACL.

Process Management:

  • ps: List running processes.

    • ps aux: List all processes.
  • top: Monitor system processes in real-time.

  • kill: Terminate processes.

  • killall: Terminate processes by name.

  • bg and fg: Manage background and foreground processes.

  • nohup: Run a command that continues running even after you log out.

Package Management (Debian/Ubuntu):

  • apt-get update: Update package lists.

  • apt-get upgrade: Upgrade installed packages.

  • apt-get install: Install new packages.

  • apt-get remove: Remove packages.

  • apt-cache search: Search for packages.

  • dpkg: Debian package management commands.

Package Management (Red Hat/CentOS):

  • yum update: Update packages.

  • yum install: Install packages.

  • yum remove: Remove packages.

  • yum search: Search for packages.

  • rpm: RPM package management commands.

Networking:

  • ifconfig or ip: Display network interface information.

  • ping: Check network connectivity.

  • netstat: Network statistics.

  • ssh: Securely access remote systems.

  • scp: Securely copy files between systems.

  • curl or wget: Download files from the internet.

  • nc: Netcat for network-related tasks.

  • iptables or firewalld: Configure firewall rules.

System Information:

  • uname: Display system information.

  • df: Show disk space usage.

  • du: Show directory space usage.

  • free: Display memory usage.

  • top or htop: Monitor system resources.

  • lscpu or cat /proc/cpuinfo: CPU information.

  • lsblk or fdisk -l: List block devices.

  • date: Display the system date and time.

Shell Scripting:

  • Create and edit shell scripts using a text editor like nano, vim, or emacs.

  • Use #!/bin/bash (or another shell) as the shebang line.

  • Make the script executable with chmod +x script.sh.

  • Execute the script with ./script.sh or bash script.sh

Automation (cron):

  • crontab: Schedule recurring tasks.

Text Processing:

  • sed: Stream editor for text manipulation.

  • awk: Text processing tool.

  • cut: Extract sections from lines of files.

Monitoring and Logging:

  • Use tools like syslog, journalctl, and logrotate for system logs.