Month: May 2014

Glob Patterns

man 7 glob

Glob Patterns: Globbing Pathnames

Long ago, in Unix V6, the was a program /etc/glob that would expand wildcard patterns.Soon it was built into shell and bash.

Glob Patterns

Glob (Wildcard) Matching

A string is a wildcard pattern if it contains one of the characters:

?  *  [

Globbing is the operation that expands a wildcard pattern into the list of pathnames matching the pattern.

? (not between brackets) matches any single character.
* (not between brackets) matches any string, including empty string.
Glob Patterns Character Classes

[abc]: matches any single character enclosed in the brackets (either a, b or c). The string enclosed cannot be empty hence ']' can be allowed between the brackets.

Glob Patterns Ranges

[a-z]: Two characters separated by a '-' denote a range.

[A-Fa-f0-9] denote [ABCDEFabcdef0123456789].

Glob Patterns Complementation

[!a-f]: matches a single character that is not matched by removing the first'!'. ie. The negation.

[!]a-]: matches all single characters except ']', 'a', '-'

Glob Patterns removing the special meaning

You can remove the special meaning of:

?   *   [    \

By preceding with a backslash, or if it is a shell command enclose in quotes.

Pathnames

Globbing is applied to each part of a path name seperately, the delimiter being '/'. The backslash cannot be matched by '?' or '*'.

If a filename starts with '.' It needs to be matched explicitly as `rm *` will not remove .profile.

Glob Patterns are Not Regular Expressions

They are similar however

  • Glob patterns match filenames not text
  • Conventions are not the same (regular expressions: '*' means 0 or more of the preceding thing.
  • Regular expressions use '^' as negation, POSIX defines '^' as undefined.

More on Differences

More on Gitignore type:

git help gitignore

 

Git Tutorial Part 2: Repository, Cloning, Tracking and Staging

This article gives the basics for a beginner user who needs to start tracking and contributing to projects managed with git.

The Git Repository

Initialising from an existing directory
git init

This command creates the .git directory.At this point nothing is tracked though.

git add *
git add README
git commit -m 'Initial Commit'
Cloning an Existing Repository

Cloning pulls an existing repo from a remote location to your local machine. This is usually the case when you want to contribute to an open source project. Remember the entire history is cloned. The latest copy of the project is checked our into the working directory.

git clone https://github.com/yiisoft/yii.git yiimod

The above command clones the yii framework into a folder called yiimod in the current directory.

Recording Changes

Each file in your working directory is of a certain state: tracked or untracked.

Tracked Files: In previous repo snapshot as unmodified, modified or staged.

Untracked Files: Files not in last snapshot and not in staging area.

When you first clone a directory all files will be tracked and unmodified. When files are edited they become modified, they are staged and then commited.

Checking File Statii

git status

This command tells you what branch you are on and the statii of files.

Adding a new file to the repo will give a response of:

 untracked files:

If you want to start tracking the newly added file you must explicitly:

git add <new file>

You must explicitly do so as it is possible that you application during compilation or runtime, additional unnecessary files were created.

Once you have added the file it is now staged as git status will give:

Changes to be commited:

If you modify a tracked file, without adding git status gives:

Changes not staged for commit:

This means the file is tracked and modified but not staged. If you add the modified file, the new file and modified file will show up under:

Changes to be commited:
new file: <new file>
modified: <modified file>

If you modify the <modified file> again, after git add, it will show up under both staged and unstaged changes. You will need to stage those unstaged changes.

Taken from: Pro Git