2025 05 15 Week 1 Session 3 Linux, BASH, git & github TDS May 2025#

2025 05 15 Week 1 Session 3 Linux, BASH, git & github TDS May 2025

Duration: 11038.0Here’s an FAQ-style transcription of the live tutorial:

Q1: I’m seeing “this term is not recognized” when I type bash in my Windows command prompt, or I’m unsure where to type commands when following videos. How do I know where to run these commands?

A1: You’re encountering this because Linux is a separate operating system. This session will clarify how to set up your system to run Linux commands, and by the end, you’ll know exactly where to execute different commands. The main focus will be on Linux setup and then Git.

Q2: Can you clarify the difference between virtualization and dual booting, and how Type 1 and Type 2 hypervisors fit in?

A2: Let’s break it down:

  • Your Normal Computer: This has hardware (CPU, SSD for storage, RAM for memory) with one operating system (like Windows) installed directly, and applications running on top.
  • Virtualization (using a Hypervisor): This is a concept where a single physical computer’s hardware (CPU, SSD, RAM) is used to create multiple independent “virtual machines” (VMs). A “hypervisor” is the software that manages this.
    • Type 1 Hypervisor: This hypervisor runs directly on the hardware, without needing a base operating system. Cloud providers (like AWS) use this. WSL2 (Windows Subsystem for Linux 2) also uses a Type 1 hypervisor called Hyper-V. All VMs running on it have direct access to hardware resources, and they can run simultaneously.
    • Type 2 Hypervisor: This hypervisor runs on top of an existing operating system (e.g., VMware or VirtualBox installed on Windows). It’s less robust because it adds an extra layer of abstraction between the hardware and the VMs, which can impact performance as resources are shared less directly.
    • Key Distinction: Virtualization allows multiple operating systems to run simultaneously, sharing hardware resources concurrently.
  • Dual Booting: This is not virtualization. In dual booting, your SSD is divided into multiple partitions. Each partition holds a separate operating system (e.g., Windows on C: and Ubuntu on D:). When you start your computer, you are presented with a menu to choose which operating system to load. Only one operating system runs at any given time.

Q3: Cloud providers like AWS use Type 1 or Type 2 virtualization?

A3: Cloud providers use Type 1 hypervisors, as they run directly on the server hardware to efficiently manage and provision virtual machines for users.

Q4: How do I set up my Windows system to use WSL2, including enabling virtualization and the necessary Windows features?

A4: You’ll need to follow these steps:

  1. Enable Virtualization in BIOS:
    • Turn off your computer.
    • Power it on and immediately press a specific key repeatedly (often F2, F10, F12, or Del, depending on your manufacturer; for HP, it’s typically F10) to enter the BIOS/UEFI settings.
    • Navigate to a section like “Configuration” or “Advanced” and look for “Virtualization Technology” (or Intel VT-x/AMD-V).
    • Enable this setting. Save changes and exit BIOS.
    • Troubleshooting: If you can’t find this option, your hardware might be too old to support virtualization. In that case, you might be limited to WSL1, which works but can be slower.
  2. Enable Windows Features:
    • Once Windows boots, search for “Features” in the Start menu and select “Turn Windows features on or off”.
    • In the pop-up window, check the boxes for “Virtual Machine Platform” and “Windows Subsystem for Linux”.
    • Click “OK” and restart your computer when prompted.

Q5: What are the fundamental Linux commands for navigating the file system and managing files (creating, reading, editing, deleting)?

A5: In Linux, everything is treated as a file or directory. Here are the core commands:

  • Navigation:
    • ls: List directory contents (like dir in Windows).
    • ls -a: List all files, including hidden ones (starting with a dot, e.g., .bashrc).
    • ls -l: Show a “long listing” format with more details (permissions, owner, size, date).
    • ls -la (or ls -al): Combines -l and -a for detailed listing of all files.
    • pwd: Print Working Directory (shows your current location).
    • cd <directory>: Change Directory.
    • cd .: Stay in the current directory.
    • cd ..: Go up one level to the parent directory.
    • cd /: Go to the “root” directory (the base of the entire file system).
    • cd ~ (tilde): Go to your home directory (e.g., /home/<username>).
  • File/Directory Management:
    • touch <filename>: Create an empty file.
    • mkdir <directoryname>: Make a new directory.
    • cp <source> <destination>: Copy files or directories.
    • mv <source> <destination>: Move or rename files/directories.
    • rm <filename>: Remove (delete) a file.
    • rmdir <directoryname>: Remove an empty directory.
    • rm -r <directoryname>: Remove a directory and its contents recursively (use with caution!).
    • cat <filename>: Display the content of a file.
    • nano <filename>: Open a text editor within the terminal to create or edit a file. Press Ctrl+O to save and Ctrl+X to exit.

Q6: How do I manage file permissions in Linux?

A6: You use the chmod (change mode) command:

  • Permissions are r (read), w (write), x (execute).
  • Each permission has a numerical value: r=4, w=2, x=1.
  • Permissions are set for three types of users: owner, group, and others.
  • To give a file full read, write, and execute permissions to everyone, you’d use chmod 777 <filename> (where 7 = 4+2+1).
  • To simply add executable permission, you can use chmod +x <filename>. This is crucial for running scripts.

Q7: How do I handle arguments when running a script, and what are .bashrc and environment variables?

A7:

  • Argument Passing: In a Python script (.py) or Bash script (.sh), you can access command-line arguments using sys.argv (in Python) or $1, $2, etc. (in Bash).
    • Example (Python): python3 my_script.py 100 7.5 3
    • Example (Bash): ./my_script.sh 100 7.5 3
    • You convert arguments to the correct data type (e.g., int() for numbers) if needed, as they are initially read as strings.
  • .bashrc and Environment Variables:
    • .bashrc is a hidden configuration file in your home directory (~/.bashrc) that is executed every time a new Bash shell starts.
    • Environment Variables: These are dynamic values that affect the behavior of processes on the system. You can define them in .bashrc or directly in the terminal.
    • To make a variable available to child processes (like scripts you run), you must export it. export MY_VAR="hello".
    • In Bash, variables are referenced with a dollar sign: $MY_VAR.
    • Quotes in Bash: Double quotes (") allow variable substitution (e.g., echo "Hello, $NAME"). Single quotes (') treat everything literally, preventing substitution (e.g., echo 'Hello, $NAME').

Q8: How do I set up Git for a project, including generating SSH keys for authentication?

A8:

  1. Initialize Git: Navigate to your project folder in the terminal and run git init to create a local Git repository.
  2. Generate SSH Keys:
    • Run ssh-keygen -t rsa -b 4096 -C "[email protected]" (replace with your email).
    • Press Enter for default file locations and passphrase (you can set a passphrase for extra security). This creates id_rsa (private key) and id_rsa.pub (public key) in your ~/.ssh directory.
  3. Add SSH Key to GitHub/GitLab:
    • Copy the content of your public key: cat ~/.ssh/id_rsa.pub.
    • Go to your GitHub/GitLab account settings -> SSH and GPG keys.
    • Add a new SSH key and paste the copied public key.
  4. Link Local to Remote: On GitHub/GitLab, create a new empty repository. Copy its SSH URL.
    • Back in your terminal, run git remote add origin <SSH_URL>.
  5. Stage and Commit:
    • git add .: Stages all changes in your current directory.
    • git commit -m "Initial commit": Records your changes with a message.
  6. Push to Remote: git push origin master (or main, depending on your remote branch name).
  7. Branching & Merging:
    • git branch <branch_name>: Create a new branch.
    • git checkout <branch_name>: Switch to a branch.
    • git merge <branch_to_merge_into_current>: Merge changes from another branch into your current one.
  8. Tags: git tag -a v1.0 -m "Version 1.0": Create a tag for specific commits (e.g., release versions).

Q9: Can you provide the links to the slides and session recording?

A9: The session recording will be uploaded within 24-48 hours. Please check the IITM BS channel for the “Tools for Data Science” playlist, where you can find all materials. You can also find additional cheat sheets and resources there.