My Top 10 Linux Commands

Over the last couple of years my role has expanded significantly and I have really had to pick up some good tips and tricks to try and make me as efficient as possible.  One area that has had to grow has been my familiarity with linux, terminal and my comfort with the command line and so I thought I would share my top 10 linux commands which I use on a regular basis. 


In no particular order:- 

1) Make a directory and any parent directories that do not exist.

mkdir -p app/cache

2) Replace a string within a file.

sed -i 's/alpha/beta/g' beta-site.conf

I found this useful for copying a vhost file from an existing site and quickly change all the references to the new domain name.

3) Check disk usage on server

df -h

When services such as MySQL don't start properly or you start getting cron error emails, this can sometimes be a symptom of a disk which is completely full. 

4) Run a command on a remote server 

ssh myserver uptime

Sometimes all I want is to run a command on a remote server but not actually enter a SSH session on the remote server.  My main requirement for this was to check the load on a server using uptime and as there were several servers which made up the platform I needed to create a small script which would run this command on each server so I could easily get a snapshot of the load across the platform.

There is a little extra configuration required to achieve this in an optimal way as SSH keys need set up so you can access the remote servers without constantly needing to enter the server username and password for each server.

5) Quickly find a phrase in a project folder when netbeans / eclipse is being slow

grep -r "the brown fox" .

I like Netbeans as an IDE but sometimes it can be unbearly slow, especially if it is scanning a project over the network so this little tip helps me to keep progressing when Netbeans is not playing ball.  If you are using sublime this can be achieved using Ctrl + Shift + F.

6) Run previous command as root

sudo !!

Does what it says on the tin!

7) Find the number of instances of a phrase within an archived error log 

less access.log.gz | grep "desktop=1" | wc -l

Logs can be tricky to analyse, especially if you are running a high traffic site.  This command was used to try and find how many instances were recorded for mobile users switching to the desktop version of the site.

8) Export database exluding stats tables

mysqldump -u username -p database --ignore-table=database.table1 --ignore-table=database.table2 > database.sql

A number of the sites I've worked on have had databases that are easily a couple of gigabytes so backing up and restoring these is a painful task.  Fortunately most of them have had sizable tables which can safely be ignored when backing up the database for transferring to a development server and this often results in a backup files of a couple of hundred megabytes rather than gigabytes.

9) Fix a accidental pull

git reset --hard HEAD
git clean -f

Ever accidentially pulled the wrong branch into your working directory.  The combination of these 2 commands helps straighten me out a few times.  The first reverts all the tracked files that have been modified to the latest commit and the 2nd removes any untracked files that are left lying around.  This has to be used with care as if your latest changes have not been committed then they will be lost, and if you have untracked files you want to keep you will need to make a copy of them or they will be lost too.

10) Run commands overnight without open connection

screen -R

This is great for running long processes overnight but without having to leave a SSH session logged in.  You can simply SSH to the remote server, run "screen" and then continue entering commands as you need.  When your process is running you can safely disconnect your SSH session or turn of your computer and the process will continue to run.  Later you can SSH back into the remote server and then run "screen -R" to re-attach to your screen session.

a) Search previously run commands

Press Ctrl + R

This one is not technically a command but it comes is so handy, not a day goes by that I don't use this one.  If you type in the phrase you are looking for and it doesn't show it right away then press Ctrl + R again and it will go to the next instance in the bash history it can find.

Now it is your turn

You've heard what helps me out so what command line tips or tricks do you have that helps make things that little bit easier?

I am a web developer specialising in web driven applications using PHP, MySQL, Symfony and Zend and I am currently working for the The Drum in Glasgow, Scotland.

Most days I can be found frantically coding away with EuroDance in my ears and consuming what I hope to be a never ending supply of coffee... happy days!

Want more like this?

Keep up-to-date with latest news from Inside the Agency using any of the following services

Recent articles

Behind the Paywall - An Insider Point of View

Over the years, a number of publishers have tried their hand at implementing a paywall. These efforts have been met with varying degrees of success:


The Sun introduced a paywall on the 1st August 2013, partially removed it in the summer of 2015 and removed it completely on the 30th November 2015. The Financial Times introduced its paywall in 2007, however, they chose to relax the paywall in 2015 in an effort to combat sluggish growth and The Times introduced its paywall in 2010, which recent news suggests it be performing well.

Read more

Four things that suck about project management

Project management is not a glamorous job.   The better you are, the less you’re noticed: things just hum along nicely, with no major conflicts or serious misunderstandings.  If you’re diligent, skilled, dedicated and competent, someone else will get credit.  The software, application, website or rebuild you so lovingly slaved over will be attributed to your boss, your client, or – if you’re lucky – to your developers or creatives.

In fact, the only time a project manager can rely on getting any real attention is when things go wrong.  A host of complex issues may be present – problematic management behaviour, shifting requirements, lack of necessary cooperation from the wider business, underinvestment in skill or resource – but the blame is ultimately yours.  You’re the project manager.

Read more

“My boss doesn’t get it.” The puzzle of motivation.

Management roles have traditionally focused on issuing assignments and offering rewards.  For much of the industrial age, this worked well.  In the vast majority of situations, people do work harder if they know they’ll get a financial bonus or more recognition.  Primed with 100 years of business advice, managers feel they have the tools they need to get things done, retain their staff and hit their targets.


But when they find themselves at the helm of a team of developers, or a mixed team of designers and developers, managers get confused.  The promise of rewards only goes so far.   Sometimes, incentives fail to generate any interest and may even lead to resistance.  Developers who never voice any dissatisfaction put in their notice and move on without any explanation, leaving you scratching your head.  It’s really confusing, and there are no easy answers. 

Read more


Digital Ocean

Chris's Reading List

BFF @ SoundCloud

Our friends at SoundCloud embarked on a journey a few years ago that changed their system and moved it from a monolithic Rails application towards an ecosystem of microservices. Read more

The Drum

The Drum

Google'€™s AMP is bringing some much needed speed to mobile but the transition won'€™t be easy for publishers

A week after launching, the Google-led Accelerated Mobile Pages (AMP) initiative has raised more questions than answers for publishers... Read more



Quick Tip: How to Permanently Change SQL Mode in MySQL

MySQL 5.7 introduced some awkward changes for older codebases and tends to break apps. Here's how to temporarily (or permanently) lower the strictness level Read more



How to Build Your Own Dependency Injection Container

Andrew Carter builds a Dependency Injection container from scratch, showing you how that rocket science is really just fireworks strapped to lego figures! Read more



13 Reasons Your Organic Traffic is in Decline | It's Not a Penalty

The landscape of search engine optimization has changed drastically in the last 3-4 years. Even as it changes, a lot stays the same. It has been very challenging to see a multitude of friends and colleagues approach me with problems that often seem beyond repair with clients that they have worked with for years. Read more



WordPress Sites Now Support Google’s AMP To Make Mobile Pages Load Much Faster

Google has some big plans when it comes to making the web faster on your mobile phone. The company just added AMP-enabled pages in its mobile search results... Read more