How can I determine the size of a directory or folder in Linux?

May 1, 2016

du -hs /path/to/directory

-h: human-readable
-s: summary (don’t show size of each individual file within the directory)

#command line #linux #ubuntu

Go to comments

Tutorial: How to use Linux Screen

March 9, 2015

A problem that often arises when you’re dealing with lots of data is that it takes forever to process.

So you SSH into your Amazon EC2 machine, start your script, and go do other things while it’s running.

You check back a few hours later to see that your SSH session seems to be frozen or you’ve gotten a “broken pipe” error.

You log back in to your EC2 machine, only to discover your script has terminated.

What to do…

Screen for Linux

Screen is like having “tabs” for your command line. You can have multiple screens running at any time. They stay active, so even if you exit from a screen, or exit your entire SSH session, whatever you were doing inside that screen will continue.

This is great if you have a script that takes longer than EC2’s allowed session duration.

Start Screen

To start screen, just enter:


Hit enter to exit out of this info screen.


How Screen Works

Once you’ve started screen, there are a few things you can do:

1. Create a screen

2. Detach from a screen (i.e. go back to your “regular” terminal)

3. Re-attach to a screen (that you’ve previously detached from).

4. List the screens you have open

This is all you need for the use case described above.


Enter commands in Screen

Once inside Screen, you can tell screen you’re about to enter a command by pressing:

Ctrl + A

Now Screen knows you’re about to enter a command.


Create a Screen

After hitting “Ctrl+A”, hit “C”.


Detach from a Screen

After hitting “Ctrl+A”, hit “D”.


Re-attach to a Screen

screen -r


List the Screens you have open

The above only works if you have only one screen open. Otherwise, you’ll see this:

If you want to re-attach to a particular screen, enter:

screen -r 14366.pts-0.affinity-proto

(Obviously you would choose the screen you want to go back to).

#big data #command line #linux #screen #ubuntu

Go to comments

How to password-protect a PDF file on Ubuntu

July 25, 2014

In a terminal, type:

sudo apt-get install pdftk

Then, to add a password to a PDF file, type:

pdftk <input-file> output <output-file> user_pw <password>


pdftk input.pdf output output.pdf user_pw 1234
#linux #password #pdf #ubuntu

Go to comments

Can’t restart Apache in Ubuntu

March 24, 2013

When I try to restart Apache using the command:

sudo apachectl -k restart

I get this error:

apache2: Could not reliably determine the server’s fully qualified domain name, using for ServerName

Solution: Edit httpd.conf:

sudo vi /etc/apache2/httpd.conf

Press “i” to insert

ServerName localhost

Then press “:x” to save.

Now you can restart Apache:

sudo apachectl -k restart

#apache #Restart #ubuntu

Go to comments

Deep Learning and Artificial Intelligence Newsletter

Get discount coupons, free machine learning material, and new course announcements