DEV Community

Pradeep Sharma
Pradeep Sharma

Posted on

Simple command to block distracting websites [Productivity]

For Linux based systems

Step 1: Open terminal
Step 2: Open the hosts file sudo vi /etc/hosts
Step 3: Add websites you want to block and save

127.0.0.1 facebook.com
127.0.0.1 www.facebook.com
127.0.0.1 web.facebook.com
Enter fullscreen mode Exit fullscreen mode

For windows

The host file location(step 2) is> C:\Windows\System32\drivers\etc
everything else is the same

I'm tweeting similar things on twitter. Follow me and feel free to message me.

Top comments (11)

Collapse
 
icart profile image
iCart

Someone made this into a single simple command, here:

github.com/timothycrosley/concentr...

Tested and approved, i have been using it for a while now.

Collapse
 
barryblando profile image
Barry⚡

Yikes! Better.

Collapse
 
pradeep_io profile image
Pradeep Sharma • Edited

Here you go:

sudo su
echo "127.0.0.1 facebook.com" >> /etc/hosts
echo "127.0.0.1 website.you.want.to.block" >> /etc/hosts

Will work very well to block a website. Unblocking the website will need more sophisticated version of this by having conditional statements and patterns to remove the matching entries. I prefer editing the file, it's much faster and neat.

Collapse
 
argysamo profile image
Argyrios Samourkasidis

I was thinking of having two /etc/hosts files:

a. one that blocks distracting websites
b. a "normal" one

Also, a cron job (?) that is running twice:

a. in the morning to activate the "blocking" one (renaming?)
b. in the afternoon (after work anyway) to activate the "normal" one

Thread Thread
 
pratikaambani profile image
Pratik Ambani

Was thinking about the same but dunno how...
How? 😀

Collapse
 
zx8754 profile image
Tokhir Dadaev
Collapse
 
x2plusy2 profile image
Aaron Chamberlain

If your on MacOS, it's even easier to just use something like the app "Self Control" you can either blacklist or whitelist a website for a set period of time, with no way to turn it off, even at restart.

Collapse
 
zeropaper profile image
Valentin Vago

and you can also block a bunch of tracking websites with that technic.

someonewhocares.org/hosts

Collapse
 
itenev profile image
Ивелин Тенев

We may need to extend that list with entries for twitter.com and dev.to :D

Collapse
 
p4rv_j profile image
Parv Jain

make sure you clear your browser cache after doing it.

Collapse
 
jsila profile image
Jernej Sila

I tried this couple of months ago! Figured out social logins don't work anymore. I settled with custom userscripts (tempermonkey/greasemonkey) that removes body from html upon visiting website.