Linux Commands (and Files) I Need to Remember
I don’t need to remember the ones I use often (like “cp” for copying a file or “rm” for removing one). It’s the ones I rarely use. Like the one that increases shared memory (SHM) and the one to mount a memory-based directory on top of a hard disk directory.
Linux Commands to Increase Shared Memory
If you issue the “df -m” command from the Linux command line, you’ll get a list of all the file systems mounted. For shared memory, it’ll be either “/dev/shm” or “/run/shm”. I use Ubuntu on my server, so it’s “/dev/shm” for me. It’s the same for Linux Mint on my laptop computer.
The size of this RAM drive is usually set automatically to one half of the installed RAM, but it really depends on how a particular Linux distribution handles it. To increase it on Ubuntu, open the file named “/etc/fstab”, find the line that says “none /run/shm tmpfs defaults 0 0” and add a comma after defaults and show the desired size, like “defaults,size=512m”. You can use “g” for gigabytes if you have that much RAM available.
Then issue the command “mount -o remount /dev/shm” or “mount -o remount /run/shm” to make the change effective immediately. You should note what it was before doing so if you want to change it back to what it was, because you have to specify it if you want it to take effect immediately.
Why would you want to increased the /dev/shm size? Well, some applications can be set to use that area instead of the hard disk. Writing to memory doesn’t wear out the hard disk, whether it’s a platter system or a solid-state drive.
Linux Commands to Mount a Memory-Based Directory
Most Linux distributions mount RAM as “tmpfs”. I know Ubuntu and Linux Mint do. You can mount part of it as a special memory-based directory on top of an existing physical directory. Once it’s mounted, the physical directory is invisible until it’s unmounted (if that’s what you want to do).
This works really well when you have a caching scheme where the cache directory can’t be moved, like with most WordPress caching plugins. Here’s how to create a 128 megabyte memory-based directory for it:
mount -t tmpfs -o size=128m tmpfs /path-to-wordpress-root/wp-content/cache
To unmount it, you’ll have to stop the web server and issue “umount tmpfs”. To make it permanent, add this to “/etc/fstab”:
tmpfs /path-to-wordpress-root/wp-content/cache tmpfs defaults, size=128m 0 0
Why would you want to do this? If your hard disk is a platter-system, this is going to make your cached pages serve much faster. Not so much with a solid-state drive.
Adding Linux Commands to my List
I’m always looking up Linux commands to deal with issues that come up. This is the page where I’ll add the ones I need to add, if only as a personal reference point.