[Reading memo] Linux standard textbook (Chapter 1 to Chapter 6)

Introduction

We will output a summary of reading the "Linux Standard Textbook (PDF)" about Linux, which beginners should understand above all. This time, from Chapter 1 to Chapter 6 of the first half.

Chapter 1 What is Linux?

-Basic software: Software that manages the entire computer system -Application software: A general term for software developed for a specific purpose (spreadsheet software, word processing software, etc.) -Linux in a broad sense = [hardware] + [kernel] + [application software] ・ Linux in a narrow sense = [kernel] -Kernel: The core of the OS that has the ability to interact directly with the hardware -Userland: Parts other than the kernel required for the OS to operate -Shell: An interactive command input environment. Understand the entered command → execute -Introduction of application software may require multiple application software and a library that supplements the operation. If a dependent program depends on yet another program, it must be ** installed in the correct location and in the correct order **.

Chapter 2 Linux installation

Omitted as it is installed by default on macOS

Chapter 3 Basic commands

・ Introduction of basic commands and options according to the purpose

Check the list

ls [option] [file name]: Get list
-a:.All hidden files starting with (All) output
-l:Output in Long format
-t:Last updated time (Time)Sort by and output
-r:Sort and output in reverse order
#Sorting is sorting by a certain standard.

-When narrowing down further from the result of the ls command, wildcards (= character strings that match all patterns) can be used. For example, to narrow down and display the "conf" files in the .etc directory, write like this ・ If the number of characters is clear, use "?"

$ cd /etc
$ ls *.conf
Trolltech.conf
ntp.conf
(* This is just an example)
$ ls hosts.*
hosts.allow hosts.deny
$ ls hosts.????
hosts.deny

Copy file

cp [option]Copy source Copy destination
-i:Confirm when processing. The computer makes an inquiry for confirmation. Used to prevent accidental overwriting

-r:Copy the directory. Basic cp only has the ability to copy files,-Add r to copy to all files and directories in the directory

-p:Save the information of the original file. Attach when you want to make a copy while keeping the old information.

Move files

mv move source file move destination file
-i:Confirm when processing. The computer makes an inquiry for confirmation. Used to prevent accidental movement
-f:Forced execution. In some processes, there is a confirmation inquiry, but it is ignored and executed.
▶ ️ Be careful not to handle it indiscriminately in team development

Delete file

rm file name
-i:Confirmation inquiry
▶ ️ Abbreviation for information, right?
-f:Forced execution
-r:Delete directory + files and directories in the directory

Directory manipulation (pwd, cd, mkdir, rmdir)

pwd:Display where you are currently (abbreviation for Print Working Directory)
cd [Directory name]:Move

mkdir [Directory name]:Create
option
-p:Creates a higher-level directory of the specified directory
$ mkdir dir1/dir2/dir3

rmdir [Directory name]:Delete
-p:Delete all directories up to the specified hierarchy
(If no option is added, only the bottom directory is deleted)
*** The target directory must be empty**
$ rmdir directory/
rmdir: failed to remove 'directory/':Directory is not empty
$ rmdir -r directory/
(rm -Can be deleted with (execute r)

Special directory

name function
Current directory (.) Current directory
Parent directory (..) Directory one level up
Home directory~) The directory where the user starts working
Root directory(/) Top level of directory hierarchy

Absolute (path) specification and relative (path) specification

Assuming that the current directory is / usr / local, there are two ways to specify the file in / usr / bin / xxx.

  1. /usr/bin/xxx

  2. ../bin/xxx

  3. specifies the directory / file name from the top-level directory (/). This method is called absolute (path) specification.

  4. is specified "as seen from where you are". This method is called relative (path) specification.

View file contents (cat)

cat [file name]
-n:Display with line numbers added

Display using pager

When displaying the contents of a file with the cat command, the display will flow if there are many lines. The function that controls the screen and stops scrolling in the middle even if there are many lines is called paging, and the expression is called pager.

more [file name]
less [file name]

There are quite a lot of things that can be done, and it seems that there are a lot of less in practice, so only reference articles are introduced. Reference article: Linux command 2 (cat, grep)

Other things that you should know

find path-name [file name]: File search
man [cp, ls, etc.]:[]Display the manual for the command in

Chapter 4 Regular Expressions and Pipes

-Standard input / output: Linux programs (= commands) have "one entrance and two exits". They are called standard input, standard output, and standard error output, respectively. In particular, displaying the result of executing a command on the screen is expressed as "output to standard output".

Search data in files (grep)

grep [Option name]Search conditions[Specified file]
option
-e:Treat strings as search patterns
-i:Insensitive to uppercase and lowercase letters in both search patterns and input files
-v:Select rows that do not match your search pattern
symbol meaning
^ Represents the beginning of a line
$ Represents the end of a line
. Means any letter
* Means 0 or more iterations of the previous character
[...] ..Means any one character in
[^...] ..Means that the character of
¥ Escape regular expression symbols

Chapter 5 Basic Command 2 (Convenient for processing text files)

Change file time stamp (touch) & create file

-Timestamp: A technology that proves that the electronic data existed at a certain time and that it has not been tampered with since then. By comparing the information described in the time stamp with the information obtained from the original electronic data, it can be surely and easily confirmed that the information has not been tampered with from the time stamped.

$ ls -l
total 8
-rw-r--r--  1 user  staff  81  8 10 23:01 dockerfile
$ touch -t dockerfile
usage:touch [-A [-][[hh]mm]SS] [-acfhm] [-r file] [-t [[CC]YY]MMDDhhmm[.SS]] file ...
# -Add the t option and type the command in the order of date, time, target file.
$ touch -t 08142033 dockerfile 
$ ls -t
dockerfile
$ ls -l
total 8
-rw-r--r--  1 user  staff  81  8 14  2020 dockerfile
$ touch test.md
#A new file is created
$ ls
dockerfile	test.md

Get part of the file (head, tail)

head [Option name]file name
tail [Option name]file name
-n(line):先頭から指定したlineを標準出力
-c(Part-Time Job):先頭から指定したPart-Time Job分を標準出力

Text file sort

sort [option]file name
Option name
-r:Sort in reverse order
-k n:Sort the data in column n
-n:Sort as a number

File comparison (diff)

diff [option]File 1 File 2
option
-c:Output difference in context diff format
-u:Output differences in unified diff format

Chapter 6 vi editor

・ Vi: A pager and an editor. Opening and closing files, saving and closing files, and other operations are possible.

command Processing content
vi [file name] Open file
:q Close file
ESC+:w Changes are written
ESC+:wq Write changes + save and exit
ESC+:q! Forced termination without saving

image

$ vi test.rb
ken ryu 80
keiko oka 40
hajime chan 100
~
~

Insert mode and command mode

-When you start the vi editor, the file is opened in the command mode for entering commands. ** To enter a character string, you need to switch to insert mode with the i command or a command **.

Move cursor

Line number Move to the specified line number G End of file h One character to the left j One character down k One character up l One character to the right w to the next word 0 at the beginning of the line $ at the end of the line

Cut and paste characters

x Delete one character dd Delete one line yy 1 line copy nyy n-line copy p Paste on the next or next line of the cursor character P Paste before or before the cursor character `ʻu`` Cancel cut and paste once

Replace and search

/ Search string Search for a string n Search downward again N Search upward again : Target line s / search character string / replacement character string / option Replace character string

String replacement

: ns / old / new Replace the first old on the nth line with new and finish : ns / old / new / g Replace all old on the nth line with new and finish :% / old / new / g Replace the search term for the entire file :% / old / new / gc Ask for confirmation every time it is replaced

Reference material

Linux standard textbook Bookmark is inevitable! Linux command list [33 types in total] [vi command](https://qiita.com/may-bee-39/items/2164819b2e27f512eefe#%E3%82%AB%E3%83% BC% E3% 82% BD% E3% 83% AB% E7% A7% BB% E5% 8B% 95) Why use Vim instead of IDE?

Recommended Posts

[Reading memo] Linux standard textbook (Chapter 1 to Chapter 6)
[Reading memo] Linux standard textbook (Chapter 7-8)
Linux standard textbook memo 1
Linux standard textbook memo 3
Linux standard textbook memo 1 part 2
Linux standard textbook memo part 6
Linux standard textbook
Linux standard textbook chapter end test answer
Linux standard textbook part 5
Linux standard textbook part 4
I read "Linux standard textbook"!
Linux x memo
Deep Learning from scratch Chapter 2 Perceptron (reading memo)
linux (ubuntu) memo
Linux # Command Memo 1
Image reading memo
[Linux] Introduction to Linux
Introduce serverspec to Linux
[For memo] Linux Part 2
Linux commands to remember
A memo on how to easily prepare a Linux exercise environment