Question: Just to be clear I want to comment crontab entries, not a basic file. Usually, I do it like

> 
> crontab -e
> 
> 
> 

```
30 * * * * /u01/app/abccompny/scripts/GenerateAWRReport.pl
01,31 * * * * /u01/app/abccompny/scripts/table_growth_monitor.sh
30 0,4,8,12 /u01/shivam/script/getMongoData.sh 

```

and I add "#" in front of each line and just save it. Similarly after work is done I remove the "#". 

```
#30 * * * * /u01/app/abccompny/scripts/GenerateAWRReport.pl
#01,31 * * * * /u01/app/abccompny/scripts/table_growth_monitor.sh
#30 0,4,8,12 /u01/shivam/script/getMongoData.sh 

```

Is there an efficient way to do this using the script?

Answer: 
We will copy cron to some other file, make changes and again apply the cron.
----------------------------------------------------------------------------

Copy your cron to some file,

```
crontabl -l > filename

```

Now `filename` has your cron, you can apply your cron using

```
crontab filename

```

---

Comments starts with #, so we will add and remove # from start of the line.

To add and remove comments you can use `sed` 

Remove comments (#)

```
sed -i -e 's/^# //g' filename

```

Add comments (#)

```
sed -i -e 's/^/# /g' filename

```

---

Apply cron using 

```
crontab filename

```

Check you cron

```
crontab -l

```

---

```
Happy Scripting

```
Old post, but i think there is a much faster and easier solution :

On Linux, everything is a file. Crontab stores crons of each user in /var/spool/cron/

* On Ubuntu 20.04 : **/var/spool/cron/crontabs/<user>**
* On RHEL7 : **/var/spool/cron/<user>**

So you can just :

```
# comment
sed -i 's/^/#/' /var/spool/cron/<user>

# uncomment
sed -i 's/^#//' /var/spool/cron/<user>

```