Character classes
Character classes are an important component of regular expression. It is used for specifying which characters are acceptable at particular point or which are not. With character classes, you can specify characters individually or give a range of allowable characters. More over with the character classes you can negate the characters which are not acceptable. Some of the character classes are given below:
1. Simple Classes ( [ ] ):~
The most basic form of a character class is to place a set of characters side-by-side within square brackets. For example, the regular expression “[bcr]at” will match the words "bat", "cat", or "rat" because it defines a character class (accepting either "b", "c", or "r") as its first character. Here “[bcr]” is a simple character class.
Enter your regex: [bcr]atEnter input string to search: bat
I found the text "bat" starting at index 0 and ending at index 3.
Enter your regex: [bcr]at
Enter input string to search: cat
I found the text "cat" starting at index 0 and ending at index 3.
Enter your regex: [bcr]at
Enter input string to search: rat
I found the text "rat" starting at index 0 and ending at index 3.
Enter your regex: [bcr]at
Enter input string to search: hat
No match found.
In the above examples, the overall match succeeds only when the first letter matches one of the characters defined by the character class.
2. Negation ( ^ ):~
One of the other most important character class which is widely used is the negation character class. It is used to match all characters except those listed, insert the "^" metacharacter (called leading caret) at the beginning of the character class. This technique is known as negation. In the given regular expression, the “[^bcr]” is a character class.
Enter your regex: [^bcr]atEnter input string to search: bat
No match found.
Enter your regex: [^bcr]at
Enter input string to search: cat
No match found.
Enter your regex: [^bcr]at
Enter input string to search: rat
No match found.
Enter your regex: [^bcr]at
Enter input string to search: hat
I found the text "hat" starting at index 0 and ending at index 3.
In the given example I apply the negation on “b”, “c” and “r”. The regular expression engine matches all the character except those which is started from above three and displays on the screen. For example when I enter the search string “bat”, “cat” and “rat” the regular expression engine does not find it and when I enter “hat”, it shows that the character found.
3. Ranges ( - ):~
Sometimes you'll want to define a character class that includes a range of values, such as the letters "a through h" or the numbers "1 through 5". To specify a range, simply insert the "-" metacharacter between the first and last character to be matched, such as [1-5] or [a-h]. You can also place different ranges beside each other within the class to further expand the match possibilities. For example, [a-zA-Z] will match any letter of the alphabet: a to z (lowercase) or A to Z (uppercase).
Here are some examples of ranges and negation:
Enter your regex: [a-c]Enter input string to search: a
I found the text "a" starting at index 0 and ending at index 1.
Enter your regex: [a-c]
Enter input string to search: b
I found the text "b" starting at index 0 and ending at index 1.
Enter your regex: [a-c]
Enter input string to search: c
I found the text "c" starting at index 0 and ending at index 1.
Enter your regex: [a-c]
Enter input string to search: d
No match found.
Enter your regex: foo[1-5]
Enter input string to search: foo1
I found the text "foo1" starting at index 0 and ending at index 4.
Enter your regex: foo[1-5]
Enter input string to search: foo5
I found the text "foo5" starting at index 0 and ending at index 4.
Enter your regex: foo[1-5]
Enter input string to search: foo6
No match found.
Enter your regex: foo[^1-5]
Enter input string to search: foo1
No match found.
Enter your regex: foo[^1-5]
Enter input string to search: foo6
I found the text "foo6" starting at index 0 and ending at index 4.
4. Union ( [ ][ ] ):~
You can, however, combine character classes to form new types of patterns. For instance the following regular expression
Letters from 19[89][2-5].
With this pattern, any year whose third digit is an 8 or 9 and the final digit between 2 and 5, inclusive, will be matched. Thus, these are the potential matches for the previous regular expression pattern:
Letter from 1982
Letter from 1983
Letter from 1984
Letter from 1985
Letter from 1992
Letter from 1995
As you can see from the output that the third digit of the year is lie between 8 and 9 and the final digit lie between 2 to 5.
Some of the other short method of character classes are given below:
Sr. No Symbol Function
1. \d Any digit [0 – 9]
2. \D Any non digit [^0-9]
3. \w Any alphanumeric [a-zA-Z0-9_]
4. \W Any non-alphanumeric [^a-zA-Z0-9_]
5. \s Any space [ \t\n\r\f]
6. \S Any non-space [^ \t\n\r\f]
For example this can be used as
Enter your regular expression [\d]Enter input string to search: 1
I found the text "1" starting at index 0 and ending at index 1.
And so on.
The File system in UNIX and Linux
As you know very well that a file is a collection of related information. Similarly a UNIX file is a storehouse of information; for the most part it is simply a sequence of characters. UNIX places no restriction on the structure of file. A file contains exactly those bytes that you put in to it – be it a source program, executable code or anything else. It neither contain its own size nor its attributes, including the end of file marks. It does not contain its own name. In UNIX and LINUX, the hard disk, printers, tape drive, CD – ROM drive or terminals even shell is also treated as a file.
There are three types of files exists in UNIX and Linux. These are given below:
(1) Ordinary file: Also known as regular file. It contains only data as a stream of characters.
(2) Directory file: A folder containing the names of other files and subdirectories.
(3) Device files: It represents all hardware devices.
Moreover, you can not directly put something into a directory file, and a device file it is because it is not really a stream of characters.
Ordinary file
The traditional file is of the ordinary or regular type. It consist of a stream of data resident on some permanent magnetic media. This includes all data, source programs, object and executable code, all UNIX commands, as well as any files created by the user. The most common type of ordinary file is the text file. This is just a regular file containing printable characters.
Directory files
A directory file contains no external data but maintains some details of the files and subdirectories that it contains. The UNIX file system is organized with a number of such directories and subdirectories, and you can also create them as and when you need.
A directory file contains two fields for each file - its name and identification number ( every file has a number called the inode number). If a directory houses, say, 10 files, there will be 10 such entries in the directory files . You can’t write directly into a directory file; such power is given only to the kernels. When an ordinary file is created or removed, its corresponding directory file is automatically updated by the kernel with the relevant information about the file.
Device files
UNIX and Linux are such kind of operating system that treat the physical devices as a files. This definition include printers, tapes, floppy drives, CD – ROMs, hard disks and terminals. The files which control these devices are called devices files. The device file is special; it does not contain any data whatsoever. Any output directed to it will be reflected onto the respective physical device associated with the filename. They perform the activity like printing files, installing software and many more.
The File Name
On most UNIX systems today, a filename can consist of up to 255 characters i.e a file name in unix can contain only up to 255 characters. If you enter more than 255 characters when specifying a filename, only the first 255 characters are effectively interpreted by the system as a file name. Some system, however, report an error message.
Files may or may not have extensions. Just as you can have a filename beginning with a “dot” , you can have one which ends with a “dot” too. All these are valid file names:
Infect you should use only the following character when framing filenames:
1. Alphabets and numerals (a to z or 0 to 9)
2. The periods ( . )
3. The hyphens ( - )
4. The underscore ( _ )
A file can have many dots embedded in its name for example “a.b.b.b.b” is a perfectly valid filename. A filename can also begin with a dot or end with one.
Unix is sensitive to case; chap1, Chap1 and CHAP1 are three different file names, and its possible for them to coexist in the same directory.
The Parent Child Relationship
All files in UNIX are related to one another. The file system in UNIX is a collection of all these related files (ordinary, directory and device files) organized in a hierarchical structure. This system has also been adopted by Windows and DOS.
The top is called ROOT, and is represented by a / (frontslash). root is actually a directory file, and it has all the subdirectories of the system under it. These subdirectories, in turn, have more subdirectories and other files under them. The block diagram of Parent child relationship is given below
The Unix File system
Lets see what directory store what kind of data:
1. /bin and /usr/bin : These are the directories where all the commonly used UNIX commands are found.
2. /sbin and /usr/sbin : It there’s a command that you can’t execute but the system administrator can, then it would probably be in one of these directory.
3. /etc : This directory contains the configuration files of the system.
4. /dev : This directory contains all device files.
5. /home: All users are housed here , romeo. Would have his home directory in /home/romeo.
6. /tmp : The directories where users are allowed to create temporary files. These files are wiped
away regularly by the system.
7. /var : The variable part of the file system. Contains all your print jobs, mail queues and incoming mail.
8. /lib: Contains all library files.
File Access Permissions
There are types of files in UNIX. They are directory files, ordinary files and special files(device files). We will be dealing with directory and ordinary files only. Whan a user wants to access the permission to access any file, he/she must take permission to the owner of that fike. The output of the 1s -1 command shows the details clearly. Ordinary files start with “-” and the directory files start with “d”. Hence in the following example girl and air.c are ordinary files while ashadir is a directory file.
EXAMPLE
$ 1S -1
Total 3
-rw-r—r-- 1 anu student 10 Jan 1 10:39 girl
drwxrwxr-- 2 anu student 80 Jan 10 15:30 ashadir
-rwxrwxrwx 1 anu student 40 Jan 13 20:40 air.c
$ _
When any user creates a file, the creator is said to be the owner of that file. We can perform any operation like delete, edit or copy on that file. If a user wants other people to access his/her files, then permission has to be granted by the owner of the file. This way LINUX helps in the security of files.
There are various types of permissions available. They are read (r), write(w) and execute (x).
Read permission is used to display, copy or to compile a file. Write permission is used to write, edit or to delete a file. Execute permissions are used to execute a file.
The 1s -1 option gives the list of permissions granted to each file . The first column of the 1s -1 command gives a list of permissions granted to all those associated with any LINUX/UNIX file.
The first three characters indicate the permission of the owner of the file. The next three position indicate the permissions of the group and the last three the permissions for others
As you see in the given example there are lots of coloum. Each coloum specify some special meaning.
Here :
I : File type and permission
II: Links (1 for File and 2 for Directory)
III: Ownership
IV: Group ownership
V: File size in Bytes
VI: Last modification and access time
VII: File name
In the given exaple the file girl (ordinary file) can be read and write by the owner but not execute by him, only read by the group members of the owner and read by the others.
Changing the FAP (File Access Permission) of a file:
We can change the mode of any file or directory using the “chmod command”. Continuing with the above example of the output of 1s -1 option, let us take the “air.c” file. Suppose the user wants to revoke (denied) the execute permission, then the command is,
$ chmod -x air.c
$ _
If the user wants to grant the execute permission, then
$ chmod +x air.c
$ _
The granting and revoking of permission can be done together also like +wx for write and execute permission and –wx for revoking write and execute permissions.
FAP can be changed for one particular category or for all users. This is done by specifying the name of user before the “+/-“ sign.
‘u’ - granting or revoking of permission for the owner of the file only.
‘g’ - granting or revoking of permission for the group who need to share that file only.
‘o’ - granting or revoking of permissions for others only.
“Vi” Editor
UNIX Editor
An editor is a utility program that is used to make modification to the contents of a file or files. No doubt, editing is one of the most frequently used capabilities of a general purpose system. An editor is designed to deal with text files. Many users prefer to use an editor to create or modify their files. Therefore, an editor interactive utility program by which the user can make any changes that can be viewed by that time.
UNIX provides basically three types of editors in almost all its versions: “ed”, “ex”, and “vi”. The “ed” also known as “line editor” and was the first editor. The “ed” editor assigns line number to each line in the file. The “ex” editor is an improved version of an ed editor. The “vi” editor stands for visual editor, which is more popular than the earlier tow editors “ed” and “ex”.
The “vi” editor is developed by the University of California at Barclay by Bill Joy when he was a student there.
The “vi” editor is a Screen editor rather than a line editor that allows the user to see some part of his file on the terminal’s screen. The “vi” editor shows the user as much of the file contents as it can fit on the screen. The vi editor is the first full screen editor.
“vi” Editing Modes
The “vi editor works in three different modes:
(i) Command mode:
When the vi editor is started, it is placed in command mode. In the command mode, whenever the user presses any key, it is interpreted to be editor command. Note that the keys, that are hit, are not displayed on the screen in command mode.
(ii) Text Input Mode:
This mode is used when a new text is added; existing text is edited or replaced. We can not come to text input mode directly. We change over from the command mode to text mode with any of the following subcommands: The a, A, s, S, i, I, R, o, O, c, C commands. After using one of these commands, we can enter the text.
After completing the text work, we can return to command prompt by pressing either the “Esc” key or the “Ctrl – c”. This mode is also known as “Insert mode”.
(iii) The ex Command Mode:
The subcommand with the prefix : (colon), ? (question mark), / (Slash), or !! read input on a line displayed at the bottom line of the screen. The bottom line of the vi screen is called the command line.
All commands entered in the ex command mode are displayed in the command line. The vi editor uses the command line to display messages and commands. Enter key is pressed to execute the subcommand or interrupt (Ctrl – c) key to cancel it.
Introduction to "vi" editor
The vi editor is invoked by executing, just like any other UNIX command, along with the filename as:
$ vi filename
After typing this and pressing Enter key, the contents of the specified file are stored into the edit buffer. The terminal screen is cleared, a window is displayed in which you can enter and edit text, and the cursor is initially set at the first character of first line in the window.
Suppose you would like to create a file “punit” then invoke the vi editor as:
$ vi punit
It clears you previous contents of the screen and displays a window as shown in figure.
_ ~ “rohit “ |
Except the first line and the last line, the window shows a character ~ (tilde), the symbol of empty line. The first line has an underscore (_) in the first colon that waits for a command to enter by you.
By default the vi editor is placed in command mode and that’s why it waits for you to enter a command. If you want to insert text to the file “punit” then press “i” key to enter the insert mode of vi. When you press the “I” key, it is not displayed on the screen. Now you can enter the text whatever you want to insert in figure.
Rohit Sharma Mukesh kumar Ajay kumar ~ ~ “rohit” 3 lines and 31 characters |
After typing these names, press the Esc key to return the command mode from the current mode.
Editing a file
If you want to edit a file then it is necessary to load the file from a disk into buffer and then move to the part of the file you want to edit. And it is achieved as:
$ vi punit
The vi program will clear your screen and fills it with file you are editing as shown in figure.
The cursor is placed at first character of the first line. You can move the cursor by using the different commands.
rohit Sharma Mukesh kumar Ajay kumar ~ ~ “rohit” 3 lines and 31 characters |
Moving within a file
Following screen command are used to move the cursor.
h moves the cursor one character to the left
I moves the cursor one character to the right
K moves the cursor one line up while it remains in the same column character to the left
J moves the cursor one line down while it remains in the same column character to the left
Diagrammatically it may be represented as:
These commands are displayed on the screen. The current window screen contains only the contents of the file. After placing the cursor to the right position you can edit the file. Unfortunately if you see these commands on the screen then it means that you are still in insert mode. Therefore, firstly press Esc key to return back to command prompt and then try these motion commands again. You can also proceed h, j, k, l command with numbers that allows you to move the cursor a corresponding number of spaces or lines. Let you want to move 4 lines down then either press “j” four times or just type 4j and press the Enter Key.
Some other commands that help in positioning the cursor :
Backspace one character left
Spacebar one character right
$ moves the cursor to the end of the current line
+ moves the cursor up to the beginning of next line
Adding Text
The first thing you have to do is that place the cursor at position where you want to add and then press ‘a’. The ‘a’ stands for append. Now whatever you will type is appended to the text buffer after the current cursor position.
Now when you press Esc key, the cursor returns back to the last character you entered. It tells you that you are no longer in insert mode.
The vi editor provides another command ‘i’ command that works similar to ‘a’ command. The only difference between the ‘a’ and ‘i’ command is that it inserts the new characters before the current cursor position. Therefore after pressing ‘i’ whatever you type, it will be added to the left of the characters on which your cursor is placed
Deleting Text
The vi editor provides two commands, ‘x’ and ‘dd’, that delete text. If you want to delete a character then firstly place the cursor at the appropriate position. and then press ‘x’ key. After pressing ‘x’, the character at the current cursor position will disappear and the rest of the line would be moved one position left side.
If you want to delete the 4 characters of a line then just type 4x, this delete the four characters of the current line and move the line to the left side.
Whereas ‘dd’ command is used to delete the complete line. You can also used numbering with “dd” command. e.g if you want to delete 3 lines, then just press ‘3dd’, it will delete the 3 lines of the files.
Undo command
UNIX also provide undo command. For this we use character ‘u’. Suppose after deleting three lines, you think that you had to delete one line only instead of three lines then use an ‘u’ command to get back the most recently deleted lines.
Overwriting Text
The vi editor provides a ‘R’ command to overwrite the existing contents of a file. Therefore, whenever you want to overwrite, place the cursor at that special position and then press R. Now whatever you type next would be overwritten the existing text at the current cursor position.
Saving a file
The vi editor also provides the ‘ZZ’ (capital in nature) command to save all the changes that you make to the file and quit. This command is used in command mode.
Moving from word to word
The vi editor provide the facility of moving the cursor from word to word such as using ‘w’ command for next word and ‘b’ command for previous word. Some commands are given below:
w moves the cursor to the first character of next word.
b moves the cursor to the first character of previous word.
e moves the cursor to end of the current word.
Scrolling command
Scrolling is the property of a video terminal that makes the top line to leave the screen as each new line is displayed at the bottom. The vi editor provide following command for scrolling purpose
Ctrl – U Scroll up one – half screen
Ctrl – D Scroll down one – half screen
Ctrl – F Scrolls forward one screen
Ctrl – B Scrolls backward one screen
Block Commands
The commands that we have discussed so far deals with a single character, single word or a single line. The vi editor provides block commands to work on a group of lines rather that on a single line. For example, we may copy a group of lines from one part of a file to another part, delete a group of lines from a file by using a single command. The block command are used to work in ex command mode only. Although it is not necessary to associate line numbers with the text because block commands work on line number on which they are supposed to operate.
For example you have a file that contain 20 lines and you want to delete lines from 6 to 10, then you use the command;
6, 10d
Such command delete the 6 to 10 lines.
The vi editor provides a command ‘set number’ or ‘set nu’ in the ex command mode that enables you to display line number. Thus if you are in command mode and want to display line number then press the colon (:) key that takes you in ex command mode. Now the cursor is placed at the bottom line of the screen and you type in the command:
(Esc): set number
Or
(Esc): set nu
The vi editor provide some other useful block commands as:
- :m,n w file: This command writes lines m to n to a file.
- :m,n w>> file: This command appends lines m to n to a file.
- :r files: This reads contents of the specified file at current cursor position.
- :r! command: It executes shell command and output of the command is read at the current cursor position.
What is Face book ?
Face book is a popular social networking site which helps people to connect with different groups of people which includes known as well as unknown people. It allows you to add friends, send private message to them and update your profile with your current status to let people know about you. Face book is used internationally and managed by face book, Inc privately. It lets you join networks organized by different social groups, schools, colleges etc. Face Book is a channel to communicate with people efficiently. Millions and Billions of people spend time on face book every day. Now -a -days who would not like to increase their social connections which will not only help them to make friends but also allows them to promote and advertise their products, websites or blogs. Face book agrees to post your URL (link), this way you can utilize the opportunity to advertise your link to the fullest. Main intention of Face Book Inc to introduce face book is to help people build online communities and share common interest or activities with each other. It is basically never-ending stream of information sharing.
What are the features of Face Book-?
1. Face Book helps to promote your own web links and allows you create a simple blog or you can merge with your existing blog into face Book’s blog.
2. You can upload your Photos or friends’ photo and create photo albums to your profile.
3. Face Book being a social networking site will help you keep track of all your friend’s activities, blogs, profile updates etc.
4. Through face book search option you are allowed to search for people and ass them as a friend.
5. The best option in face book is, you can play games and earn extra coins or points. Games like Farmville which is fertilizing on your neighbor’s crops, you can send cause invitations like stop animal cruelty or funny and interesting topics like mafia war request and ask people to join your cause.
Face Book does not restrict any age group to join; it is absolutely free access website and completely user friendly. Face Book user should remember that it might get little difficult when friend request keeps coming in, there are chances of getting over crowded, however you have an option of accepting or declining request . Therefore the best option for you to be on a safer side would be, being careful while uploading photos or creating photo albums so that it is not misused. Be alert while sharing private messages because once the message is posted on the face book wall, it will be viewed by all your friends. Though face book allows you to set privacy settings but it cannot stop showing the photos or message exchanges with your friends. Some individuals might get too addicted with face book culture which is not advisable because spending so much time only on one website might prove to be a massive disadvantage. You can make face book experience pleasant by being aware of all the disadvantages and protect it by using the available tools on face book and by being little careful.
If you are planning to make carrier in the field of networking, t is important to have some understanding of various networking jobs that you are likely to encounter and whatthey require. Actually job requirements will vary widely between different companies abd for different established network.
The following descriptions are overviews the responsibilities or duties of each Network job.
Network Administrator :
Network Administrators are responsible for the operations of a network or in big companies, key parts of the network. Network Administrator are responsible to the continued efficiency of computer workstations, network servers and desktop computers of organizations.
Responsibilities or duties of Network Administrator are :
Install and configure new LAN servers and user workstations.
Directory service management is key responsiblity of Network Administrator.
Perform and manage regular backups for servers and user workstation file systems, helps users recover lost or deleted files.
Provide basic LAN management and trouble-shooting, using tools like cable break detectors, network protocol analyser and network management software.
Install new and upgraded application and utility software, like word processing. spreadsheets, and e-mail.
Creating, Maintaining and Removing users accounts.
Adding new networking equipments, such as servers, routers, hubs, and switches and managing those equipment.
Provide or co-ordinate user support, training and help.
Implement Network and file security,accounting and management.
Managing the Administrative accounts and their passwords.
Monitoring the network, its hardware and software problems.
Planning network upgrades.
Network Administrators are also called as Sysetm Administrators, or LAN Administrators. There duty is to ensure that networks, systems and services are available to users and that information is processed and transfered correctly, preserving its integrity. He also plays a part in monitoring compliance with policies, which apply to the system. For example some organizations may prohibit the sending or viewing of particular types of material or may restrick access to certain external sites, or ban certain services from local system or networks.
Network Engineer :
Network Engineers are more deeply involved in bits and bytes of a network. It is a person who takes care of Network for smooth functioninf of Network. He or she works under Network Administrator. Network Administrator must have knowledge of hardware as well as software.
Responsinilities of Network Engineer are :
Network Engineer is responsible for network and network services, design and implementation.
He is also responsible for the daily operations, support and Administratoristration of these networks and services.
His responsibilities include Administratoristration support, tunning, troubleshooting, monitoring and fault detection ofnetk.
To solve the problems of Network operating system(NOS).
Network Engineer are troubleshooters of last resort, to diagnose and fix the most of the problems in the network.
He is regularly expected to evaluate new hardware and software technologies and present analysis and purchase recommendations to the Administratorstration team and to management.
Network Architect :
Network Architect is also called Network Designer. The job of Network Architect is to design network as per need. When designing network they must understand the business needs, and all networking product available. He is also important when upgrading he Network. He must ensure that new addition or replacement in existing network don't cause any problems elsewhere in the network.
Responsinilities of Network Architect are :
Design a network as per business need.
To choose the reliable hardware and software for new network.
To provide reliability to user data.
Design network in such a way to reduce cabling length.
To choose correct location for Network server and it's related hardware.
Select proper cable topology.
Select proper cable type of interconnecting nodes.
To provide support when upgrating existing network.
More Articles …
Subcategories
Web Hosting
Web Hosting is a service offered by web hosting providers to the individuals and organizations to make their websites accessible on the internet. Depending on the requirement, one can avail different types of web hosting such as shared hosting, dedicated hosting, virtual private hosting, cloud hosting etc.
Page 163 of 193