Vous êtes sur la page 1sur 26

bhavinmodi04@gmail.

com

1. Check the output of the following commands. Date Command: date (Displaying date and time) : UNIX has a date command that shows the date and time in the form used on the Internet. Date is a valid command, and it displays both the date and time. Notice another security feature of UNIX; the command doesnt prompt you to change either the date or time. This facility is available only to the administrator, and the strange thing is that he uses the same command.

Syntax: $date Fri $_ $date $date + %m --System Date & Time Current Month (05) Aug 19 13:28:34 IST 2005

$date + %d -Current day (25) $date + %y -Current year (1986) $date + %D -Date in format mm/dd/yy $date + %T -Time in format HH:MM:SS $date + %H -Hour $date + %M -Minute $date + %S -Second $date + %H%M%S -Hour Minute Second $echo Today date is: `date` -- Today date is: 25-05-1986 List directory command (ls): To list the name file and subdirectories of the current directory ls command is use. The order of display would be (numbers, uppercase and lowercase) ASCII collating sequence The command ls can be use along with a no. Of options. Options are the predetermine arguments use along with (hyphen) The different options force the command to work differently There should be one space between the command name and option

1 PREPARED BY :- BHAVIN R MODI | CONFIDENTIAL

There should not be any white space between the and option character Options -x : it will give multicolumn list of directory and file -r : List in to reverse order -t : List in time order -a : List all hidden files including. & .. -A : List all hidden files excluding. & .. -i : List all the files and directories with anode(Identification Number) number -c : List files and directories of which inode number are changed -R : It will give recursive list of file and directories -l : it will give the long list of file i.e. owner, size, date and time -F : it will list the directory with \ , Exefile with * , Symbolic link with @ Who command: who who Lists who is logged on your machine Options -a : --all same as -b -d --login -p -r -t -T u -b: --boot time of last system boot -H: --heading print line of column headings -l: --login print system login processes -m: only hostname and user associated with stdin -p: --process print active processes spawned by init -q, --count all login names and number of users logged on -s: --short print only name, line, and time (default)

2 PREPARED BY :- BHAVIN R MODI | CONFIDENTIAL

-t time print last system clock change -u: --users list users logged in Calendar Command: Syntax $cal [Month Number Year] cal is a handy tools that you can invoke any time to see the calendar of any specific moth, or a complete year. To see the calendar for the month of July 2009, provide the month number and year as the two argument to cal:

Month Number Year This option will show you the calendar for the particular month of particular year. To see the Aug 2009 calendar then following command will be invoked. $cal 8 2009 Above command will show you the calendar for the month of august 2009. User can see also all year calendar for the particular year for that user has to write year number after cal command. Example $cal 2009

Above command will show you 12month calendar for the year of 2009. With cal, you can produce the calendar for any month or year between the year 1 and 9999. This should serve our requirements. $cal $cal 02 2010 --Display calendar of the current month Display calendar of Feb. 2010 (Year from 1 to 9999)

3 PREPARED BY :- BHAVIN R MODI | CONFIDENTIAL

PS command:
List of all the process currently running on the system PID tty time cmd ProcessID Terminal cpu time name of process associated with process $ps f UID (User ID) PID (Process ID) $ps A or e $ps a $ps u ---give the detail list of all the process including UID PPID (Parent PID) CPU Time (in %) CMD (Process Nm)

It will give the list of all the system process only (i.e. cat,mkdir) list all the currently running user process user name

Word Count command : Print newline, word, and byte counts for each FILE, and a total line if more than one FILE is specified. With no FILE, or when FILE is -, read standard input. Syntax wc - print newline, word, and byte counts for each file wc [OPTION]... [FILE]... wc [OPTION]... --files0-from=F Options -c: --bytes print the byte counts -m: --chars print the character counts -l: --lines print the newline counts --files0-from=F read input from the files specified by NUL-terminated names in file F -L: --max-line-length print the length of the longest line -w: --words print the word counts

Cat Command:
$cat > myfile -Create the file named myfile Tis is my thousand file in unixt File name is unix Last sentences is nothing

4 PREPARED BY :- BHAVIN R MODI | CONFIDENTIAL

Ctrl + d $cat myfile -$cat myfile > testfile -$cat myfile >> testfile --

--

Save the file and return to the command prompt To view the content of file myfile Copy myfile content to the testfile Append myfile content to the testfile

File naming convention Name up to 255 character long May or may not have an extension It can contain alphabets, digits, dot (.), underscore (_), hyphen (-) anywhere It can contain both upper case and lower case alphabets File name are case sensitive MCA <-> Mca It can have as many dots embedded in the name (i.e. m.c.a.b.c.a) Name should not have white space or tab

User Name Command:


$uname $uname r $Uname s $uname n Options -a: print all information, in the following order, except omit p and -i if unknown: (Linux bic02 2.6.27-7-generic #1 SMP Fri Oct 24 06:42:44 UTC 2008 i686 GNU/Linux) -s: --kernel-name print the kernel name (Linux) -n: --nodename print the network node hostname (bic02) -r: --kernel-release print the kernel release (2.6.27-7-generic) -v: --kernel-version print the kernel version (#1 SMP Fri Oct 24 06:42:44 UTC 2008) -m: --machine print the machine hardware name (i686) -p: --processor print the processor type or "unknown" (Unknown) -i: --hardware-platform print the hardware platform or "unknown" ----linux Version of OS Name of Kernel Host Name

5 PREPARED BY :- BHAVIN R MODI | CONFIDENTIAL

(Unknown) -o: --operating-system print the operating system (GNU/Linux) Path Command: $pwd -Print Working Directory [absolute path] It will display the current working directory of a user. Make Directory:
To create a new directory this command will use.

$mkdir book $mkdir book/ch1 book/ch2 book/ch3 $mkdir sem5/AI sem5/JAVA sem5 Remove Directory $rmdir book --

Remove the directory book

--ignore-fail-on-non-empty ignore each failure that is exclusively because a directory is Change Directory $cd .. -$cd sem5 -Move to the parent directory Move to the Directory sem5 non-empty

Copy command In the first command form, copy file1 to file2. If file2 exists and you have appropriate privileges, it will be overwritten without warning (unless you use the -i option). Both file1 and file2 can be any valid filename, either fully qualified or in the local directory. In the second command form, copy one or more files to directory. Note that the presence of multiple files implies that you wish to copy files to a directory. If directory doesn't exist, an error message will be printed. This command form can get you in trouble if you attempt to copy a single file into a directory that doesn't exist, as the command will be interpreted as the first form and you'll end up with file2 instead of directory.

6 PREPARED BY :- BHAVIN R MODI | CONFIDENTIAL

Syntax cp [options] file1 file2 cp [options] files directory Options -f: Force an overwrite of existing files in the destination. -I: Prompt interactively before overwriting destination files. It is common practice (and advised) to alias the cp command to cp -i to prevent accidental overwrites. You may find that this is already done for you for user root on your Linux system. -p: Preserve all information, including owner, group, permissions, and timestamps. Without this option, the copied file or files will have the present date and time, default permissions, owner, and group. -r,-R: Recursively copy directories. You may use either upper- or lowercase for this option. If file1 is actually a directory instead of a file and the recursive option is specified, file2 will be a copy of the entire hierarchy under directory file1. -v: Display the name of each file verbosely before copying. Example 1 Copy the messages file to the local directory (specified by .): $ cp /var/log/messages . Example 2 Make an identical copy, including preservation of file attributes, of directory src in new directory src2: $ cp -Rp src src2 Copy file1, file2, file5, file6, and file7 from the local directory into your home directory (under bash): $ cp file1 file2 file[567] ~ Remove command Syntax Delete one or more files from the file system. To remove a file, you must have write permission in the directory that contains the file, but you do not need write permission on the file itself. The rm command also removes directories when the -d, -r, or R option is used. rm [options] files Options

7 PREPARED BY :- BHAVIN R MODI | CONFIDENTIAL

-d: Remove directories even if they are not empty. This option is reserved for privileged users. -f: Force removal of write-protected files without prompting. -I: Query interactively before removing files. -r, -R: If the file is a directory, recursively remove the entire directory and all of its contents, including subdirectories. -i: removes in interactive mode rm * To remove all files in current directory Move Command moves files and directories around in the file system. This command can also be used to rename the file Move or rename files and directories. For targets on the same filesystem (partition), moving a file doesn't relocate the contents of the file itself. Rather, the directory entry for the target is updated with the new location. For targets on different filesystems, such a change can't be made, so files are copied to the target location and the original sources are deleted. Note that mv is used to rename files and directories, because a rename operation requires the same directory entry update as a move. If a target file or directory does not exist, source is renamed to target. If a target file already exists, it is overwritten with source. If target is an existing directory, source is moved into that directory. If source is one or more files and target is a directory, the files are moved into the directory. mv [options] source target mv file1 file2 renames file1 with the name file2 mv file1 moves file1 to its parent directory mv file2 dir1 moves file2 into subdirectory dir1 Options -f: Force the move even if target exists, suppressing warning messages. -I: Query interactively before moving files. Difference Command Reports the differences between file1 and file2. Prints file1 text flagged (<) and file2(>). Displays line-by-line differences between pairs of text files.

Syntax

8 PREPARED BY :- BHAVIN R MODI | CONFIDENTIAL

Syntax diff file1 file2 Options -b: ignore blank spaces. -e: produce a script of commands to recreate file2 from file1, using ed editor. -D: merge file1 and file2 into a single file containing conditional C preprocessors (#ifdef). Defining symbol and then compiling yelds file2. Not defining symbol, yields file1. -i: --ignore-case Ignore case differences in file contents. --ignore-file-name-case Ignore case when comparing file names. --no: -ignore-file-name-case Consider case when comparing file names. -w: --ignore-all-space Ignore all white space. -B: --ignore-blank-lines Ignore changes whose lines are all blank. -a: --text Treat all files as text. --label: LABEL Use LABEL instead of file name. -q: --brief Output only whether files differ. -y: --side-by-side Output in two columns. --left -column Output only the left column of common lines. --suppress-common-lines Do not output common lines. -r: --recursive Recursively compare any subdirectories found. -N: --new-file Treat absent files as empty. Change Permission Mode Command Change the access mode of one or more files. Only the owner or privileged user may change its mode. Create mode by concatenating who, opcode and permission.

9 PREPARED BY :- BHAVIN R MODI | CONFIDENTIAL

Syntax chmod [options]mode files Options Following are the symbolic representation of three different roles: u is for user, g is for group, and o is for others. Following are the symbolic representation of three different permissions: r is for read permission, w is for write permission, x is for execute permission. Following are few examples on how to use the symbolic representation on chmod. 1. Add single permission to a file/directory Changing permission to a single set. + symbol means adding permission. For example, do the following to give execute permission for the user irrespective of anything else: $ chmod u+x filename 2. Add multiple permission to a file/directory Use comma to separate the multiple permission sets as shown below. $ chmod u+r,g+x filename 3. Remove permission from a file/directory Following example removes read and write permission for the user. $ chmod u-rx filename 4. Change permission for all roles on a file/directory Following example assigns execute privilege to user, group and others (basically anybody can execute this file). $ chmod a+x filename 5. Change execute permission only on the directories (files are not affected) On a particular directory if you have multiple sub-directories and files, the following command will assign execute permission only to all the sub-directories in the current directory (not the files in the current directory). $ chmod u+X * octal permission bits with chmod

10 PREPARED BY :- BHAVIN R MODI | CONFIDENTIAL

Unix file and directory permission is in the form of a 33 structure. Three permissions (read, write and execute) available for three types of users (owner, groups and others).

In the output of ls -l command, the 9 characters from 2nd to 10th position represents the permissions for the 3 types of users. -rw-r--r-- 1 admin administrator 67 2010-10-28 09:33 alpha.sh In the above example: User (admin) has read and write permission Group has read permission Others have read permission Three type of permissions: read: permitted to read the contents of directory ( view files and sub-directories in that directory ). write: permitted to write in to the directory. ( create files and sub-directories in that directory ) execute: permitted to enter into that directory. Numeric values for the read, write and execute permissions: Read 4 Write 2 Execute 1 To have combination of permissions, add required numbers. For example, for read and write permission, it is 4+2 = 6. Change File and Directory Permissions Using Chmod Command You can use either the octal representation or symbolic representation to change the permission of a file or directory. Octal representation for permissions: First number is for user Second number is for group Third number is for others For example, give read, write ( 4+2 = 6 ) to user and read ( 4 ) to group and others. $ chmod 644 filename For example, give read, execute ( 4 + 1 = 5 ) to user and read (4 ) to group, and nothing ( 0 ) to others.

11 PREPARED BY :- BHAVIN R MODI | CONFIDENTIAL

$ chmod 540 filename For example, give read, write ( 4 + 2 = 6 ) to user and nothing ( 0 ) to group, and read ( 4 ) to others. $ chmod 604 filename Default file permission: 644 Default directory permission: 755 Example chmod u+x file (add permission to the user to execute the file) chmod 751 file (chmod u=rwx, g=rx, o=x file) They are the same command. Regular Expression Regular expression as used in vi, grep, etc. Regular expressions are formed from single characters, concatenation of regular expressions, choice between two regular expressions, and zero or more occurrences of a regular expression. In UNIX, regular expressions are defined using the following Meta symbols and extensions to the regular expression notation. . [xyz] Match any single character. Match any character enclosed in the brackets.

[A-B] Match any character in the range. [^xyz] Complement: match any character not enclosed in the brackets. re* ^re re$ \\ The Kleene star: match zero or more occurrences of the Re. RE match must occur at the beginning of a line. RE match must occur at the end of line. Represent the backslash

grep command The grep command is used to read from the specified file on the command line. Syntex $grep [option] RE [file(s)] option

12 PREPARED BY :- BHAVIN R MODI | CONFIDENTIAL

-b

Display, at the beginning of the output line, the number of the block in which the regular expression was found. This can be helpful in locating block numbers by context. (The first block is block zero) Print the number of lines that contain the pattern, that is, the number of matching lines. Prevent the name of the file that contains the matching line from being displayed at the beginning of that line. Note:- When searching multiple files, grep normally reports not only the matching line but also the name of the file that contains it.

-c -h

-i -l -n -s -v Examples:

Ignre distinctions between uppercase and lowercase during comparisons. Print one time the name of each file that contains lines that match the pattern-regardless of the actual number of matching lines in each file-on separate lines of the screen. Precede each matching line by its line number in the file. Suppress error messages about nonexistent or unreadable files. Print all lines except those that contain the pattern. This reverses the logic of the search.

1. $grep i you pax corn Here the pax and corn are file name from where you want to find you or YOU because option i is indicating that ignoring case. 2. grep c you pax corn Here you want to see that you how many times repeated in the files. The output of above command will be this. Output pax : 1 corn: 5 3. grep h you pax corn Above command will shows the output for the matching lines without specifying the files from which they came. 4. grep iv you pax corn

13 PREPARED BY :- BHAVIN R MODI | CONFIDENTIAL

Above command specifies output of every line in pax and corn that does not have you or YOU. 5. grep ^The pax cron The above command finds lines that begin with The. 6. $grep n$ pax corn Above command finds lines that end with n. sed command: sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline). While in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over the input(s), and is consequently more efficient. But it is sed's ability to filter text in a pipeline which particularly distinguishes it from other types of editors. sed is a multipurpose tool which combines the work of several filters. It is derived from ed. The sed performs non interactive operations on a data stream hence its name. It uses very few options but has a host of feature that allow you to select lines and run instructions on them. Learning sed will prepare you well for perl which uses many of these feature. sed uses instructions to act n text. An instructin combines an address for selecting lines, with an actions to be taken on them, as shown by the syntax:

Syntax sed [option] address action file name Options -n: --quiet, --silent suppress automatic printing of pattern space

14 PREPARED BY :- BHAVIN R MODI | CONFIDENTIAL

-e: script, --expression=script add the script to the commands to be executed -f: script-file, --file=script-file add the contents of script-file to the commands to be executed -i[suffix], --in-place[=suffix] : edit files in place (makes backup if extension supplied) -l N: --line-length=N specify the desired line-wrap length for the `l' command -r: --regexp-extended use extended regular expressions in the script. -s: --separate consider files as separate rather than as a single continuous long stream. -u: --unbuffered load minimal amounts of data from the input files and flush the output buffers more often head command Print the first few lines of one or more files (the "head" of the file or files). When more than one file is specified, a header is printed at the beginning of each file, and each is listed in succession. Syntax: head [-n lines] files Here files is the list of the files you want the head command to process. Without the -n lines option, the head command shows the first 10 lines of its standard input. This option shows the specified number of lines instead Options -c n: Print the first n bytes, or if n is followed by k or m, print the first n kilobytes or megabytes, respectively. -l n: Print the first n lines. The default is 10. -c, --bytes=[-]N : print the first N bytes of each file; with the leading -, print all but the last N bytes of each file. -n, --lines=[-]N: print the first N lines instead of the first 10; with the lead , print all but the last N lines of each file. -q, --quiet, --silent: never print headers giving file names

tail command:

15 PREPARED BY :- BHAVIN R MODI | CONFIDENTIAL

print the last few lines of one or more files (the "tail" of the file or files). When more than one file is specified, a header is printed at the beginning of each file, and each is listed in succession. Syntax: tail [options] [files] Options -c, --bytes=N: output the last N bytes; alternatively, use +N to output bytes starting with the Nth of each file -f, --follow[={name|descriptor}] : output appended data as the file grows; -f, --follow, and --follow=descriptor are equivalent -F: same as --follow=name retry

-n, --lines=N: output the last N lines, instead of the last 10; or use +N to output lines starting with the Nth --max-unchanged-stats=N with --follow=name, reopen a FILE which has not changed size after N (default 5) iterations to see if it has been unlinked or renamed (this is the usual case of rotated log files) --pid=PID with -f, terminate after process ID, PID dies -q, --quiet, --silent never output headers giving file names -s, --sleep-interval=S with -f, sleep for approximately S seconds (default 1.0) between iterations. cut command: Cut command is used to cut or pick up a given number of character or fields from the specified file. This command is support you to see specified filed. Like you have large database information but out of them you want to see some selected fields than cut command is useful in UNIX.

16 PREPARED BY :- BHAVIN R MODI | CONFIDENTIAL

Syntax $cut [Main Options] Field or Character List [Options] File Name

Options -f -b -c This option is used to specify field list separated by TAB This option is used to specify bytes list single character taken as bytes This option is used to specify character list single character taken as character It is must that you will have to used one main option with cut command. -b, --bytes=LIST select only these bytes -c, --characters=LIST select only these characters -d, --delimiter=DELIM use DELIM instead of TAB for field delimiter -f, --fields=LIST select only these fields; also print any line that contains no delimiter character, unless the -s option is specified -n (ignored) --complement complement the set of selected bytes, characters or fields. -s, --only-delimited do not print lines not containing delimiters --output-delimiter=STRING use STRING as the output delimiter the default is to use the input delimiter -d -s This option is used to specify the character as field separator This option is used to skip the lines which does not have field separator

Example 1: $cat >> abc.txt

17 PREPARED BY :- BHAVIN R MODI | CONFIDENTIAL

1. 2. 3. (1)

one one one

two two two

three four three four three four

five five five

six six six

$cut b 1,2 abc.txt 1. 2. 3.

(This will show you given byte)

(2)

$cut b 1-4 abc.txt (This will show you range 1 to 4 byte) 1. 2. 3. o o o (This will show you given character)

(3)

$cut c 1,2 abc.txt 1. 2. 3.

(4)

$cut c 1-4 abc.txt (This will show you range 1 to 4 character) 4. 5. 6. o o o

Example 2: $cat >>abc1.txt 1:one:two:three:four:five:six 2:one:two:three:four:five:six 3:one:two:three:four:five:six

18 PREPARED BY :- BHAVIN R MODI | CONFIDENTIAL

$cut f 1-3 d: abc1.txt 1:one:two 2:one:two 3:one:two Example 3: (1) $cat >> abc.txt 1. 2. 3. one one one two two two three four three four three four five five five six six six

abcdefghijklmnopqrstuvwxyz

(2)

$cut f 1-4 abc.txt $cat >> abc.txt 1. 2. 3. one one one two two two three three three

abcdefghijklmnopqrstuvwxyz

(3)

$cut f 1-4 s abc.txt 1. 2. 3. one one one two two two three three three

Show usernames (in the first colon-delimited field) from /etc/passwd: $ cut -d: -f1 /etc/passwd Show first column of /etc/passwd: $ cut -c 1 /etc/passwd

19 PREPARED BY :- BHAVIN R MODI | CONFIDENTIAL

Paste Command: Syntax $Paste [Option] File Name1 File Name2 Options -s -d Serial Paste the lines of one file at a time rather then one line from each file. Delimiters tow files This command is used to merges lines of files. This command prints lines consisting of sequentially corresponding lines of each given files, separated by tabs, terminated by a new line. If no files are given , the standard input is used. A filename of -means standard input.

Example 1 $cat >> 1.txt 1. 2. 3. aaa aaa aaa bbb bbb bbb ccc ccc ccc

$cat >> 2.txt A) B) C) (1) AAA AAA AAA BBB BBB BBB CCC CCC CCC

$paste 1.txt 2.txt 1. 2. 3. aaa aaa aaa bbb bbb bbb ccc ccc ccc A) B) C) AAA AAA AAA BBB BBB BBB CCC CCC CCC

20 PREPARED BY :- BHAVIN R MODI | CONFIDENTIAL

(2)

$paste -d"|" 1.txt 2.txt 1. 2. 3. aaa aaa aaa bbb bbb bbb ccc ccc ccc |A) |B) |C) AAA AAA AAA BBB BBB BBB CCC CCC CCC

(3)

$paste -s 1.txt 2.txt 1. A) aaa AAA bbb BBB ccc CCC 2. B) aaa AAA bbb BBB ccc CCC 3. C) aaa AAA bbb BBB ccc CCC

(4)

$paste -s -d"|" 1.txt 2.txt 1. A) aaa AAA bbb BBB ccc CCC |2. |B) aaa AAA bbb BBB ccc CCC |3. |C) aaa AAA bbb BBB ccc CCC

Sort command: Sorts the lines in a text file. Syntax sort [option] [+fields] filename [-o output file] sort also works on fields, the default field separator is the space character. The t option, followed by the delimiter, overrides the default. This lets the user to sort on a particular field. For instance to sort the second field sort t \| +1 list #skips first field

The sort order can be reversed with the r option. Numeric sort: sort n numfile Options

21 PREPARED BY :- BHAVIN R MODI | CONFIDENTIAL

-b: Ignores spaces at beginning of the line. -d: Uses dictionary sort order and ignores the punctuation. -f: Ignores caps -i: Ignores nonprinting control characters. -m: Merges two or more input files into one sorted output. -M: Treats the first three letters in the line as a month (such as may.) -n: Sorts by the beginning of the number at the beginning of the line. -r: Sorts in reverse order -u If: line is duplicated only display once +fields:Sorts by fields , usually by tabs filename The name of the file that needs to be sorted. -o outputfile: Sends the sorted output to a file.

Uniq command: Report or filter out repeated lines in a file Syntax uniq [options] [ -f fields ] [ -s char ] [-n] [+m] [input_file [ output_file ] ]

Options -c: Precede each output line with a count of the number of times the line occurred in the input. -d: Suppress the writing of lines that are not repeated in the input. -u: Suppress the writing of lines that are repeated in the input. -f: fields Ignore the first fields fields on each input line when doing comparisons, where fields is a positive decimal integer. A field is the maximal string matched by the basic regular expression: [[:blank:]]*[^[:blank:]]* If fields specifies more fields than appear on an input line, a null string will be used for comparison. -s char: Ignore the first chars characters when doing comparisons, where chars is a positive decimal integer. If specified in conjunction with the -f option, the first chars characters after the first fields fields will be ignored. If chars specifies more characters than remain on an input line, a null string will be used for comparison. -n: Equivalent to -f fields with fields set to n. +m: Equivalent to -s chars with chars set to m. -b, --ignore-leading-blanks : ignore leading blanks

22 PREPARED BY :- BHAVIN R MODI | CONFIDENTIAL

-d, --dictionary-order: consider only blanks and alphanumeric characters -f, --ignore-case: fold lower case to upper case characters -g, --general-numeric-sort compare according to general numerical value -i, --ignore-nonprinting consider only printable characters -M, --month-sort compare (unknown) < `JAN' < ... < `DEC' -n, --numeric-sort compare according to string numerical value -r, --reverse reverse the result of comparisons find command: used to locate files in the file system it recursively examines a directory tree to look for files either by name or by matching one or file attribute.

Syntax find path_list selection_criteria action it recursively examins all files in the directories specified in path_list o (it begins the search from home) It then some action on those selected files. Finally it takes each file for one or more selection criteria. Options for selection criteria. -nmae : find with file name 1. find . name *.sh it will print all files conatins extension .sh 2. find / -name Chapter1 searches through the root filesystem ("/") for the file named "Chapter1"

23 PREPARED BY :- BHAVIN R MODI | CONFIDENTIAL

3. find . -name Chapter1 -type f To search in the current directory, and all subdirectories, just use the . character to reference the current directory in your find commands, -type : find files or directory as per type find . type d print f -> files d -> directories l -> symbolic links -inum : display files from its inode no. find . inum 3760508 (to display files with inode use command ls l) -perm : display files with their permission find . perm 000 (give octal permission for User,Group and others) find . perm 644 gives the list of files which have read and right permission for user,read and execute permission for grouop and others. find . perm -400 give the list of files for read permission of owners. -size : find the files as per given size find . size +50k it will gives the list of all files which have size more then 50 k. find . size 50k it will gives the list of all files which have size exactly 50 k. find . size -50k it will gives the list of all files which have size less then 50 k. -mtime : give the files as last modified time in days find . mtime -1 it will gives the list of all files which are last modified in less then one day. -mmin : give the files as last modified time in minute find . mmin -1 it will gives the list of all files which are last modified in last minute. -newer : give the files names which are modified after given one file find . newer <oldfilename> e.g. find . newer emp it will give the list of files which are modified after file emp. exec <command> to execute command after finding files.

24 PREPARED BY :- BHAVIN R MODI | CONFIDENTIAL

e.g. find . type size 0k exec ls l {}\; here Unix command support followed by {}\; command.

Digitally signed by BHAVIN Reason: I am the author of this document Location: Date: 08/30/12 14:48:34

25 PREPARED BY :- BHAVIN R MODI | CONFIDENTIAL

Vous aimerez peut-être aussi