Unix/Linux Notes

Copy Files on Unix Using scp (Secure Copy):

Using the unix command scp is way more reliable than any ftp client I've ever used. Just open up a shell and type:

scp -r -P 22 username@domainname.com:remotedirectory completelocalpath

to copy the remote directory remotedirectory on the remote host domainname.com to the directory completelocalpath on your local computer.

The -r means recursive since i want the entire directory with all it's contents copied.

The -P isn't always necessary, but if your ssl port is not the default, you'll need to specify it.

Creating a tar file:

tar -cvvf file.tar myfile.txt

In the above example the system would create a tar named file.tar in the directory you currently are in. Wildcards could also be used in this command, for example: tar -cvvf file.tar *.txt would compress all txt files in the current directory.

tar -cvvf home.tar home/

In the above example command the system would create a tar file named home.tar in the directory you currently are in of the home directory.

Extracting the files from a tar file:

tar -xvvf myfile.tar

In the above example command the system would uncompress (untar) the myfile.tar file in the current directory.

tar -xvvzf myfile.tar.gz

In the above example command the system would uncompress (untar) the myfile.tar.gz file in the current directory.

Grep search recursively for something

usage: grep [options] PATTERN [FILE...]
example: % grep -R 'style' ./

The example above will search the current working directory recursively for the pattern "style" returning a list of occurrences the file path, colon, preview of the file where the pattern was found.
The -R means search this directory and all directories beneath it.
The ./ means to search where I am now.

example: % grep -r -i -l 'style is dead' ./

The above example searches from the current location recursively through the directory structure (-r) for the phrase 'style is dead' ignoring case (-i) and only outputing a list of files (-l).

301 redirect one domain to another using .htaccess

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{HTTP_HOST} !^www.desireddomain.com [NC]
RewriteRule ^(.*)$ http://www.desireddomain.com/$1 [R=301,L]

The first line has to be enabled for any of this to work. While it usually is enabled by default, it can't hurt to include.
Rewrite Engine on starts the engine that does the work for us.
RewriteCond looks for a condition present. In this case we are looking for the server variable containing the domain name part of a url %{HTTP_HOST}. This example checks to see if it is NOT www.desiredomain.com !^www.desireddomain.com (case insensitively) [NC] and applies rewrite rules following it until it hits one containing [L], which stops rewrite rules based on this condition. You can have multiple rules. They happen in the order they are listed.

Now for the rule:
The rule shown tranlated means, look for the start the URL ^ to the end of the line $. Remember what follows our condition (.*). Replace our condition with http://www.desireddomain.com/ and put what followed it, back $1.
R=301 makes this a permanent redirect for Search Engine friendly redirection, L means stop redirection for this condition.

So anything hitting this site with "http://www.parkedaliaseddomain.com/myfancypage.html" would be redirected to "http://www.desireddomain.com/myfancypage.html"

 


I know how to do other stuff too. really . . . .

 

browse categories