Where is everything? Where do files go in Unix? There are no bonafide rules. But we’re free to invent some. So here are mine.
The Heap
/data – Everything starts off in this subdirectory. Consider it the Heap from which all other areas are carved out of. We’re using the term data in its most broadest sense.
/data/apps – Installed apps that don’t install themselves into the woodworks.
/data/backups – Back up files
/data/downloads – Downloaded files
/data/www – Website Root dir
Symlinks
We then symlink them to root to make them easier to get to
# ln -s /data/apps /apps
# ln -s /data/backups /backups
# ln -s /data/downloads /downloads
# ln -s /data/www /www
This gives:
/apps
/backups
/downloads
/www
Websites
/apps/crowfly – Production git master branch
/home/dlink/crowfly – Development version – git feature branches
/www/crowfly.net –> /apps/crowfly/www – A symlink to the web portion or the public portion of a production application
/www/dev.crowfly.net –> /home/dlink/crowfly/www – A symlink to the web portion of a development branch.
/www/crowfly.net/purple-bat.com –> /apps/purple-bat/www – A symlink to the web portion of an application that does not have its own domain name. It lives over the parent domain. The source code of the parent needs to list the symlink in its .gitignore file.
Backups
/backups/flower_images_20141203.tgz – A backup of images tarred and zipped – with timestamp in name.
/backups/db/books_20150220.dump.gz – A database dump, zipped – with timestamp in name. These are created like this:
mysqldump -uuser -ppass -hhost db | gzip - > /backups/db/books/20150220.dump.gz
and they are recovered like this:
alias bookdb='mysql -uuser -ppass -hhost db'
echo 'create database books' | booksdb
gunzip -c /backups/db/books_20150220.dump.gz | booksdb
Logs
There is such a long tradition of placing logs in /var/log that we don’t moved to /data.
Application Logs
/var/log/plant/plant.log – Production log
/var/log/plant/stage_plant.log – Staging Log
/var/log/plant/dev_plant.log – Development Log
/var/log/plant/dlink_plant.log – Alternative Development Log (using username)
/home/dlink/log/dev_plant.log – Alternative Development Log (using user homedir)
/var/log/plant/plant_traceback.log – Production Traceback Log
/var/log/plant/stage_plant_traceback.log – Development Traceback log
Web Logs
/var/log/apache2/crowfly.net.log – Apache Log for site.
/var/log/apache2/crowfly.net.error.log – Apache Error Log for site (periods (.) not dashes)
Advantages
What’s nice about adopting a standard for where files go on all your systems (Your local mac included) is you can easily move files around. Here is an examples.
cd /backups/db
scp flyingcrows.com:$PWD/world_2014*.dump.gz .