Tealmermaid Designs

web design, coding, and SEO tips and tricks

Terminal commands for command line Linux

Terminal commands for command line Linux
Linux is a free Open Source clone of the UNIX operating system. Popular versions include Ubuntu, Red Hat Enterprise, Debian, and Fedora. Over 90% of today's internet runs on a Linux server because it is fast, free, and easy.

Many people who use Linux access the server through a shell (Terminal on a Mac). This provides access to a command prompt. Your web host may require the use of a secure shell (SSH), but you will have to check their FAQ for specifics. This simply covers the commands used by a Linux terminal to navigate your server space.

Linux terminal commands

When you open a terminal and log in, you will be the "home" directory for your user. The path is usually in the form /home/username.

Note #1: Command line directories and filenames are case-sensitive. USERNAME.txt is not the same as username.txt

Note #2: Filenames and directory names should be one word with no spaces. If you need a space, use a dash or underscore: my_directory or my_file.

Command list

To use these, simply type the command at the prompt.

CHMOD codes

CHMOD is an abbreviation of change mode. This is a UNIX command to change the permissions on a file. It is based on the Binary language. When viewed on a server, file permissions appear in the form:

aaabbbccc user filename

where a represents the permissions granted to the owner of the file, b represents the permissions granted to the usergroup of the file, and c represents the permissions granted to everyone else.

File permissions

There are four states for each permission:

These file permissions can be changed with CHMOD. This can be done at the command line in the form:

chmod abc filename

Common file permissions:

A typical HTML, PHP, or image file on a server should have its permissions set to 644 (shown on the server as -rw-r--r--. It is rare to need them to have any other permissions -- and if you do see another permission displayed, it may be that your file has been hacked.

Warning: As a rule, do not ever set any file to have permissions reading 777. This grants read, write, and execute permission to anyone who can access the file. It is just begging someone to hack your server.

.htaccess codes

An .htaccess file is a short (or not) file on your web site which exists to 'direct traffic', so to speak. When another server attempts to access any file on your site, the .htaccess file determines how to direct that server to locate the file it seeks.

Begin by creating a simple text file named .htaccess (note the beginning period). In this file you will code all the redirects needed for your site. In the absence of any code in your .htaccess file about a particular file on your server, the server will serve the requested file.

Redirection Header codes

The code for a moved or missing file has the form Redirect XXX /filename_1 /filename_2. This is useful if you delete a file, rename a file, or move a file. With an .htaccess file, you can use have your server serve an error page. The code for a error page redirect has the form ErrorDocument XXX /error-page.php.

Redirect 301 /projects_old.php /projects.php

ErrorDocument 404 /404-error.php

Hotlink allow or deny

If your referrer logs are showing that other sites are hotlinking your images, you will want to use your .htaccess to deal with this. The simplest methods are to either forbidden access entirely or respond by serving an image that indicates access to that file is not allowed.

You can code your .htaccess your server allow access to certain sites including your own.

The code for a allow/deny hotlink redirect which returns a Forbidden error has the form
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yoursite\.com.*$ [X]
RewriteRule .*\.(filetypes)$ - [F]

'Not a blank referrer, not one of the allowed non case sensitive domains, if one of these file types is requested serve a Forbidden error.'

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?tealmermaid\.com.*$ [NC]
RewriteRule .*\.(gif|jpg|png|jpeg|css)$ - [F]

The code for an allow/deny hotlink redirect which returns an image has the form
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yoursite\.com.*$ [X]
RewriteRule .*\.(filetypes)$ http://yoursite.com/nohotlink.jpe [XXX]
.

'Not a blank referrer, not one of the allowed non case sensitive domains, serve a no-hotlink image, Last Rule.'

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?tealmermaid\.com.*$ [NC]
RewriteRule .*\.(gif|jpg|png|jpeg)$ http://tealmermaid.com/nohotlink.jpe [NC,R=302,L]

Note: If you choose to serve a 'no hotlink' graphic, it will have to be a file type other than the types listed. I recommend changing the file type for this file to be something that is both unusual yet web-safe such as jpe. This can be done with any graphics app.

Tealmermaid's Treasure Grotto
Advertisement