Useful linux commands for web developers

Useful linux commands for web developers

Posted on by Petter Kjelkenes - last updated 11. July, 2019

These are linux commands that I use every day at work and home as a web developer.

history

history

History is useful, especially when dealing with deployments and other setups on projects that you are not very familiar with. If the standard go-to guy for deploying the app is on vacation, and you need to deploy emergency fix - history is your friend.

I normally use sudo su - www-data and change directory to the web app i'm dealing with. As deployments in terms of a php app is normally done via the www-data user / web server user.

If the project is a php project you can assume that it uses composer (at least now in 2019). Then, to find out how the app was deployed you can simply use history together with grep.

history | grep "composer"

Using this command you should probably get some results of how to use the composer install command.

pwd

"pwd" shows the current working directory. Useful when you're lost.

top

"top" is useful to check for abnormal resource usage. A list of the processes will display live in the terminal. Important statistics are e.g. memory usage and CPU usage.

To sort the results by memory usage press "SHIFT+M".

To sort by CPU usage press "SHIFT+P"

To exit "top" press "q".

clear

"clear" clears the terminal in the viewport. Very useful when you need a clean sheets for some heavy command use. I normally use clear

grep

I use grep every day for searching a tree of files for some keyword.

To do a recursive lookup you can use the following command:

grep -lir "cash" src/

This command searches the src/ folder and its sub folders of a file that contains the word "cash" or even "CaSH".

Arguments explained

  • i: Means its a case-insensitive search.
  • l: Means it prints only the names of the files that matches.
  • r: Recursive search in all sub folders.

And then to some one-off commands for dealing with web related tech.

Clearing all data in memcache

This is especially useful when testing caching strategies and deployment. You want to remove all the data in memcache.

echo 'flush_all' | nc localhost 11211

This command uses netcat, connects to the memcache instance and runs the "flush_all" command which clears the memcache data.

Comments