You can learn coding through interactive online platforms, structured courses, and project-based programs that teach languages like Python, Java, and JavaScript from beginner to advanced levels.
Python is a versatile programming language used for various applications. Here are some basic examples to get you started.
Hello World Program
The simplest program in Python is printing "Hello, World!".
print("Hello, World!")
Adding Two Numbers
You can add two numbers using the + operator.
a = 5
b = 3
sum = a + b
print("Sum:", sum)
Factorial of a Number
Calculate the factorial of a number using recursion.
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
print(factorial(5)) # Output: 120
Checking Prime Number
Check if a number is prime.
def is_prime(num):
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
print(is_prime(11)) # Output: True
Fibonacci Sequence
Generate Fibonacci sequence up to n terms.
def fibonacci(n):
a, b = 0, 1
for _ in range(n):
print(a, end=" ")
a, b = b, a + b
fibonacci(10) # Output: 0 1 1 2 3 5 8 13 21 34
These examples cover basic concepts like printing output, arithmetic operations, recursion, and loops. Practice these to build a strong foundation in Python programming.
The sudo command (Superuser Do) in Linux allows an authorized user to execute commands with administrative (root) privileges without logging in as the root user. It is controlled by the /etc/sudoers file, which defines who can run what commands and as which users.
Using sudo improves security by avoiding direct root logins, enabling per-user permissions, and logging all privileged commands for auditing.
Basic Syntax:
sudo [options] command
command: The command to run with elevated privileges.
[options]: Flags to modify behavior (e.g., run as another user).
Common Examples:
# List root directory (requires admin rights)
sudo ls /root
# Edit system configuration file
sudo nano /etc/hosts
# Run command as another user
sudo -u postgres psql
# Start an interactive root shell
sudo -i
sudo -i → Full root login shell (loads root’s environment)
sudo -s → Root shell but keeps current environment
sudo -u user → Run as a specific user
Useful Options:
-l → List allowed/forbidden commands for current user
-v → Extend sudo session without running a command
-k → Invalidate sudo session (forces password next time)
-H → Set HOME to target user’s home directory
-b → Run command in background
-- → End of sudo options (useful if command starts with -)
Best Practices:
Use sudo instead of su – Avoids sharing the root password and provides an audit trail.
Check permissions with sudo -l before running commands.
Never run untrusted scripts with sudo.
Revoke access after tasks using sudo -k.
Audit logs in /var/log/auth.log to track usage.
Example – Running as Web Server User:
sudo -u www-data ls /var/www/html
This runs the ls command as the www-data user, useful for checking web server file permissions.
Key Difference from su:
su switches to another user account entirely (needs that user’s password).
sudo runs a single command (or shell) with elevated privileges using your own password, with logging and fine-grained control.
Do you want me to prepare a quick reference table of all sudo options for faster command recall? That would make administration much easier.
APT COMMAND
apt is a command-line utility for managing software packages on Debian-based Linux distributions, allowing users to install, update, upgrade, and remove packages efficiently.
apt install <package>: Installs a new package, automatically resolving and installing dependencies.
apt remove <package>: Removes a package but keeps configuration files.
apt purge <package>: Removes a package along with its configuration files.
apt auto remove: Cleans up unused dependencies that are no longer required.
apt search <package>: Searches for packages in the repositories.
Git is a distributed version control system with a rich set of commands for repository management, collaboration, and history tracking. Below is a categorized list of essential commands for daily use and advanced workflows.
Setup & Configuration
git config --global user.name "Your Name" # Set global username
git config --global user.email "you@example.com" # Set global email
git config --list # View all configurations
git help # Show help for commands
Repository Initialization & Cloning
git init # Initialize a new repository
git clone <repo_url> # Clone a remote repository
git clone --branch <branch> <repo_url> # Clone specific branch
Staging & Committing
git add <file> # Stage a file
git add . # Stage all changes
git status # Show working tree status
git diff # Show unstaged changes
git commit -m "message" # Commit staged changes
git commit -am "message" # Stage & commit tracked files
Branching & Merging
git branch # List branches
git branch <name> # Create branch
git checkout <name> # Switch branch
git checkout -b <name> # Create & switch branch
git merge <branch> # Merge branch into current
Remote Operations
git remote -v # List remotes
git remote add origin <url> # Add remote
git fetch # Fetch changes
git pull # Fetch & merge
git push # Push changes
git push -u origin <branch> # Push & set upstream
History & Inspection
git log # Commit history
git log --oneline --graph --all # Compact graph view
git show <commit> # Show commit details
git blame <file> # Show last change per line
Undoing Changes
git restore <file> # Discard changes in file
git reset --soft <commit> # Move HEAD, keep changes staged
git reset --hard <commit> # Reset & discard changes
git revert <commit> # Create commit to undo changes
Stashing
git stash # Save uncommitted changes
git stash list # List stashes
git stash pop # Apply & remove latest stash
Tags
git tag # List tags
git tag <tagname> # Create lightweight tag
git tag -a <tagname> -m "message" # Annotated tag
git push origin <tagname> # Push tag
Advanced Tools
git rebase <branch> # Reapply commits on another base
git reflog # Show HEAD history
git cherry-pick <commit> # Apply specific commit
Runs Python 3 scripts using the Python interpreter.
Basic Syntax:
Bash
Copy code
python3 script.py
Examples:
Bash
Copy code
# Run a Python script
python3 hello.py
# Run inline Python code
python3 -c "print('Hello from Python 3')"
# Start interactive Python shell
python3
Notes:
python3 ensures you’re using Python 3.x (not Python 2.x).
You can pass arguments to scripts:
Bash
Copy code
python3 myscript.py arg1 arg2
Runs JavaScript files using the Node.js runtime.
Basic Syntax:
Bash
Copy code
node script.js
Examples:
Bash
Copy code
# Run a JavaScript file
node app.js
# Run inline JavaScript
node -e "console.log('Hello from Node.js')"
# Start interactive REPL
node