Enjoy your Linux journey! ๐Ÿ˜Š๐Ÿงโœจ

Enjoy your Linux journey! ๐Ÿ˜Š๐Ÿงโœจ

Linux Zero to Hero Commands!

Don't be intimidated by the terminal; mastering Linux commands can be an enjoyable and empowering experience! ๐Ÿค“

  1. To view what's written in a file.

     cat file.txt
    
  2. To change the access permissions of files.

     chmod 777 file.txt #owner-group-other has read-write-execute permission
    
  3. To check which commands you have run till now.

     history
    
  4. To remove a directory/ Folder.

     rm -rf file.txt
     rmdir -rf /folder/myfolder
    
  5. To create a fruits.txt file and to view the content.

     vim fruits.txt #create a file
    
  6. Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.

     # After creating file using vim, type 'i' to insert content as - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava
     #save it by ':wq!' 
     cat fruits.txt #see the content of the file
    
  7. To Show only top three fruits from the file.

     head -3 fruits.txt
    
  8. To Show only bottom three fruits from the file.

     tail -3 fruits.txt
    
  9. To create another file Colors.txt and to view the content.

     touch colours.txt
     cat colours.txt
    
  10. Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey.

    vim colours.txt # Red, Pink, White, Black, Blue, Orange, Purple, Grey.
                                    #OR
    echo "Red" >> Colors.txt
    echo "Pink" >> Colors.txt
    
  11. To find the difference between fruits.txt and Colors.txt file.

    diff <fruits.txt> <Colors.txt>
    
  12. Write a Shell Script to take user input, input from arguments and print the variables.

    ########### WRITE A SIMPLE CODE TO TAKE INPUT FROM THE USER & PRINT ##########
    #!/bin/bash
    echo "Hello, who am I talking to?" # Ask the user for their name
    read varname
    echo "It is nice to meet you $varname"
    
  13. Write an Example of If else in Shell Scripting by comparing 2 numbers

    #!/bin/bash
    echo "Enter a number:"
    read num
    
    if [ $num -gt 0 ]; then
        echo "It's a positive number!"
    elif [ $num -lt 0 ]; then
        echo "It's a negative number!"
    else
        echo "It's zero!"
    fi
    
  14. Create 90 directories (day1 .. day 90)within seconds using a simple command

    mkdir day{1..90}
    
  15. Write a bash script createDirectories.sh that when the script is executed with three given arguments (one is directory name and second is start number of directories and third is the end number of directories ) it creates specified number of directories with a dynamic directory name.

    # $1-Day(Directory Name) $2-StartDay $3-EndDay
    #!/bin/bash
    start_day=$2
    end_day=$3
    for (i=start_day;i<=end_day;i++)
    do
    mkdir $1$i
    done
    

    Execute as ./createDirectories.sh day 1 90

    if we run like ./createDirectories.sh Movie 20 50 then it creates 50 directories as Movie20 Movie21 Movie23 ...Movie50

  16. Create a Script to backup all your work done till now. backup.sh

    #!/bin/bash
    src_dir=/home/ubuntu/myprofile/scripts/*.sh
    target_dir=/home/ubuntu/backup
    
    current_time=$(date +"%Y-%m-%d-%H:%M")
    backup_file=$target_dir/$current_time.tgz
    
    echo "Started Backup for $src_dir"
    tar -czf $backup_file --absolute-names $src_dir
    echo "Backup Completed!"
    
  17. Automate the backup Script - Visit https://crontab.guru/

    * 2 0 * * /root/backup.sh #first of every month at 2 am.
    
  18. Create 2 users and just display their Usernames

    sudo useradd user1
    sudo useradd user2
    cat /etc/passwd
    
  19. Create a simple file and see the details of the files

    touch file1.txt
    ls #see the files 
    ls -a # -a show hidden files as well
    
  20. Change the owner of a file from ubuntu to kshitija

    sudo chown kshitija file.txt #Now owner of file.txt is kshitija
    ls -ltr
    
  21. Modify file permission

    sudo chmod 755 file.txt
    ls -ltr
    
  22. ACL commands getfacl and setfacl

    getfacl <file or directory name>
    #To add permission for user -m : modify
    setfacl -m u:kshitija:rwx test/declarations.h
    #To add permissions for a group
    setfacl -m "g:group:permissions" /path/to/file
    #To remove ACL permission of user: -x = remove
    setfacl -x "u:user:permissions" /path/to/file
    #To remove ACL permission of group:
    setfacl -x "g:group:permissions" /path/to/file
    
  23. You have to install docker and jenkins in your system from your terminal using package managers

    #!/bin/bash
    
    #Docker Installetion
    sudo apt update 
    sudo apt  install docker.io -y
    sudo apt install docker-compose -y
    
    #Jenkins Installetion 
    #for jenkins firstly you need java so 
    sudo apt update
    sudo apt install openjdk-11-jre -y
    
    #Jenkins
    curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \
      /usr/share/keyrings/jenkins-keyring.asc > /dev/null
    echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
      https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
      /etc/apt/sources.list.d/jenkins.list > /dev/null
    sudo apt-get update
    sudo apt-get install jenkins -y
    
    #for start jenkins
    sudo systemctl start jenkins
    sudo systemctl enable jenkins
    

    ๐Ÿ“‚ File and Directory Management

    1. ls: List files and directories in the current location.

    2. cd: Change the current directory.

    3. pwd: Print the working directory โ€“ know where you are!

    4. mkdir: Create a new directory.

    5. touch: Create a new file.

    6. cp: Copy files or directories.

    7. mv: Move or rename files or directories.

    8. rm: Remove files or directories (be cautious with this one! ๐Ÿ˜…).

๐ŸŒ Networking Magic

  1. ping: Check network connectivity to a specific server or IP address.

  2. ifconfig: Display network interface configuration (older command; use ip command on newer systems).

  3. ssh: Securely connect to a remote server.

  4. wget: Download files from the web directly in the terminal.

๐Ÿ”ง System Configuration

  1. sudo: Execute a command with superuser (root) privileges.

  2. top: Monitor system processes and resource usage.

  3. apt: Advanced Package Tool - install, update, or remove software packages (Debian-based systems).

  4. yum: Install, update, or remove software packages (Red Hat-based systems).

๐Ÿ›ก๏ธ Security

  1. passwd: Change your user password.

  2. chmod: Change file permissions.

  3. chown: Change file ownership.

๐Ÿ“… Date and Time

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

๐Ÿšฎ Trash Talk

  1. rm (with caution!): Move files to the trash instead of permanently deleting them. Use alias to set up a trash command.

๐ŸŒŸ Bonus Tips

  • Use man followed by a command to access the manual page and learn more about it (e.g., man ls).

  • Combine commands using pipes (|) to create powerful one-liners.

    THANK YOU! :)

ย