Linux Files and Directories

September 24, 2017 | Author: G.R.THIYAGU ; Oracle DBA | Category: Computer File, Filename, Utility Software, Information Retrieval, Areas Of Computer Science
Share Embed Donate


Short Description

Download Linux Files and Directories...

Description

Files Directories and Permission Settings in Linux LINUX FILES Each file belongs to a specific user and group. File names can be up to 256 characters . Every FILE/DIRECTORY in Linux has access permissions. There are three types of access READ/ WRITE/ EXECUTE. When listing a file, there are 10 characters that they indicate type and permissions of the file. 1

2

3

FILE

User permissions

Group Permissions

Other Permissions

Type

read

read

read

write

4

execute

5

6

write

7

execute

8

9

10

write

execute

These commands cat/more/less/head/tail that can be used to view a file in linux. pico/vi/ued/ed/vim these are editors a file in linux. Commands are used to display content of files but different ways. $ cat script.sql Cat displays contents of the file. $ more script.sql More display contents page wise only in downward direction. (Hitting Enter = One Line Down, Spacebar = Page Down, q=quit) $ less script.sql Displays content pagewise in both upward and downward. Hit q = To quit. $ head script.sql display first few lines of the file. $ tail script.sql display last few lines of the file. Successful People in life seem to like LINUX

Page 1 of 29

Files Directories and Permission Settings in Linux File Creation and Text Editors in Linux Command cat also using to create a file. To save a file ( CTRL + D). $ cat sample.txt = To view a a text file $ cat > sample.txt = To create a simple text file. $ cat >> sample.txt = To append (add) existing text file.

The vi Editor (Visual Editor) The

vi is case-sensitive. We can use vi editor to edit an existing file or to

create a new file. In vi the mouse cannot be used to move cursor. vi has two modes: “the command mode” and “the insert mode”. vi always starts out in command mode. Htting “I” to enter the insert mode. If we wish to leave from the insert mode and return to the command mode, hit the ESC key. Create a Text file using vi /vim Text Editor $ vi $ vi samp.sh Text Editor Commands (Moving Within a file ) Moving one character at a time “ Direction keys” to move up , down , left and right in text editor. Command

Description

k or -

Move up a line

j or +

Jump down a line

l or space

Move to the right

h or backspace

Move to the left

Successful People in life seem to like LINUX

Page 2 of 29

Files Directories and Permission Settings in Linux Moving among Words and Lines Command

Description

e

Move to the end of the word

w

Move forward to the beginning of a word

b

Move backward to the beginning of a word

Screen Movement Command

Description

H

Moves the cursor to top of the screen

M

Moves the cursor to middle of the screen

L

Moves the cursor to last line of the screen

Deleting/Cutting - Characters, Words, and Lines Command

Description

x

Delete a character from a file.

X

Deletes the character to the left of the cursor

D

Delete from the cursor position to the end of the line

dd

Deletes the current line

dw

Delete from the cursor position to the end of the word

5j= Would move down 5 characters 4dd = Deletes four lines. 5dw = Deletes 5 words 10x = Delete the character selected and the next 9 characters 10X = Deletes the 10 characters to the left of the currently selected character d^= Deletes from current cursor position to the beginning of the line Successful People in life seem to like LINUX

Page 3 of 29

Files Directories and Permission Settings in Linux Copy and Paste Commands. Command

Description

yy

Copies a word into a buffer ( 3yw copies 3 words )

yw

Copies a line into a buffer ( 3yy will copy 3lines )

p

Puts the copied text after the cursor.

P

Puts the copied text after the cursor.

ctrl f = scrolls down one screen ctrl b=scrolls up one screen L= Bottom line Editing FILE Commands Command

Description

I

Inserts text before current cursor location

I

Inserts text at beginning of the current line

a

Inserts text after current cursor location

A

Inserts text at end of the current line

o

Open a new line above cursor

O

Open a new line below cursor

J

Joins two lines together

Replacing Characters, Words, and Lines Command

Description

R

Replace character at cursor

R

Overwrite current_line starting at cursor

cw

Changes and replaces the current word

A

Inserts text at end of the current line

u

Undo the last command

Successful People in life seem to like LINUX

Page 4 of 29

Files Directories and Permission Settings in Linux Closing and Saving Files Command

Description

:q!

Quits without saving

zz or :wq

Save the changes and quit

:w!

Saves the current changebut doesn’t exit from vi

a

Inserts text at end of the current line

Searching and Substitution Replacing Text : /oracle = search forward for the string 'oracle' ?oracle = search backward for the string 'oracle'

:1,$s/string1/string2/g or :%s/oracle/ORACLE/g substitution command (:s/) enables to quickly replace words or groups of words within the file. Here word oracle is changed to ORACLE. g stands for globally global replacement of sting1 withstring2. Some Additional commands set term=Prints terminal type > = shift contents of line one tab stop to the right 2l = Go to 2nd character in the line from the current place. G or shift g = To last line of the file , gg = Top line of the file. $ = Move to the end of the line 0 = Move to beginning of the line Command touch is used to change the timestamp of a file. Using touch command we can create files. $ touch f1 f2 f3 . Successful People in life seem to like LINUX

Page 5 of 29

Files Directories and Permission Settings in Linux Getting help = whatis /man / info/whereis/help/which. whatis = It is a helping command that provides a short description about command. Linux provides help tools to make familiar with any command. $ whatis rmdir rmdir

(1) - remove empty directories

rmdir

(2) - delete a directory

man/ info command provide a manual (long notes) about the command. manual entries online. Man command will be described in one sentence and some times in paragraphs. $ man rmdir $ info rmdir $ whereis $ORACLE_BASE Adding User and Setting Password # useradd sam Creating user and changing password can be done by # root user not by local user. # indicates root user i.e. “ SUPER USER “. # passwd sam Changing password for user sam New UNIX password: Retype new UNIX password: passwd: all authentication tokens updated successfully

Successful People in life seem to like LINUX

Page 6 of 29

Files Directories and Permission Settings in Linux Set User account disables date # useradd -e # useradd -e 2013-12-31 sona Can set date for the account to be disabled in the format YYYY-MM-DD With -e option when creating account itself. Set Default Password Expiry # useradd -e YYYY-MM-DD -f # useradd -e 2012-11-14 -f 2 sona -f{days} indicates the password expires until the account is disabled. If 0 specified, the account is disabled immediately after the password expires. If -1 specified, the account is not be disabled after the password expires. To find all users $ cat/etc/passwd or $ more/etc/passwd or $ less/etc/passwd

$ awk -F':' '{ print $1}' /etc/passwd

,

$ cat /etc/passwd | cut -d":" -f1

$ cat /etc/passwd | wc -l ( total count only)

Adding Groups & Finding Groups in Linux # groupadd # groupadd oragroup $ less /etc/group , $cat /etc/group , $more /etc/group

Successful People in life seem to like LINUX

Page 7 of 29

Files Directories and Permission Settings in Linux Finding User name starts with „r‟ $ grep -i " ^r " /etc/passwd

Linux Wildcard Search Wildcard allows users to search for or use multiple files with similar names. Wildcards with any command that accepts file/directory name as arguments. Wildcard

Matches

*

zero or more characters

?

exactly one character

[abcde]

exactly one character listed

[a-e]

exactly one character in the given range

[!abcde]

any character that is not listed

[!a-e]

any character that is not in the given range

{debian,linux}

exactly one entire word in the options given

Examples for wildcard Search $ cp [A-Z]* dir2 Copies all files, that begin with an uppercase letter, to directory dir2: $ rm *[!cehg] This deletes all files that don't end with c, e, h or g $ ls hda[0-9] list all files & dir names begin with hda, followed by exactly one numeral $ rm junk.??? removes all files names begin with junk., followed by exactly three characters Successful People in life seem to like LINUX

Page 8 of 29

Files Directories and Permission Settings in Linux $ mv *linux*.html dir1 Moves all HTML files, that have the word "linux" from the working directory into a directory named dir1. $ ls hda[0-9][0-9] lists all files or dir beginning with hda, followed by exactly two numerals $ ls {hd,sd}[a-c] Lists all files or directories whose name starts with either hd or sd, followed by any single character between a and c $ ls *gif Would list all the files having the letters ' gif ' in them. So a file named somegifs.txt as well as a file named 123.gif would be listed in the output. $ ls *.gif Lists all the files having ' gif ' as the extension of their filename. Thus in this case a file named somegifs.txt file would NOT be listed since its extension is not ' gif '. Whereas a file named 123.gif would be listed. $ ls *day* list all the files that have the letters 'day' in their filenames. Thus files such as today.txt, dayone.txt and lastday.gif would all be listed in the output. $ ls .*gif* List all the hidden files in the current directory that have the letters ' gif ' in their filenames. Hidden files in Linux begin with a .(period) in their filenames. “ Linux filenames are case sensitive, a range of [a-z] is differ from [ A-Z] ”

Successful People in life seem to like LINUX

Page 9 of 29

Files Directories and Permission Settings in Linux Directory vs. Files DIRECTORY first letter starts with “d” and FILES first letter starts with “–“ drwxr-xr-x 3 oracle oinstall 4096 DEC 29 21:54 Desktop

-rw-r--r-- 1 oracle oinstall 427 JAN 13 05:34 sample.sh

Creating Directory in LINUX

Creating Multiple Directory

DIR 1

DIR 2

Parent Directory / Sub directory

DIR 1

DIR 2

DIR 3

mkdir dir1 dir2 dir3

.

Current directory .. Parent directory

DIR 3

mkdir –p dir1 dir2 dir3

~

home directory

Hidden Files/Dir in LINUX create with a dot "." prefixed. Hidden files filename begins with a “.” period . To see hidden files using the ls command with -a option. Most of the Hidden files are text files so any text editor like "vim" or "nano" will display the text. "cat .foofile | less" to see it displayed within console. ls -altr lists hidden dir. Successful People in life seem to like LINUX

Page 10 of 29

Files Directories and Permission Settings in Linux CHMOD/ CHOWN /CHGRP (Changing Permissions & ownership) Chmod ( Change access permissions on a file or directory) Chown ( Change ownership for a file or directory).  Concept of owner and groups for files is fundamental to Linux  Every file is associated with an owner and a group.  Changing Ownership  chown and Permissions  chmod. CHMOD Stands for "Change Mode" Command is used to change “ access permissions to files and directories”. >  r = Read permission  w = Write permission  x = Execute permission  s = Set user (or group) ID.  t = Sticky bit; OPCODE , PERMISSIONS  + Add Permission  - Remove Permission  = Assign Permission “ Basic rights that permissions are "Read" , "Write" and "eXecute" FILES  "Read" means to be able to open and view the file  "Write" means to overwrite or modify the file  "eXecute" means to run the file as a binary Successful People in life seem to like LINUX

Page 11 of 29

Files Directories and Permission Settings in Linux DIRECTORIES  "Read" means to be able to view the contents of the directory  "Write" means to be able to create new files/directories within the dir.  "eXecute" means to be able to "Change Directory" (cd) into the directory Most of the time you set "Read" and "eXecute" together on directories . To see permissions a file or directory, use the ls with option –l -rwxrwx--- 1 root root 1304 Nov 2 09:56 space.sh drwxr-xr-x 2 root root 4096 Nov 2 21:20 test

First letter indicates what type of FILE OR DIRECTORY Remaining 9 characters are broken down into 3 groups of 3 characters.  First three are the permissions for the owner,  Middle three are permissions for the group which has access to the file ,  Last three are the permissions for everyone. Permissions are the first 10 characters of the line (-rwxrwx---) are Ex - FILE Permission (-rwxrwx---) -

rwx

rwx

filetype owner group

---

1

all

links

root

root

owner group

1304 size

nov 2

space.sh

mod_dt file_name

First character on the line shows what type of file or directory  - = Regular file , d = directory  l = symbolic link  b = block-type special file Successful People in life seem to like LINUX

Page 12 of 29

Files Directories and Permission Settings in Linux  c = character-type special file  p = named pipe  s = socket  s = XENIX semaphore , m = XENIX shared data (memory) file  m = XENIX shared data (memory) file , D = Solaris door  n = HP-UX network special file Change permissions of Files/Directories  chown - change the ownership of the file/dir (need to be root to use)  chgrp - change "Group Ownership" of a file or directory  chmod - change the "access rights" to the file or directory

Add single permission to a file/directory $ chmod u+x filename Add multiple permission to a file/directory $ chmod u+r,g+x filename Remove permission from a file/directory $ chmod u-rx filename Remove all permission from a file/directory $ chmod a-r,a-w,a-x filename Change permission for all roles on a file/directory $ chmod a+x filename

or chmod

Make permission for a file same as another file $ chmod --reference=file1 file2

Successful People in life seem to like LINUX

Page 13 of 29

Files Directories and Permission Settings in Linux Applying the Permission to all the files “Recursively” in a dir $ chmod -R 755 directory-name/ Change execute permission only on the directories (files not affected) $ chmod u+X * CHMOD Examples r = 4 , w = 2 , x = 1 i.e. rwx = 7 # chmod 777 filename.ext # chmod 777 space.sh First number stands for "user" Second group stands for "group" Final number stands for "other read

= 100 in binary = 4 in octal

write

= 010 in binary = 2 in octal

execute = 001 in binary = 1 in octal So , where does the 7 come from ? 7 in binary = 111 in decimal = read, write, execute Some Examples read write execute= 111=[1+2+4 =7] read write no execute =110=[4 +2=6] read no write execute =101=[4+1=5] read no write no execute=100=[4] no read write execute = 011=[2+1=3]

Successful People in life seem to like LINUX

Page 14 of 29

Files Directories and Permission Settings in Linux no read write no execute =010=[2] no read no write execute =001 =[1] no read no write no execute=000=[0] NOTE: Each file or directory is assigned to a specific user and group. Simple Example Pemissions for files Examples

What it means

-rwxrwxrwx

read, write and executable for owner, group and all others

-rwxrwx---

read, write and executable for owner, group only

-rwx------

read, write and executable for owner only

-rw-rw-rw

read and write for owner, group and all others

-rw-r--r-

read and write by owner, read only for group and all others

-rwxr-xr-x

read, write and executable by owner, only read and executable by group and others

CHOWN Stands for CHANGE- FILE OWNER & GROUP Command chown used to change the owner and group of a file or directory. This is an admin command, root user only can change the owner of a file or dir Change the owner of a file : root to sam -rwxrwx--- 1 root root 1304 Nov 2 09:56 space.sh # chown filename # chown sam space.sh -rwxrwx--- 1 sam root 1304 Nov 2 09:56 space.sh space.sh file owner changed from root to sam. Here file group not changed. Successful People in life seem to like LINUX

Page 15 of 29

Files Directories and Permission Settings in Linux Change the group of a file : root to oragroup -rwxrwx--- 1 sam root 1304 Nov 2 09:56 space.sh # chown : # chown : oragroup space.sh -rwxrwx--- 1 sam oragroup 1304 Nov 2 09:56 space.sh Changing directory from one group to another dba to oinstall drwxr-xr-x 2 sona dba 4096 Nov 14 14:53 scripts # chown : # chown :oragroup scripts drwxr-xr-x 2 sona oinstall 4096 Nov 14 14:53 scripts Change both Owner and the Group to files Don’t ge

# chown owner:group # chown sona:orasamp space.sh or # chown owner.group # chown sam.oragroup space.sh -rwxrwx--- 1 sona orasamp 1304 Nov 2 09:56 space.sh -rwxrwx--- 1 sam oragroup 1304 Nov 2 09:56 space.sh

Successful People in life seem to like LINUX

Page 16 of 29

Files Directories and Permission Settings in Linux Change both Owner and the Group to directories > drwxr-xr-x 2 sona oinstall 4096 Nov 14 14:49 backup1 # chown owner.group # chown oracle.dba script drwxr-xr-x 2 oracle dba 4096 Nov 14 14:53 backup1

Change the owner/group of the sub directories files Recursively drwxr-xr-x 3 root root

4096 Nov 3 22:57 test

From root to sam (owner) From root to oragroup (Group) # chown -R owner:group '/dir_path' # chown -R sam:oragroup '/root/test/' drwxr-xr-x 3 sam oragroup 4096 Nov 3 22:57 test # cd test # ls -l -rw-r--r--

1 sam oragroup

60

Nov 3 22:57 space.sh

drwxr-xr-x 2 sam oragroup 4096 Nov 3 22:57 test1 # cd test1 / # ls –l -rw-r--r-- 1 sam oragroup

90 Nov 3 22:57 space2.sh

Successful People in life seem to like LINUX

Page 17 of 29

Files Directories and Permission Settings in Linux Chown and Chgrp command in linux. chown command is used to change file or directory ownership. chgrp command is used to change the group with which a file is associated. Using chown command (if we want to change group name) command should be username.group_name (sona.dba). Using chgrp command no need to use user_name , directly can change group_name. EXAMPLES

Changing group from sona to dba using chown drwxr-xr-x 2 sona sona

4096 Nov 14 14:53 script

# chown dba script chown: `dba': invalid user # chown sona.dba script # ls -al drwxr-xr-x 2 sona dba

4096 Nov 14 14:53 script

Changing group from sona to dba using chgrp

drwxr-xr-x 2 sona sona

4096 Nov 14 14:53 script

# chgrp dba script # ls -al drwxr-xr-x 2 sona dba

4096 Nov 14 14:53 script

Successful People in life seem to like LINUX

Page 18 of 29

Files Directories and Permission Settings in Linux UMASK  Umask (User file creation MASK) -- four-digit octal number.  Umask command can restricts permissions.  It is used to determine the permission for newly created files or dir.  It can be used to control the default file permission for new files.  0022 which means your base mask is 755  0000 which means you base mask would be 777 The first 0 is the special bit, so it can be ignored for the time being. Default UMASK root vs user # umask 0022 # su - rose $ umask 0002

# useradd -g oinstall chris # su - chris $ cd /home/chris/ $ umask 0022 022 is the normal umask, for root and user. umask 022 gives 755 for folders and 644 for files umask default (002) value differs 775/664 (folders/files) That's the default permission you get when you create new files/folders. Successful People in life seem to like LINUX

Page 19 of 29

Files Directories and Permission Settings in Linux WHAT IS 0022(022) and 0002(002) chris@testorcl ~]$ ls -al drwx------ 2 chris oinstall 4096 Nov 14 00:13 .

[sona@testorcl ~]$ ls -al drwx------ 7 sona sona 4096 Nov 13 22:36 .

[root@testorcl ~]# ls -al drwxr-x--- 22 root root

4096 Nov 13 22:42 .

An user is not assigned to specific group (sona), and no one else is a member of that group, can have 002 -(that would in effect be the same as umask 022) i.e (drwxrwxr-x). If user added with with any group as primary (g) , umask will be 0022(022). Usr1 with Primary Group and umask is 0022 # useradd -g oinstall usr1 usr1 umask : 0022 $ mkdir sample $ touch sample.txt $ ls -ld sample sample.txt drwxr-xr-x 2 usr1 oinstall 4096 Jan 13 20:32 sample -rw-r--r-- 1 usr1 oinstall 740 Jan 13 20:33 sample.txt DIR =777 – 022 = 755 (rwxr-xr-x) and FILE = 666-022=644 (-rw-r--r-- )

Successful People in life seem to like LINUX

Page 20 of 29

Files Directories and Permission Settings in Linux User(rose) with oinstall(secondary) and umask is 0002 # useradd -G oinstall rose usr1 umask : 0002 # mkdir sample $ touch sample.txt $ ls -ld sample sample.txt drwxrwxr-x 2 rose rose 4096 Jan 13 20:38 sample -rw-rw-r-- 1 rose rose 680 Jan 13 20:40 sample.txt DIR =777 – 002 = 775 (rwxrwxr-x) and FILE = 666-022=644 (-rw-rw-r-- ) Any co -relation between umask & group either primary/secondary ? Absolutely No. -g option with useradd, it adds "oinstall" or whichever group we specified with it , as primary group for that user. - g option is used to specify primary group of the user. - G option is used to specify secondary/any alternative group. So when we set "oinstall" as primary group, it sets umask to 0022 for that user, so any new file created by that user can get 644 permission. Point to note here, 6 stands for owner, 4 stands for group and 4 stands for others respectively. that user can also have write permission on that file. If a user don’t have "oinstall" as primary group, then others won’t get write permission on that database file, that's why umask 0002.

Successful People in life seem to like LINUX

Page 21 of 29

Files Directories and Permission Settings in Linux Calculating Umask [ OCTAL] UMASK is an octal number that specifies the which of the permission bits will not be set.  0 : read, write and execute  1 : read and write  2 : read and execute  3 : read only  4 : write and execute  5 : write only  6 : execute only  7 : no permissions Lets check umask settings for 7 i.e (no permission). Default base permission is 666 for files. Default base permission is 777 for directories Now we would subtracrt (777 – 777)= 0 and (666 – 666) =0 i.e ( no read , write, execute permissions ) for anyone. $ umask 777 [oracle@testorcl ~]$ mkdir sqlscript [oracle@testorcl ~]$ touch sqlscript.txt [oracle@testorcl ~]$ ls -ld sqlscript sqlscript.txt d--------- 2 oracle oinstall 4096 Jan 13 06:23 sqlscript ---------- 1 oracle oinstall 640 Jan 13 06:24 sqlscript.txt

Successful People in life seem to like LINUX

Page 22 of 29

Files Directories and Permission Settings in Linux Default Permission vs Base Permission Default umask for the root user is 0022. Default directory permissions are 755 (rwxr-xr-x) Directories, base permissions : 0777 (rwxrwxrwx) Default file permissions are 644. (rw-r--r--) Files , base permissions : 0666 (rw-rw-rw).. Calculating DIR Permissions for a umask value of 022 (root user) Default Permission = 777 Subtract umask value = 022 i.e. (755 – 022) (-) Now Directory Permission is =755 755 allowing read, write, and execute permissions to user and only read and execute to group and other users. Calculating File Permissions for a umask value of 022 (root user): Default permission= 666 Subtract umask value= 022 i.e. (666 – 022) (-) Now File permission: 644 File permissions default to 644 allowing read and write access to user but only read to group and others. Example for umask setting 022 # umask 022 # mkdir bdir # touch bfile.txt

Successful People in life seem to like LINUX

Page 23 of 29

Files Directories and Permission Settings in Linux Output of the above umask Settings

# ls -ld b.txt bb drwxr-xr-x 2 root root 4096 Nov 8 00:17 bdir -rw-r--r--

1 root root 240 Nov 8 00:17 bfile.txt

Have a look here , Default settings are not changed , files are created with the access mode 666 and directories with 777. Directories 777 – 022 = 755 , Files 666 - 022 =644 DIRECTORIES DIR BASE PERMISSION IS 777 , UMASK VALUE= 022 so, 777- 022 = 755

Permissions of new DIR is (777-022) = 755 (rwxr-xr-x) Owner will have read, write, execute permissions Group will have read, execute permissions Others will have read, execute permissions FILES FILE BASE PERMISSIONS IS 666 , UMASK VALUE= 022 so , 666 - 022= 644 Subtract to get permissions of new file (666-022) = 644 (rw-r--r--) No other user can read or write your data, if umask is set to 077. BASE PERMISSION OF FILE IS 0666 and DIRECTORY IS 0777. So DIR = 777 - 077 =700 and FILE= 666 - 066 = 600. Successful People in life seem to like LINUX

Page 24 of 29

Files Directories and Permission Settings in Linux Dir = read,write, execute for owner group and others has no permission. File= read ,write for owner group and others has no permission.

[oracle@localhost ~] $ umask 077 [oracle@localhost ~] $ vi script.txt [oracle@localhost ~] $ mkdir script [oracle@localhost ~]$ ls -al script.txt script -rw------- 1 oracle oinstall

144 Nov 11 08:58 script.txt

drwx------ 2 oracle oinstall

4096 Nov 11 08:58 .

drwxrwxrwx 3 oracle oinstall 4096 Nov 11 08:58 .. [oracle@localhost ~] $ ls -ld script drwx------ 2 oracle oinstall 4096 Jan 13 07:07 script

If your umask is set to 077 i.e. 0077 , then do a subtraction . Umask sets automatically permissions on newly created files to 066 even we set 077. Newly created directory will be having permission 0777 (rwx rwx rwx) – 0077 (---rwxrwx)= 0700 i.e. (rwx------). Newly created file will be having permission 0666 (rw-rw-rw-) – 0077 (---rwxrwx) = 0600 i.e. (rw------). POINTS TO REMEMBER UMASK , is it's a mask and not a 'setting' chmod creates a setting. We can set umask in /etc/bashrc or /etc/profile for all users. umask -S displays the current mask in symbolic form. This is the default output. Successful People in life seem to like LINUX

Page 25 of 29

Files Directories and Permission Settings in Linux $ umask 022 $ umask -S u=rwx, g=rx, o=rx $ umask -p umask 0022 $ mkdir sample [foo@testorcl ~] $ ls -ld sample d rwx r-x r-x 2 foo1 foo1 4096 Jan 13 07:34 sample

So if we have a program 'touch' create a file naturally with 666 as its permissions (rw-rw-rw-). The octal level for Linux starts at 666. 4 |2 |1 = r|w|x 4+2+1 =7 = rwx 4+0+1 = 5 = r-x Hence 4+2+0 = 6 = rwIf a file with -rwx rwx rwx , must have the octals 777 to match. If a file is -rwx r-x r-x then the octals that match are 755. We start with a base figure of 666 – 022 = 644 (rw- r-- r--) Change Octal way change to octal mode r-x rw- r-x to abc chmod 565 change to octal mode --x r-xr--

to abc chmod 154

change to octal mode rw----rwx to abc chmod 607

Successful People in life seem to like LINUX

Page 26 of 29

Files Directories and Permission Settings in Linux INODE Inode(index node). Unix/LINUX don’t use the filename to refer to the file; Linux uses the inodes. A file's inode number can be found using the ls -i command. LINUX/UNIX os kernel knows the file name as an inode number keeps track of all the file information . Whatever info will get from stat of a file , those are stored in the corresponding files inode number. An inode stores basic information about a regular file, directory. Each and every file under Linux having following attributes . Run ls -il to get a clean output. Inode consists of the following fields  File type  Device ID  File access permissions  Number of links  File size in bytes  User ID of file owner  Group ID of the file  Location of the file data  Timestamp of the file ( ctime , mtime , atime) i.e.  last modified (ctime, change time)  file content last modified (mtime, modification time)  last accessed (atime, access time).  Pointers to the blocks storing file’s contents  link counter to determine the number of hard links  File mode information and access privileges for owner, group & others Successful People in life seem to like LINUX

Page 27 of 29

Files Directories and Permission Settings in Linux STAT Linux command 'stat' is used for displaying status information of Linux files and file systems. stat utility allows to see all information about either a file or a directory. These functions return information about the specified file. stat, fstat, lstat - displays file or filesystem status. $ stat -f file_name $ stat -f script.sql

[oracle@localhost ~]$ stat script.sql File: `script.sql' Size: 605

Blocks: 8

Device: 805h/2053d

IO Block: 4096 regular file

Inode: 2583996

Links: 1

Access: (0644/-rw-r--r--) Uid: ( 500/ oracle) Gid: ( 500/oinstall) Access: 2012-10-15 00:06:17.000000000 +0530 Change: 2012-10-14 23:52:45.000000000 +0530

[oracle@localhost ~]$ stat -f script.sql File: "script.sql" ID: 0

Namelen: 255

Type: ext2/ext3

Blocks: Total: 6694774 Free: 1924314 Available: 1584239 Size: 4096 Inodes: Total: 3401216 Free: 3265909

The –f flag shows file-system wide information (e.g. the total number of free inodes) while stat with no arguments shows information for the file itself. stat command gets the information it presents from the inodes stored on disks.

Successful People in life seem to like LINUX

Page 28 of 29

Files Directories and Permission Settings in Linux ID Command id - print real and effective UIDs and GIDs Prints information of the current userand numeric user and group ID on BSD. In order login into Linux system we need to supply need a username and password. Username and password stored in /etc/passwd and /etc/shadow file respectively. When we supplies password, it encrypts and compare with password stored in /etc/shadow, which is also in, encrypted format (it was stored when you or system administrator registers/updates it). If both are equal, can login. Once logged in, we are become the number to Linux kernel UID number 0 is special and used by the root user. The zero (0) UID enjoys the unrestricted/unlimited access to Linux system. 0 UID assigned to root ; Id command for root vs oracle user

[root@testorcl ~]# whoami root [root@testorcl ~]# id uid=0(root) gid=0(root) groups=0(root), 1(bin), 2(daemon), 3(sys), 4(adm), 6(disk), 10(wheel)

[root@testorcl ~]# su - oracle [oracle@testorcl ~]$ id uid=500(oracle) gid=500(oinstall) groups=500(oinstall), 501(dba)

Successful People in life seem to like LINUX

Page 29 of 29

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF