Thursday, April 28, 2011

Checking File Size and Disk Space in Linux

Linux comes with two commands that are useful for checking disk space usage.

df is used to check the space of mounted partitions
du is used to check the file sizes of files and directories

The most common use for df is to check partition free space. To make the output more human readable, use the -h option.

df -h

If you need to check on the size of a directory or its contents, use the du command. The most common options are -h (human readability), -a (display files and folders, not just folders) and -c (display a total size at the bottom).

cd /some/dir
du -ahc

For more advanced uses, run each command with the --help option for a list of additional options.

Saturday, April 2, 2011

Download a File From Linux Command Line Terminal

Getting a file from the internet using the command line is super easy. Simply cd to the directory you want:
   cd /var/www/images

And use wget to download the file you need:

That's it! Don't let it fool you, wget is a very advanced tool. For more usage examples go here:

Install an FTP server on Amazon EC2 LAMP

I've recently created my first server on Amazon EC2 (more on that soon) and I needed to move some stuff over. Here's how to setup a secure FTP server and configure it for your LAMP.

First, install the ftp software:
   apt-get install vsftpd

Next, edit /etc/vsftpd.conf and uncomment or change the following:

Add following lines at the end of file:

Next, you'll want to create a local user and a home directory where files will be saved. This keeps your www directory safe from intrusion. Upon connecting over FTP you'll be able to see and read from anywhere on the system, but only upload to one directory.
   adduser ftp_user
   passwd ftp_user
   mkdir /home/ftp_user
   chown ftp_user:users /home/ftp_user

You might only need the first command as your distro will take care of all the rest by prompting you.

Now you need to restart the ftp server to load the new configuration:
   /etc/init.d/vsftpd restart

If you are wondering why I chose to restrict the passive ports to 1044 - 1048, this is because Amazon blocks all ports unless specifically allowed by the security group. You will need to open those ports in your Amazon Console. Click Security Groups, chose your group, click the Inbound tab and create a new Custom TCP rule. Specify ports 1044-1048, click Add Rule and Apply Rule Changes.

Presto! You can now connect to your LAMP over FTP using ftp_user. Your files will be uploaded to /home/ftpuser