Linux Server Administration Tips PHP Tips & Tutorials

PHP: Getting Last Accessed Time of a File – File atime

File atime is the last accessed time of the file, in PHP, you can get the last accessed time of any file by:

$last = fileatime('anyfile');

You may also want to know how to get the mtime or ctime of a file.

Linux Server Administration Tips PHP Tips & Tutorials

PHP: Getting Last Modification Time of a File – File mtime

File mtime is the last modified time of the file or the time when the last modification of the file content occurred. To get the last modified time of the file in PHP, use:

$last = filemtime('anyfile');

Read more about how to get the ctime and atime in PHP.

Linux Server Administration Tips PHP Tips & Tutorials

PHP: Getting Last Changed Time of a File – File ctime

File ctime may be a little misleading in nature as many would think it as the creation time of the file, but actually it’s the meta data such as the ownership or permissions change time of the file in addition to content modification. To get the ctime of a file in PHP:

$last = filectime('anyfile');

Aside from ctime, you may also want to learn about getting the atime and mtime in PHP.

Hosting Tips & Deals Linux Server Administration Tips

How to count the lines and get the number of lines in a text file under Linux?


wc -l foo.txt

And the system returns:

12 foo.txt

Meaning foo.txt has 12 lines.

To count unique lines a file has:

sort -u foo.txt | wc -l

Which will simply exclude all extra lines that are identical.

Hosting Tips & Deals Linux Server Administration Tips

How to know if your hosting provider is overselling on your server?

To check whether you are one of the victims that are dwelling on oversold web hosting servers, you need to have SSH access to your server. Now perform the following commands:

cat /proc/cpuinfo | grep processor | wc -l

Which will usually return the number of the CPUs of the current server:


Then, display the server load by


Which outputs a single line of information concerning the server load and how it is doing its jobs:

08:44:12 up 11:09, 2 users, load average: 1.91, 2.37, 2.09

Now you’ve got the data you need to calculate the server oversellingness.

Linux Server Administration Tips

What is this Linux command?

Lost in Linux and shell commanding?

There are a number of ways to get information about a particular Linux command. Chances are you are using bash shell which is currently the most popular shell of all types of Linux distributions, therefore in a sense, what you mean by Linux commands are bash commands.

So what are the ways to know more about a particular bash / Linux command?

Let’s take Linux command ls for example

ls is probably the most frequently used linux command for listing files under a particular directory, to know more about the command ls, type:

  1. ls –help
    This would generally lists all possible usages or parameters for this command on the current screen.
  2. man ls / apropos *ls* / man -k ^ls&
    This finds and switches to man(ual) pages concerning ls command. ‘apropos’ or ‘man –k’ searches through all man pages for related information of similar commands on the command or command regular expression. This would come handy if you don’t quite remember the command name.
  3. info ls
    Same as above, but maybe more useful and the viewing / scrolling can be easier. info is usually more complete than man in that man sometimes gets you to refer to info for more information.
  4. help ls
    Finds help topics.
  5. whatis ls
    This outputs a small line of brief description of what this Linux command is for.
  6. whereis ls / which ls / locate ls
    These give the stored locations of the actual program.
  7. type ls
    Presents alias commands defined by the name ‘ls’.
Linux Server Administration Tips

How to quit vi editor?

To exit and quit vi text editor, you need to type:


To save the changes you have made and quit:


To discard the changes and quit without saving the file:


What? You have no idea what I’m talking about?!

Hosting Tips & Deals Internet Tools Linux Server Administration Tips

Dismiss unusable proxy server lists – Build your own stable socks5 proxy server and surf anonymously in minutes!

All web hosting servers with SSH access enable you to tunnel the sessions so that your local computer can act like a socks proxy. For web hosting users, browsing anonymously has never been so easy.

There’s a detailed step by step tutorial for turning your web host into a socks5 proxy server.

Basically, you use PuTTY to utilize the SSH connection to the web hosting server to be an alternative transport of all traffic between your personal computer browser (or any other web clients such as FTP programs or IM) and the destination site (such as facebook or myspace). Of course, all the transfer will be billed in your web hosting subscription.

Not bad at all, if you have some large chunks of extraly available transfer to spare from your current web hosting plan. It’s simply the most stable and usable proxy server you can get and make  for yourself, much better than the servers in all the un*available* proxy servers lists you can find online.


Linux Server Administration Tips SQL / MySQL Tips and Tutorials

Backup and recover a MySQL database under command line

Yes you can log into phpmyadmin, backup your database by simply using Export and recover it by using Import. However all lamp servers come with a max upload file size, limited by the smaller of upload_max_filesize and post_max_size while also restricted by php.ini configurations such as memory_limit and max_input_time. What if you’ve got a huge database of hundreds of thousands of records taking up a few dozens of megabytes or even more?

Use MySQL command line to fulfill the same task.

Backup a database to sqlfile.sql:

mysqldump -h localhost -u username -p dbname > sqlfile.sql

After dumping it as a SQL text file, you may want to first zip it using the following command:

tar zcf sqlfile.sql.tar.gz sqlfile.sql

And download it to your local computer to be kept safe. When an emergency occurs, upload sqlfile.sql.tar.gz to your web server and unzip it:

tar zxf sqlfile.sql.tar.gz

Now that you have sqlfile.sql, you may proceed to restore it back into database, using the command below.

Recover a database from sqlfile.sql:

mysql -h localhost -u username -p dbname < sqlfile.sql

Beware of the less than / greater than mark that’s representing operation directions.

Change localhost to your own mysql server address, username to your own mysql account username and dbname to the name of the database to be backed up or recovered. Straight enough.

Also notice that MySQL user password is not specified in the command line but you will be prompted to enter it after hitting enter.

Linux Server Administration Tips

How to count files (get the number of files) under a directory in Linux?

Just perform this command under the directory:

find . -type f | wc -l

and you will get the total number of files under it (recursively). Simply copy and paste that to do the trick.

Or if you just need to count the files directly under the current directory:

ls -f | wc -l

Which is a lot faster than the previous solution.

This should also work on all *nix OS.