How to Make an Entire Directory Path
Question: How do I create an entire path of directories?
Answer: On a desktop computer, anytime you want to create a folder, you have to go through a series of clicks, type in the name, and press Enter. If you want to create a series of nested folders, you have to go through that process several times for each one. That is time consuming and not something you want to have to do on a server.
There are times when creating an entire path of directories may be very useful. For example, if you have a website photo gallery and want to setup the album directories, you will want to be able to quickly create those paths. You can do this easily from the command line and do not need to repeat steps.
On a Linux server, to create an entire path of directories, enter from the command line:
mkdir -p photos/2010/albums/zoo
On a Windows server, just reverse the slashes:
mkdir photos\2010\albums\zoo
This will automatically create the photos, 2010, albums, and zoo directories. With one quick command, you saved yourself four steps.
Tag: command line, directories, files, folders, linux, path, server, windows
How to Sync Two Websites on the Same Server
Question: I have two separate websites that I want to have identical data on each site. How can I do this?
Answer: First of all, to sync files on two separate sites on the same server, you will need to have a user that has write permissions on both sites. If you are using a shared hosting account, and both sites are under your account, you probably already have this. For a VPS that has a unique user for each site, you will need to use the root user.
Next, you need to know the full path to the directories for both sites. For example, site one may be /home/user/www/html/siteone.com/html and site two may be /home/user/www/html/sitetwo.com/html. To sync both directories and keep them synced even when data changes, the best choice is rsync. Although rsync is normally used for remote syncing, it also works for local directories.
To sync the two directories, you would use this command:
rsync -avc /home/user/www/html/siteone.com/html/ /home/user/www/html/sitetwo.com/html/
If you want the sync to be performed periodically and automatically, you can create a script and then drop it into one of the cron directories, such as cron.daily. You can also setup a manual cron job in /etc/crontab. From now on, both sites will show identical information.
Tag: cron, directories, hosting, rsync, server, sync, vps
How to Display Files Modified Today
There are many ways to search Linux files and directories using grep, find, or locate. All of them find files that match certain search parameters, usually words or characters. On a Linux server, you can also find any files that were modified within the current day. This is useful for finding security exploits and generally tracking website usage.
Using the find command, you can look for all files modified in a specific directory within the current day. To do so, enter the following string:
find -maxdepth 1 -type f -mtime -1
The output will look something like this:
./syslog
./lastlog
./user.log
./auth.log
./daemon.log
./mail.info
./syslog.1
To find only the directories created on the current day, simply change the “f” to a “d”:
find -maxdepth 1 -type d -mtime -1
Using this information can help you track down possible problems. Certain files like ones listed above are supposed to be modified daily, but if you find files that should not be modified, that can be a clue to help you fix whatever ails your server.
Image Source: Wikimedia Commons
Tag: directories, files, find, linux, locate, search, server
Linux file and directory structure

An important part of knowing your Linux server is knowing where directories and files are. Most Linux distributions organize files in a similar manner, following specific standards. It is very different from the Windows file and directory structure, but once you know one Linux setup, you will pretty much know the basic layout of every Linux distribution.
/ The root directory, under which all other directories reside.
/boot Here Linux stores information about booting, including the kernel itself and the bootloader.
/etc Most system-wide configuration files are kept in this directory, particularly those you use for your web server.
/bin, /usr/bin, /sbin All of these are where Linux stores executable files. This is one area where it differs depending on the software and distribution.
Read More >>
Tag: directories, file system, files, kernel, linux, root, server
Password Protecting Your Directories

Question: How do I password protect a directory on my website?
Answer: Many web hosting control panels offer a “password protect” feature for your directories. If not, there is a moderately easy way to do it with an Apache .htaccess file.
First, create an .htaccess file that looks like this:
AuthUserFile /home/yourname/.htpasswd
AuthName “Password Protected”
AuthType Basic
require user yourname
Replace “yourname” with your desired username. Next, you will need to create the .htpasswd file in the location you specified. This requires you to have an encrypted password entry:
username:encryptedpassword
Use the following form to create one: Htpasswd Generator.
Tag: apache, directories, htaccess, htpasswd, password, web hosting, website