Utility Tutorials

Check size of directory in Linux

In this tutorial, we will look at how to check the size of a directory in Linux. This task is done using the du command which is a standard Unix/Linux program. The abbreviation du is short for disk usage.

Checking the size of a directory may be useful, for example, on something like a Linux web server where we may want to know what the size of our web root is for backup purposes. The simple fact is, being able to check the size of a directory in Linux is very useful in a number of ways.

Check Free Space on Linux

In this tutorial we will look at how to check free space on Linux or Unix from the command line. It is important to keep track of the amount of free disk space you have, especially on a server where it is of utmost importance that data loss or downtime be kept to a minimum.

Linux and Unix systems come with a handy utility called df (short for disk free) which is used to display the amount of free space on any filesystem that the user invoking the command has read access to.

Check open ports on Ubuntu Linux

One may want to check open ports on Ubuntu to ensure that there are no services listening that shouldn't be. If we remember, a port is what an application will use to communicate with another application, provide a service, etc. To get an idea of what services are running on a system, we would need to check the open ports on the system.

Use cron to run PHP script

Using a cron job to run a PHP script is very easy if you know how. If we recall, cron is a Unix/Linux utility that is used to perform tasks at specified intervals. By setting up a cron job with the appropriate parameters, we can get our system to execute PHP scripts or any other kind of script.

Create file with dd on Linux

Occasionally, for testing purposes, we will want to create a large file. There is a handy utility installed on most Linux systems called dd which makes the task of creating files of any size very easy. The beauty of dd is that it works very fast and very large files can be created quite quickly. The tutorial below will show how to create a file of any size with dd on Linux.

Send Email with attachment from the command line in Ubuntu Linux

Sending emails with attachments from the command line in Ubuntu is easily accomplished using a tool called mutt. Mutt allows us to send emails non-interactively. That is, we can invoke mutt from a shell script and it will perform the specified tasks for us with no further intervention needed on our part.

We can also run mutt from a shell (such as bash) or even as a cron job and have it carry out our desired tasks.

Bash Timestamp - Get Unix timestamp in bash

The current Unix timestamp is a numeric representation of the current date and time. The current timestamp may come in handy when checking when files were last modified or when an event occurred or something of the sort.

To get the current Unix timestamp from a bash terminal we may use the following code:

date +%s

If we execute that command in a terminal, we get a really big number which represents the current date and time. We may see output like:

1302902881

Exclude files from Tar Archive

Tar is a UNIX/Linux utility which is used to compress files for storage in an archive. When we tell tar to compress and create an archive of a directory, it will go ahead and include all the files in that directory.

Sometimes we may want to exclude a particular file from an archive. Tar allows use a convenient option to specify a file or files to exclude when making the archive. The tutorial below shows how we do a tar exclude file operation by using the command line.