Picture this: You're following a tutorial, typing commands like a wizard, when suddenly...
./install.sh: Permission denied
(based on a true story)
Or worse:
command not found
Congratulations! You've met Linux's gatekeepers: chmod and PATH. Let's dissect them without the usual jargon overdose.
Part 1: chmod (Or, "Why Can't I Run My Own Damn Script?")
What It Actually Means
Every file in Linux has permissions like a nightclub bouncer:
Read (r): "You can look at this file."
Write (w): "You can edit this file."
Execute (x): "You can run this file (if it's a script/program)."
The chmod Command
It changes permissions. Syntax:
chmod [who][+/-][permissions] file
Examples:
Give yourself execute permission:
chmod u+x script.sh # u = user (you), +x = add execute
Lock down a file (read-only for everyone):
chmod 444 file.txt # 4 = read, for user/group/others
Pro Tip: Octal Notation
Nerds love numbers. Here's the cheat sheet:
Number | Permission |
---|---|
4 | Read |
2 | Write |
1 | Execute |
Add them up:
- 7 = 4+2+1 (read+write+execute)
- 6 = 4+2 (read+write)
- 5 = 4+1 (read+execute)
chmod 755 script.sh # You get everything, others get read/execute
Part 2: PATH (Or, "Why Can't Linux Find My Program??")
What Is PATH?
A list of directories Linux checks when you type a command. Run this to see yours:
echo $PATH
# Output: /usr/local/bin:/usr/bin:/bin:/snap/bin
The "Command Not Found" Crisis
If you install a program (like rustc or npm) and get this error, it means:
- The program isn't in any PATH directory.
- Linux is being deliberately obtuse.
Fixes:
- Add a Directory to PATH (Temporarily)
export PATH=$PATH:/path/to/your/program
(Dies when you close the terminal.)
- Permanently Add to PATH
Edit your shell config file:
Bash: ~/.bashrc
Zsh: ~/.zshrc
Add this line:
export PATH=$PATH:/path/to/your/program
Then reload:
source ~/.bashrc # or ~/.zshrc
- Nuclear Option (Not Recommended)
sudo cp my_script /usr/local/bin # Now it's in PATH... but pray you don't break anything.
Real-World Example: Installing a Python Script
Permission Denied?
chmod +x cool_script.py
"Command Not Found" After Moving It?
export PATH=$PATH:/home/yourname/scripts
TL;DR
chmod +x file.sh = "Linux, let me run this!"
export PATH=$PATH:/new/path = "Linux, LOOK HARDER."
Now go fix those errors before I rm -rf my patience.
Top comments (0)