This script helps you block or unblock a list of distracting websites, such as social media platforms, by modifying your /etc/hosts file. It can be used to increase productivity and avoid distractions.
- Download the script and place it in a directory of your choice.
- Open a terminal, navigate to the directory where the script is located, and run the following command to give the script execution permission:
chmod 777 block_websites.sh- Optionally, you can create a symbolic link to the script to make it globally accessible from anywhere in your terminal. Run the following command, replacing
/path/to/your/scriptwith the actual path to the script:
sudo ln -s /path/to/your/script/block_websites.sh /usr/local/bin/block_websitesNow you can use the block_websites command instead of the script path.
Run the following command:
sudo ./block_websites onor, if you created a symbolic link:
sudo block_websites onThis command will block all websites listed in the arr variable inside the script by modifying the /etc/hosts file.
Run the following command:
sudo ./block_websites offor, if you created a symbolic link:
sudo block_websites offThis command will unblock all websites listed in the arr variable by removing their entries from the /etc/hosts file.
Run the following command, replacing example.com with the actual website you want to add:
sudo ./block_websites add example.comor, if you created a symbolic link:
sudo block_websites add example.comThis command will update the script file, adding the new website to the arr variable. To block the newly added website, run the sudo block_websites on command again.
Run the following command, replacing example.com with the actual website you want to remove:
sudo ./block_websites remove example.comor, if you created a symbolic link:
sudo block_websites remove example.comThis command will update the script file, removing the website from the arr variable. To unblock the removed website, run the sudo block_websites off command again.