Saturday, October 29

Sites

grep command to serch to word in file

grep (don't ask why it is called grep)


grep is one of many standard UNIX utilities. It searches files for specified words or patterns. First clear the screen, then type

% grep science science.txt

As you can see, grep has printed out each line containg the word science.

Or has it ????

Try typing

% grep Science science.txt

The grep command is case sensitive; it distinguishes between Science and science.

To ignore upper/lower case distinctions, use the -i option, i.e. type

% grep -i science science.txt

To search for a phrase or pattern, you must enclose it in single quotes (the apostrophe symbol). For example to search for spinning top, type

% grep -i 'spinning top' science.txt

Some of the other options of grep are:

-v display those lines that do NOT match

-n precede each matching line with the line number

-c print only the total count of matched lines

Try some of them and see the different results. Don't forget, you can use more than one option at a time. For example, the number of lines without the words science or Science is

% grep -ivc science science.txt

chmod command

Each file and directory is owned by a user, and each user belongs to a group. By default, users own their home directory (the current directory when the user logs in) and the contents of the home directory. Most other files and directories are owned by "root" and other special users. The user assigns a type of privilege to each file and directory owned by the user. By default, the privilege is rwxr-xr-x.


The first three characters of rwxr-xr-x indicate that the owner can read, write, and execute the file (or directory). The middle three characters indicate that all other users in the same group as the owner can read and execute the file (or directory), but cannot write onto the file (or directory), as indicated by the middle "-" character. The last three characters indicate that everyone else on the system can read and execute the file (or directory), but cannot write onto the file (or directory), as indicated by the last "-" character.

Changing file permissions and attributes

chmod 755 file Changes the permissions of file to be rwx for the owner, and rx for

the group and the world. (7 = rwx = 111 binary. 5 = r-x = 101 binary)

chgrp user file Makes file belong to the group user.

chown cliff file Makes cliff the owner of file.

chown -R cliff dir Makes cliff the owner of dir and everything in its directory tree.

You must be the owner of the file/directory or be root before you can do any of these things.