Zip Command

Posted: May 4th, 2009 | Author: Troy | Filed under: Linux | Tags: | No Comments »

The following examples illustrate typical uses of the command zip for packaging a set of files into an “archive” file. also called “zip file”. The command uses the standard zip file format. The archive files can therefore be used to tranfer files and directories between commonly used operating systems.

zip archivefile1 doc1 doc2 doc3 This command creates a file “archivefile1.zip” which contains a copy of the files doc1. doc2. and doc3. located in the current directory.

zip archivefile1 * This command creates a file “archivefile1.zip” which contains a copy of all files in the current directory in compressed form.

However. files whose name starts with a “.” are not included. The extension “.zip” is added by the program.

zip archivefile1 .* * This version includes the files that start with a dot. But subdirectories are still not included.

zip -r archivefile1 . This copies the current directory. including all subdirectories into the archive file.

zip -r archivefile2 papers This copies the directory “papers”. located in the current directory. into “archivefile2.zip”.

zip -r archivefile3 /home/joe/papers This copies the directory “/home/joe/papers” into “archivefile3.zip”. Since in this case the absolute path is given. it doesn’t matter what the current directory is. except that the zip file will be created there.
The command unzip extracts the files from the zip file.

unzip archivefile1.zip This writes the files extracted from “archivefile1.zip” to the current directory.


Mount Points

Posted: May 4th, 2009 | Author: Troy | Filed under: Linux | Tags: | No Comments »

Below are various commands for discovering. mounting and un-mounting drives.

Command:
fdisk -l
will give you the hd* (* = number) of the Hard Drive you want to format

To format the drive. as ROOT
enter this command
mkfs /dev/hd*

Line for the /etc/fstab file:
/dev/sda1 /mnt/sdb1 auto noauto.user.owner 0 0

Mount the drive:
mount -t auto /dev/sdb1 /mnt/dev_backups


Setting File Permissions

Posted: May 4th, 2009 | Author: Troy | Filed under: Linux, PHP | Tags: , | No Comments »

Here’s a few facts about locking down the server when it comes to hosting PHP scripts.

1) No PHP file should ever require the X bit (ie. you should be able to set all PHP files to 744 - rxwr–r–)
2) All directories do need X bit so set all directories to (755 - rxwr-xr-x)

The following steps should be performed to properly set the file permissions

- chown -R user /direcory/to/receive/new/permissions
- chgrp -R group /directory/to/receive/new/permissions
- chmod -R 744 /directory/to/receive/new/permissions - (this changes all files and directories to rwxr–r–. so still need to set all directories with the X bit)
- find /dir/to/chmod/all/dirs -type d -exec chmod 755 {} \;


Secure Copy (scp)

Posted: May 4th, 2009 | Author: Troy | Filed under: Linux | Tags: | No Comments »

scp stands for secure cp (copy). which means that you can copy files across an ssh connection that will be encrypted. and therefore secured.

You can this way copy files from or to a remote server. you can even copy files from one remote server to another remote server. without passing through your PC.

Usage: scp [[user@]from-host:]source-file [[user@]to-host:][destination-file]

EXAMPLE:
scp /var/www/html/somedirectory/somezipfile.zip root@ip_address:/var/www/html/someotherdirectory
scp root@myserver:/var/www/html/somezipfile.zip root@ip_address:/var/www/html/someotherdirectory

Description of options

from-host
Is the name or IP of the host where the source file is. this can be omitted if the from-host is the host where you are actually issuing the command

user
Is the user which have the right to access the file and directory that is supposed to be copied in the cas of the from-host and the user who has the rights to write in the to-host

source-file
Is the file or files that are going to be copied to the destination host. it can be a directory but in that case you need to specify the -r option to copy the contents of the directory

destination-file
Is the name that the copied file is going to take in the to-host. if none is given all copied files are going to maintain its names

Options

-p  Preserves the modification and access times. as well as the permissions of the source-file in the destination-file
-q  Do not display the progress bar
-r  Recursive. so it copies the contents of the source-file (directory in this case) recursively
-v  Displays debugging messages

Examples

scp *.txt user@remote.server.com:/home/user/

This will copy all files with .txt extension to the directory /home/user in the remote.server.com host

scp -r miguel@10.1.2.2:/home/duder/ duder@10.1.2.3:/home/duder/

This is going to recursively copy all files from miguel’s Home directory on 10.1.2.2 host to his Home directory in 10.1.2.3 host.

Note

To use this command you need to have open-ssh installed in the hosts