Display Octal Permissions

If you’re working on the command line, listing a directory to display permissions of files is not always the most user-friendly. Here’s an example of listing the files in a directory using the ‘ls -al’ command.

$ ls -al
total 20
drwxrwsr-x  2 ulysses www-data 4096 Feb 26 13:31 .
drwxrwsr-x 10 ulysses www-data 4096 Feb 26 02:30 ..
-rw-rw-r--  1 ulysses www-data    0 Feb 26 13:31 display.txt
-rwxrwxr-x  1 ulysses ulysses   659 Dec  3 06:40 sync_com.sh
-rw-r--r--  1 ulysses ulysses   181 Feb 26 13:26 sync_db.sh
-rwxrwxr-x  1 ulysses ulysses   244 Feb 26 13:23 sync_s3.sh

There has to be a better way to display permissions?

Well, there is. It’s a command called “stat” that displays the detailed status about a file or file system. On one of the switches of the stat command, is an option that allows you to display the file status in human readable format. Here’s an example using the stat from the command line.

$ stat -c '%A %a %n' *
664 display.txt
775 sync_com.sh
644 sync_db.sh
775 sync_s3.sh

The result is a list of files in a directory with the file permissions in human readable format!

How to Rotate Apache Logs

Apache comes with a logrotate utility. You can customize the way logrotate behaves by editing the /etc/logrotate.d/apache file. The logrotate utility has many options. In this example, we are rotating the log files that are located at the /var/www/domain.com/log/ directory. We are instructing the log files to rotate monthly for a total of 24 times. We are compressing the files by zipping them. We are using the date extension as part of the filename. We are also delaying the compression until the log has been rotated at least twice. Finally, Apache is restarted.

$ sudo nano /etc/logrotate.d/apache
/var/www/domain.com/*.log {
  monthly
  missingok
  rotate 24
  dateext
  compress
  delaycompress
  notifempty
  create 640 root adm
  sharedscripts
  postrotate
    if /etc/init.d/apache2 status > /dev/null ; then \
      /etc/init.d/apache2 reload > /dev/null; \
    fi;
  endscript
  prerotate
    if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
      run-parts /etc/logrotate.d/httpd-prerotate; \
    fi; \
  endscript
}

To learn more about the logrotate utility, please visit the documentation.

PHP vs Node.js

If you would like to launch a new career as a front-end developer, which programming language would you choose? You have multiple options, but nothing could be as popular as PHP and Node.js. An article from ComputerWorld examines the strengths and weaknesses of both languages. Each language has their own pluses and minuses. PHP is simpler, with a deeper code base, easy access to databases, and it’s boosted by HHVM and the Hack language. Node.js is based on Javascript with thinner service calls. It works with JSON, and raw speed is unparalleled. Both languages has it’s own MVC frameworks. Perhaps, a hybrid solution of PHP and Node.js might be the best approach on some projects. It really depends on what you’re trying to achieve. If you want to code fast, you may choose PHP. If application raw speed is in order, then you may want to consider using Node.js.

Grub Customizer

Grub is a menu program that allows Linux users the ability to choose from a multi-boot system. The original Grub program allowed administrators the ability to edit the menu listing from the command line. Sadly, when Grub 2 was implemented, editing files no longer had the same effect. The files are being overwritten by the system. Any changes to the menu listing file is discarded.

What’s the fix?

One of the easiest way customize the Grub 2 menu listing is to use an application called Grub Customizer.

To install, perform the following commands:

$ sudo add-apt-repository ppa:danielrichter2007/grub-customizer
$ sudo apt-get update
$ sudo apt-get install grub-customizer

Once installed, access the program from the menu under Administration (Linux Mint 18).

Remove the entries you don’t want. Rename the entries to something meaningful to you.

Gitlab Community Edition

Git is the most popular version control software for managing your code. If you’re looking for the best version control system out there, Git is the pretty much the de-facto standard of version control. Although you can run Git locally without a server, you’ll need some kind of repository to share your code with others.

Enter Github. Github provide free and paid Git repositories. Github public repositories are free, while private ones require subscription. For $7 dollars a month, you can have up to 5 private repositories. For $50 per month, you can use up to 50 repositories.

If you want to run your own Git repository either on the cloud or on your own private network (it’s more secure this way), then you’ll need to look at Gitlab’s Community Edition (Github.com is proprietary). Gitlab requires that you install their software on a Linux server (I’m using Ubuntu Server).

I tried running Gitlab CE on the cheapest server ($5 per month) I can find at Digital Ocean. It works but, it’s painfully slow. I don’t recommend it. The $5 per month server only has 1 CPU core and 512 MB of RAM. I recommend that you go for a system that has 2 CPU cores and 2GB of RAM. This system will cost $20 per month.

By the way, if you don’t want managing your own server, you can simply sign up with Gitlab.com. It’s free! They offer unlimited private and public repositories up to 10GB of disk space per project. Of course, Gitlab has other products. For a paid subscription you can get enterprise support and more advanced features.

Visit Gitlab for more details.