Regular expressions

Regular Expressions

Regular expressions are patterns in which certain characters or character combinations are interpreted specially when being matched against a data string. grep, sed and awk treat patterns as regular expressions. For example, regular expressions allow the use of wildcards in search strings (patterns). Note that regular expressions are different from the shell’s wildcard system.

Regular expressions include:

^
start of line
$
end of line
\<
start of a word
\>
end of a word
.
any single character
.*
any character, repeated any number of times (including none)
c*
matches zero or more repetitions of the character c
\c
match character c (switch off any special meaning)
c?
match one or more repetitions of c
[agkAGK]
match any one of a, g, k, A, G, K
[0-9a-f]
match any in range 0-9 or a-f
[^string]
match any character NOT in string

Examples of patterns

^The
matches a line starting with The
\<[A-Z]
matches a word starting with a capital letter
embar?ass*
matches embaras, or any other spelling with one or more r‘s or more s‘s; also unembaras, embarased etc.
x.*y
matches x followed by y with any or no characters between

Characters with Special Meaning

Certain characters are interpreted with a special meaning by the shell. Often they can be interpreted differently depending on the context.

Examples

*
Used as a wildcard to represent any number of characters. For example, ls p* would list all the filenames in the current directory beginning with the letter p.
?
Used as a wildcard for one character only. For example ls jun??.dat would list all the files beginning with the characters jun, ending with .dat and with any 2 characters in between.
[
Used to specify exactly which characters the wildcard can be matched with only. For example, the command rm prog[2-4p-r].c could delete, if the files exist, prog2.c, prog3.c, prog4.c, progp.c, progq.c, progr.c.
~
Used to represent the full pathname of a home directory. For example, ls ~mary would list the contents of the home directory of user mary, whose full pathname could be /u0/xhul/mary.
{
Braces can be used to expand filenames rather than act as wildcards, for example rm {prog1,testing,yesterday}.c would remove the files prog1.c, testing.c and yesterday.c. Note, in the last example there should be no spaces separating the comma separated list of files.
$
Used to refer to the value of a variable or field. For example, echo $PRINTER would display the current value of the environment variable PRINTER
!
Used in command history notation. For example, !3 would reissue the command numbered 3 in your command history (if available).
&
& can be used to run a job in the background, for example f77 program.f &, would compile and link the FORTRAN program program.f in the background. && is the logical operator for AND in a programming context.
|
Pipes the output from one command as the input to another command. For example, ls -al |more, would send the directory listing output of ls as the input to the scroll command more.
<
Redirects the input of a command. For example, maple < algebra, sends the file algebra as the input to the program maple.
>
Redirects the output of a command. For example, ls > dir_list sends the output of ls to a file called dir_list.
;
Used to separate commands on the same line. For example, ls -l | more; quota would list files a screenful at a time and then list your current quota usage.
(
Used as brackets in a programming context. For example, (in C shell programming) if ($string=='Jane') then
\
To use any of the above characters in their literal sense, they need to be ‘escaped’ by preceding them with the backslash, \. For example, to display the string <*Hello*> would require echo\<\*Hello\*\>

chmod calculator


Check the desired boxes or directly enter a valid numeric number to see its value in other formats.

Permissions:

  Owner Group Other
Read
Write
Execute

Typical Chmod permissions values:

664 or -rw-r–r–  – web pages and images viewed by surfers.
666 or -rw-rw-rw-  – log files or pages that are written to.
755 or -rwxr-xr-x  – perl scripts to make them executable.
755 or -rwxr-xr-x  – directories are usually given this value.
777 or -rwxrwxrwx  – for files that are written to by all.
777 or -rwxrwxrwx  – directories that have files created inside them.

What is Owner, Group and Other?

Owner – the user/owner of a file or directory.
Group – individuals who are in the same group.
Other – users that are not the owner or part of the group.

Theme: TheBuckmaker.com Blogging Themes