Linux standard textbook

What is linux

It seems that it consists of a kernel and userland

What i learned

--You can output the result with >

➜  Desktop cat someoutput | tr a A > newsomeoutput
➜  Desktop cat newsomeoutput
yAmAdA 100
tAnAkA 20
kAndA 60

Methods you might use

official
find pathname--name file name

--Head It seems that it can be displayed by specifying the number of lines

➜  Desktop head someoutput
hello

It seems that the contents of the file can also be sorted

➜  Desktop cat someoutput
yamada 100
tanaka 20
kanda 60
➜  Desktop sort someoutput
kanda 60
tanaka 20
yamada 100
➜  Desktop sort -r someoutput #r is reverse
yamada 100
tanaka 20
kanda 60

➜  Desktop sort -n -k 2 someoutput #n is the number k is the line
tanaka 20
kanda 60
yamada 100

--tar command (using | pipe)

➜  Desktop cat someoutput
yamada 100
tanaka 20
kanda 60
➜  Desktop cat someoutput | tr a A
yAmAdA 100
tAnAkA 20
kAndA 60

Output the changed thing to another file

➜  Desktop cat someoutput | tr a A > newsomeoutput
➜  Desktop cat newsomeoutput
yAmAdA 100
tAnAkA 20
kAndA 60

Options are essential. -n (unified) is a familiar format

➜  Desktop diff -u someoutput newsomeoutput
--- someoutput	2020-01-02 03:02:12.000000000 +0900
+++ newsomeoutput	2020-01-02 03:12:35.000000000 +0900
@@ -1,3 +1,3 @@
-yamada 100
-tanaka 20
-kanda 60
+yAmAdA 100
+tAnAkA 20
+kAndA 60

About vi command

I'm not so interested here. I wish I could edit and save

--Search / --Replace

:1s/old/new/g
  1 yamada 100
  2 tanaka 20
  3 kanda 60

:1s/yamada/nkanda/g

  1 nkanda 100
  2 tanaka 20
  3 kanda 60
It has changed.
It seems that there is also conversion by searching the full text of the file.

Full text search Full-text search with % s

:%s/melon/*MELON*/g

About management authority

User type

--Group --User Minimum unit authority to use resources such as memory and files

--User created

ʻUseraddUsername * mac seems to be different -g` group name

--Change user permissions

ʻUsermod` Username

--User deletion

ʻUserdel` username

--Group creation

groudadd group name

Edit deletion is the same as the user, change only the first letter to group

In ʻetc / passwd`

--group file The group is stored etc/group

User and access rights

File owner and owning group

--chown user (group) directory --chown user (group) directory

#Changed to nobody

➜  Desktop ls -l user
-rw-r--r--  1 username  staff  0  1  2 03:44 user


➜  Desktop ls -l user
-rw-r--r--  1 nobody  staff  0  1  2 03:44 user

#I try to edit but I can't change it with readonly
➜  Desktop vi user

--chgrp group directory --chgrp group file

Files and permissions

--There are three authorities. Read (r read), write (w write), execute (x exec?)

d rwx rwx rwx From the left, file type, owning user (u), owning group (g), and others (o)

--Change command

chmod mode file

➜  Desktop ls -l user
-rw-r--r--  1 username  staff  0  1  2 03:55 user


#Add w permission to group Addition+
-rw-r--r--  1 username  staff  0  1  2 03:55 user
➜  Desktop chmod g+w user
➜  Desktop ls -l user
-rw-rw-r--  1 username  staff  0  1  2 03:55 user

#Remove w permission for group Add-
➜  Desktop chmod g-w user
➜  Desktop ls -l user
-rw-r--r--  1 username  staff  0  1  2 03:55 user

#Change in octal number This is 664 or something

➜  Desktop ls -l user
-rw-r--r--  1 username  staff  0  1  2 03:55 user
➜  Desktop chmod 664 user
➜  Desktop ls -l user
-rw-rw-r--  1 username  staff  0  1  2 03:55 user

Shell script

The kernel has the function of operating the hardware in the basic part of the OS. Operate the OS when operating kernel functions. That is the shell

--Create

touch lsdata.sh

#!/bin/bash  #Select the shell file to use

ls #The command you want to execute
date

--Execute

➜  Desktop sh lsdate.sh
Screenshot 2020-01-01 11.13.02.png #List
Performance improvement.md
Thursday, January 2, 2020 12:16:37 JST#The date comes out with date

--echo command (command to output the characters given as arguments as standard)

➜  Desktop echo message test
message test

--Variables

Can it be used like this in the terminal?

➜  Desktop abc=123 #Substitution is=Stick together
➜  Desktop echo $abc
123

--export command

export abc=345 #Set environment variables

--Check shell variables and environment variables

Shell variable set Check environment variables ʻenv`

--Arguments Run-time arguments can be called with $ 1 etc.

➜  Desktop sh lsdate.sh hello yahoo
$1: hello
$2: yahoo

#The contents of the file

➜  Desktop cat lsdate.sh
# !/bin/bash

echo '$1:' $1
echo '$2:' $2
➜  Desktop sh lsdate.sh hello
The characters are the same


➜  Desktop cat lsdate.sh
# !/bin/bash

STR1='hello'

if [ $STR1 = $1 ]; then #When calling a variable$Put on
 echo "The characters are the same"
fi

--Repeat, I want to see functions, etc.

Actual shell

It seems that there are many things to do at startup. The configuration may be divided into the main file and the separated function file.

#Constitution
etc/functions/Function file.sh
init.sh

#init.with sh
# !/bin/bash
.etc/functions/* #Read the function carved here

Debugging method

Add a x option when running

➜  Desktop sh -x lsdate.sh
+ echo '$1:'
$1:
+ echo '$2:'
$2:

network

IP address and TCP (Transfer Control Protocol)

When sending data, it is delivered to the server by IP address, and the TCP port (22: ssh 80: application) determines where to deliver to the application.

--ping command

➜  Desktop ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1): 56 data bytes
Request timeout for icmp_seq 0

--Route confirmation

➜  Desktop traceroute lpi.jp
traceroute to lpi.jp (3.112.116.66), 64 hops max, 52 byte packets
 1  192.168.3.1 (192.168.3.1)  2.046 ms  2.912 ms  2.549 ms
 2  * * *
 3  softbank32432423432.bbtec.net (221.110.235.201)  43.241 ms  25.163 ms  29.019 ms

Network settings

--ifconfig command

ʻInet` is the IP address https://www.atmarkit.co.jp/ait/articles/0109/29/news004.html

Recommended Posts

Linux standard textbook
Linux standard textbook memo 1
Linux standard textbook memo 3
Linux standard textbook part 5
Linux standard textbook part 4
Linux standard textbook memo 1 part 2
I read "Linux standard textbook"!
Linux standard textbook memo part 6
[Reading memo] Linux standard textbook (Chapter 7-8)
Linux standard textbook chapter end test answer
Linux standard textbook (ver3.0.2) I tried Chapter 1
[Reading memo] Linux standard textbook (Chapter 1 to Chapter 6)
Linux
New Linux textbook (study notes)
Linux command # 4
Linux commands
Linux commands
Linux command # 3
Linux overview
Easy JSON formatting with standard Linux functions
Linux basics
direnv (linux)
Organize Linux
linux commands
Linux practice
Ubuntu Linux 20.04
Linux Summary
Linux process
Linux permissions
Linux command # 5
About Linux
Linux basics
Forgot linux
About Linux
Linux commands
Linux commands
About Linux
About Linux
About Linux ①
Linux redirect