# Password Generator ## 1. File Checks Using `[[...]]` ```bash [[ ! -f "$file" ]] ``` This line checks **if the password file does not exist**, and creates it if needed. | Expression | Meaning | |----------------|-------------------------------------------------------------------------| | `[[ ... ]]` | Bash's keyword for conditional expressions | | `!` | Logical negation – inverts the result | | `-f "$file"` | Returns true if `$file` **exists** and is a **regular file** | | `-e "$file"` | (Alternative) Returns true if file exists (directory, symlink or file) | | `-d "$file"` | Returns true if file is a **directory** | ### Example: ```bash [ -f "file.txt" ] && echo "file exists" ``` ## 2. `grep -q "^$name :" "$file"` This line checks if a given password **name already exists** in the file. | Part | Meaning | |------------------------------|---------------------------------------------------------------| | `grep` | Searches for patterns in files | | `-q` | Quiet mode – no output, just returns success/failure | | `^$name :` | [regex](https://www.sitepoint.com/learn-regex/): matches only lines that **start** with "`$name :`" | | `"$file"` | File to search within (`passwords.txt`) | ### 3. Code Walkthrough ```bash file="passwords.txt" if [[ ! -f "$file" ]]; then touch "$file" fi ``` **Checks if the password file exists**, if not, creates it using `touch`. ```bash echo "Enter the number of characters" read len if (( len > $file; then echo "saved to passwords.txt" else echo "Couldn't save the password" echo "password: $p" fi ``` ## 4.`(tr -dc 'A-Z' < /dev/urandom | head -c1)` `/dev/urandom` :special file in Unix-like systems that provides an endless stream of random bytes. `tr -dc 'A-Z'` : deletes all bytes except the characters from 'A-Z' (c-complement). `tr` : stands for translate and is used for transforming or deleting specific characters from its input. `head -c1` ## Clipboard Option (`xclip`) ```bash if command -v xclip >/dev/null; then echo "$p" | xclip -selection clipboard echo "Copied to clipboard" else echo "xclip is NOT installed" fi ``` - Checks if `xclip` is installed - `command -v xclip` return the path to the xclip if its installed. - `>/dev/null` discards the output, so nothing is displayed to the user. - The `-selection clipboard` option tells xclip to place the input text into the system clipboard, so it can be pasted elsewhere with a standard paste operation (e.g., Ctrl+V). ## Sample Output ``` Enter the number of characters > 10 Choose type: 1 - alpha-numeric 2 - alpha-numeric + symbols > 2 Enter the name of the password: > github ⚠️ A password named github already exists. Do you want to replace it?? (y/n): y saved to passwords.txt Copied to clipboard ``` ## Summary Table | Concept | Tool/Command | Meaning/Purpose | |---------------|------------------|---------------------------------------------| | `[[ -f FILE ]]` | File existence check | True if file exists and is regular | | `grep -q` | Quiet match | True if pattern is found | | `tr -dc` | Char whitelist | Filters characters | | `shuf`, `fold`| Random shuffle | Mixes final password | | `xclip` | Clipboard tool | Copies password | # File organizer: - Organizes files based on extension and file type. - deletes all the duplicate files(files with same name and bytes) and sends them to bin - modifies the path of ur original files and creates a backup to your previous file system just in case.