clear ram

By default settings, Linux has a very efficient way of managing the computer’s RAM to get the best performance out of the resources available on your system. This approach may sometimes confuse users as the RAM looks like completely eaten up in spite of closing all applications. Don’t worry, that’s how Linux works. It utilities available memory to cache the applications from the hard disk drive, in a goal to make faster read times.

But, the same advantage becomes a frustrating ordeal, especially for system administrators who are troubleshooting the PC. The changes applied to the system files in the hard disk may not be read because Linux is loading it from RAM. So, in order to know to fix a problem, it is a good idea to clear the RAM instead of rebooting the PC. Let’s take a look.

Clearing RAM in Ubuntu, Linux Mint, and derivatives

Launch Terminal and enter the following command.

sudo sync; echo 3 > /proc/sys/vm/drop_caches

The command ‘sync’ is actually flushing the file system buffer. Command ‘echo’ is doing the job of writing to file and additionally, drop_cache is deleting the cache without killing any application/service. You should immediately see RAM getting freed-up.

Tip: Automate Freeing up RAM by Cron Job

Now that you know how to free up memory on your computer, you may want to automate the clearing memory process in a certain frequency. It can easily be done by applying a cron job. Note that I strongly advise NOT to apply cron job of server machines! It could corrupt the server data. This is to be used only on desktop and laptop PCs.

READ  Ubuntu 18.04.1 LTS released, here is how to upgrade now

STEP 1: To get started, launch terminal and enter the following command to install vim. It is a preferred text editor to create sh files.

sudo apt-get install vim

Pay attention to the terminal and enter root password and ‘Y’ when requested.

STEP 2: Now let’s create a sh file named where we will be adding the script.


STEP 3: In the vim editor, you need to press ‘esc’ key and then press ‘i’ to enter into INSERT mode. Then add the following script to it. The first line below is the Shebang, and then the command which we used to clear RAM.

echo "echo 3 > /proc/sys/vm/drop_caches"

Save the sh file and exit out of the vim text editor. To do that type :wq and press enter. vim will save the sh file and exit out to the terminal.

STEP 4: Now enter the following command in the terminal to give read/write permissions.

sudo chmod 755

STEP 5: Time now to call the crontab command:

sudo crontab -e

STEP 6: Let’s assume that we want to clear the RAM every day at 1 PM.

0 13 * * * /

By default, the new sh file will be created at the top level home directory. You can move it to another place, but do remember the path you give in the above command.

That’s it!

Previous articleHow to increase the Laptop’s Battery Life in Fedora
Next articleHow to create desktop wallpaper slide show in Ubuntu 17.10
Hi there! I'm Kiran Kumar, founder of I'm an avid Linux lover and enjoy hands-on with new promising distros. Currently, I'm using Ubuntu as a daily driver and run several other distros such as Fedora, Solus, Manjaro, Debian, and some new ones on my test PC and virtual machines. I have a day job as an Engineer, and this website is one of my favorite past time activities especially during Winter ;). When I'm not writing for FOSSLinux, I'm seen biking and hiking on scenic trails. Hope you enjoy using this website as much as I do writing for it. Feedback from readers is something that inspires me to do more, and spread Linux love!. If you find a time, drop me an email or feedback from the 'Contact' page. Or simply leave a comment below if you found this article useful. Have a good day!

Leave a Reply

2 Comment threads
2 Thread replies
Most reacted comment
Hottest comment thread
3 Comment authors
Niels Engdahl JensenGaurab SantraBrian Recent comment authors
newest oldest most voted
Notify of

Shebang? Isn’t it just a ‘bang’ ? Your articles are really a great help!

Gaurab Santra
Gaurab Santra

It is giving an output mentioedbelow

“bash: /proc/sys/vm/drop_caches: Permission denied”

What to do?

Niels Engdahl Jensen
Niels Engdahl Jensen

It seems like, you have to bee root.

Niels Engdahl Jensen
Niels Engdahl Jensen

I am sorry for my stupid comment.
Step 4 is now working for me.