Linux Day3

Reading Permissions

- : Regular file
d : Directory
l : Symbolic link
r : Read
w : Write
x : Execute
u : user 
g : group
o : other
a : all

image

  1. This is a ‘-‘ regular file
  2. User can Read and Write
  3. Group can Read
  4. Other can Read

Group

  • 모든 유저는 적어도 한 그룹에 속해있다.

  • User가 속한 그룹 보여주는 커맨드

    groups 
    id -Gn
    

Changing Permissions

Info

  • chmod : Change mode command
  • ugoa : User category , User, Group , Other, All
  • +-= : add, subtract, or set permissions
  • rwx : Read, Write, Execute

Example

  • sales.data에 user가 write할 수 있게 하고 싶을 때

    chmod u+w sales.data
      
    chmod u+rwx, g-x sales.data
      
    chmod a=r sales.data
      
    ls -l sales.data
    

Numeric Based Permissions

Read : 4 Write : 3 Execute : 1

chmod number filename

chmod 0 : No permissions
chmod 1 : Execute only
chmod 2 : Write only
chmod 3 : Write and Execute
chmod 4 : Read only
chmod 5 : Read and Execute
chmod 6 : Write and Read
chmod 7 : Write, Read and Execute

Working with Groups

  • 새로운 파일은 작성자의 primary group에 속한다.
  • chgrp command는 group을 바꾼다.

File Creation Mask

  • File creation mask

    • system admin 이 따로 바꾸지 않으면 기본으론 다음과 같다.
    Default
    777 : for directories
    666 : for files
    
  • umask [-S] [mode]

    022, 022, 077, 007 //자주 사용되는 umask 모드
    
  • File creation mask + umask

    Base Permission : 777
    Subtract Umask : umask 022 //cmd
    Creations Permission : 755 //결국에는 755 퍼미션을 가진 파일이 생성된다. 
    

Different ways to display the contents of files

  • 스페이스바는 다음 장,
  • 엔터는 한줄씩
cat file : 파일 컨텐츠를 보여준다.
more file : 파일을 browse하게
less file : more보다 기능이 많다.
head file : 처음 열줄
tail file : 마지막 열줄

Viewing Files in Real Time

tail -f file 

Nano Editor

nano file.txt

Vi Editor

vi : Edit file

vim : same as vi, but more features

view : Starts vim in read-only mode

vi filename.extension

command Mode

  • hit ESC first
 k -- Up one line
 j -- Down one line
 h -- Left one character
 l -- Right one character
 w -- Right one word
 b -- Left one word
 ^ -- Go to the beginning of the line
 $ -- Go to the end of the line

insert Mode

i -- insert at the cursor position
I -- Insert at the beginning of the line
a -- Append after the cursor position
A -- Append at the end of the line
o -- Open a new line below the current line
O -- Open a new line above the current line

Vi Line Mode

hit : first

:w -- Write the file
:w! -- Forces the file to be saved
:q -- Quit
:q! -- Quit without saving changes
:wq! -- Write and quit
:x -- same as wq
:n -- :15 (15번째 줄)
:$ -- 마지막줄
:set nu -- Turn on line numbering
:set nonu -- Turn off line numbering
:help --help

Deleting Text
x -- Delete character
dd -- Delete line
dw -- Delete word
d{motion} -- Delete {motion}

Copy/Paste
y{motion} -- Yank {motion}
yy -- Yank line
p -- Paste after cursor
P -- Paste before cursor

Searching
/{pattern} -- Forward search for {pattern}
?{pattern} -- Reverse search for {pattern}
n -- Repeat the last search
N -- Repeat the last search in the opposite direction

Undo/Redo
u Undo
Ctrl-r Redo

Find and Replace
:s/{old}/{new}/{options} Substitute {new} for {old} on the current line
:%s/{old}/{new}/{options} Substitute {new} for {old} in the entire document
The g option substitutes all occurrences on a line, otherwise just the first occurrence is changed per line

Emacs editor

Emacs Reference
Movement
C-n Next line
C-p Previous line
C-f Move cursor forward one character
C-b Move cursor backward one character
M-f Forward one word
M-b Backward one word
C-a Move to beginning of line
C-e Move to end of line
M-a Move back to beginning of the sentence
M-e Move back to end of the sentence
M-< Go to the beginning of the file
M-> Go to the end of the file
M-g g N Go to line N
Searching
C-s Start a forward search.
C-r Start a reverse search.
Repeating Commands
C-u {num} {command} Repeat {command} {num} times
Deleting Text
C-d Delete a character
M-d Delete a word
Copy/Paste
C-k Kill (cut) the rest of the current line of text
C-y Yank (or paste) from the previously killed text
Undo
C-x u Undo.
Save and Quit
C-x C-s Save the file
C-x C-c Exit
Help
C-h Help
C-h t Tutorial
C-h k {key} Describe {key}
Find and Replace
M-% {old} {new} ! Substitute {new} for {old} in the entire document
Legend
M-x means “press and release the Escape key and then press the x key. “
C-x means “press and hold the Control key and then press and release the x key.”

Find command

find [path] [expression ]

options

-name pattern : pattern 에 맞는 파일과 디렉토리를 찾아준다. 
-iname pattern : -name option 과 비슷하지만, case insensitive하다.
-ls : 찾아진 아이템들에 ls를 수행한다.
-mtime days : modification time
-size num : size에 따라서 
-newer file :param file보다 나중에 만들어진 파일
-exec command {} \;

Example

find .
find /sbin -name makedev
find . -mtime +10 -mtime -13 //10 일 이상, 13일 이하
find n -name s* -ls
find . -type d -newer file.txt
find . -exec file {} \;

locate command

  • realtime이 아니다. find 보다 다르다. 그치만 간편함. (find는 realtime)
locate sales
locate tpsre
locate tomcat

Graphical Editors

  1. Emacs : Emacs has a graphical mode too
  2. gedit : default text edtor for Gnome
  3. gvim : The graphical version of vim
  4. kedit : the default text editor for the KDE
  5. AbiWord : MS word alternative
  6. LibreOffice : Full office suite
  7. Kate : source code editor

© 2018. All rights reserved.

Powered by Hydejack v8.5.2