Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions assignment1/q1/1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Bandit wargame
Personal refernce- Read about the new commands again
## Level 0:
`ls`
`cat readme`

Password: ZjLjTmM6FvvyRnrb2rfNWOZOTa6ip5If

## Level 1:
`ls`
`cat ./-`

Password: 263JGJPfgU6LtdEvgfWU1XP5yac29mFx

## Level 2:
`ls -l`
`cat "spaces in this filename"`

Password: MNk8KNH3Usiio41PRUEoDFPqfxLPlSmx

## Level 3:
`ls`
`cd inhere`
`ls -la`
`cat ...Hding-From-You`

Password: 2WmrDFRmJIq3IPxneAaMGhap0pFhF3NJ

## Level 4:
`cd inhere`
`file ./*`
For refernce: `file <filename>` (Used to find the type of a file)<br>
`cat ./-file07`

Password: 4oQYVPkxZOOEOO5pTW81FB8j8lxXGUQw

## Level 5:
`find . -type f -size 1033c`<br>
`cat ./inhere/maybehere07/.file2`<br>
For reference:
`ls -s` : Lists files with their disk usage in block of 1024 bytes. ie- Shows the disk space the file is taking<br>
Find command works recursively by default (recursively inside the directories)
. :Current directory

Password: HWasnPhtq9AVKe0dmk45nxy20cvUa6EG

## Level 6:
`find / -type f -user bandit7 -group bandit6 -size 33c 2>/dev/null`
`cat /var/lib/dpkg/info/bandit7.password`<br>
For personal reference:<br>
`.` :Refers to the current directory itself<br>
`..` :Refers to the parent directory<br>
`2>/dev/null` :Hide error messages (stderr)
/ :Root directory (Every file and folder in Linux is inside or under this directory)

Password: morbNTDkSW6jIlUc0ymOdMaLnOlFVAaj

## Level 7:
`grep -i millionth data.txt`

Password: dfwvzFQi4mU0wfNbFOe9RoWskMLg7eEc

## Level 8:
`sort data.txt | uniq -u`<br>
For personal reference:<br>
`uniq -u`: removes all duplicates entirely

Password: 4CKMh1JI91bUIZZPXDqGanal4xvAg0JM

## Level 9
`strings data.txt | grep '==='`

Password: FGUW5ilLVJrxX9kMYMmlN4MgbpfMiqey

## Level 10
`cat data.txt`
`base64 -d data.txt`<br>
Personal reference- Decode by converting Base64 to binary, then to ASCII text<br>
Each Base64 character = 6 bits<br>
4 Base64 chars = 3 bytes of data

Password: dtR173fZKb0RRsDFSGsg2RWnpNVj3qRr

## Level 11
`cat data.txt`
`cat data.txt | tr 'A-Za-z' 'N-ZA-Mn-za-m'`

Password: 7x16WNeHIi5YkIhWsfFIqoognUTyj9Q4

## Level 12
``

For personal refernce- <br>
`mktemp` = make temporary file or directory<br>
Created inside /tmp by default (a place for temp files)<br>
Has a random name, so it's hard to guess (important for security)<br>
Prevents name collisions


Password:
40 changes: 40 additions & 0 deletions assignment1/q2/2a.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Shell Assignment 2.a (Missing Semester -The Shell)

1. `echo $SHELL`

2. `mkdir /tmp/missing`

3. `man touch`

4. `touch /tmp/missing/semester`

5. `nano /tmp/mmissing/semester`

Paste into the file:
```bash
#!/bin/sh
curl --head --silent https://missing.csail.mit.edu
```
Save and Exit

6. `/tmp/missing/semester`
Check why it failed:
`ls -l /tmp/missing/semester`

7. `sh /tmp/missing/semester`

8. `man chmod`

9. ` chmod +x /tmp/missing/semester`

Run the file :
`/tmp/missing/semester`

10. `/tmp/missing/semester | grep -i "last-modified" > ~/last-modified.txt `

11. Battery: `cat /sys/class/power_supply/BAT0/capacity
`

CPU temperature (in millidegrees Celsius): `cat /sys/class/thermal/thermal_zone0/temp
`

86 changes: 86 additions & 0 deletions assignment1/q2/2b.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Shell Tools and Scripting

1. `ls -alh --sort=time --color=auto`

2.
``` bash
#!/bin/bash

# Function to save the current directory
marco() {
export MARCO_DIR="$PWD"
}

# Function to return to the saved directory
polo() {
cd "$MARCO_DIR" || echo "No directory saved. Run marco first."
}
```
Personal reference- <br>
`source filename.sh` - <br>
Executes the commands in the given file in the current terminal<br>
Variables and functions defined in the script remain available after it runs<br>
`bash marco.sh` - <br>
It runs in a new temporary shell, and any functions or variables won’t persist after that script ends.<br>

`export` makes the variable available globally to the current shell and any child processes.<br>
`$VAR_NAME` means: "Get the value stored in the variable `VAR_NAME`

![alt text](image.png)


3.
`failing_Script.sh`
```bash
#!/usr/bin/env bash

n=$(( RANDOM % 100 ))

if [[ n -eq 42 ]]; then
echo "Something went wrong"
>&2 echo "The error was using magic numbers"
exit 1
fi

echo "Everything went according to plan"

```

`watcher.sh`
```bash
#!/bin/bash

count=0

while true; do
((count++))
./failing_script.sh > out.txt 2> err.txt
if [[ $? -ne 0 ]]; then
echo "Script failed after $count runs"
echo "---- STDOUT ----"
cat out.txt
echo "---- STDERR ----"
cat err.txt
break
fi
done
```
Personal reference-
`(( ))` is used for arithmetic operations in Bash <br>
`n=$(( RANDOM % 100 ))` - Store a random number from 0–99 in variable n<br>
`exit 0` = success<br>
`exit 1` or any non-zero = error/failure<br>
`[] [[]]` - Difference

`chmod +x failing_script.sh`
`chmod +x watcher.sh`

![alt text](image-1.png)

4.
`find . -name '*.html' -print0 | xargs -0 zip html_files.zip` <br>
`-print0` - prints them separated by a null character (\0) instead of a newline, which is safe for filenames with spaces or special characters.

5.
`find . -type f -printf '%T@ %p\n' | sort -nr`- Lists all files, from most recent to oldest.<br>
`find . -type f -printf '%T@ %p\n' | sort -n | tail -1` - Sorts from oldest to newest and gives the last(newest) file
Binary file added assignment1/q2/image-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assignment1/q2/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions assignment1/q5/5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Bash Script Automation Task: Clean Up Downloads Folder

`clean_downloads.sh`
```bash
#!/bin/bash

# Description:
# This script cleans up the Downloads folder by deleting files
# older than 2 months (~60 days).

DOWNLOAD_DIR="/mnt/c/Users/Anushka/Downloads"
DAYS=60
SIZE="+100M"

echo "Cleaning up files older than $DAYS days and larger than $SIZE in $DOWNLOAD_DIR..."

# Find and delete matching files
find "$DOWNLOAD_DIR" -type f -mtime +"$DAYS" -size "$SIZE" -print -delete

echo "Cleanup complete."
```

Make the file executable: `chmod +x cleanup_downloads.sh` <br>
Run the script: `./cleanup_downloads.sh`

## Justification
This Bash script automates the cleanup of the Downloads folder by deleting files that are larger than 100 MB and older than 60 days. It is particularly useful for freeing up disk space by removing outdated and bulky files that are no longer needed.<br>
Two parameters `$DAYS` and `$SIZE` are defined at the top of the script, making it easy to modify the criteria as needed<br>
By scheduling this script to run periodically, users can maintain a cleaner and more efficient file system without manual intervention.

## Output
![alt text](image-2.png)
Binary file added assignment1/q5/image-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.