--About Linux --Basic commands --Server settings --Process display --Combine multiple commands on the terminal
I wrote a review of Linux commands for deploying applications to production on AWS.
I've used commands many times on my Mac, but I thought it was suspicious in the first place, so I read through it and relearned. Linux is one of the types of OS such as Mac, and is an OS (operating system) that is widely used for smartphones, web applications, routers, and so on. The OS is a basic program such as a PC. It has functions such as inputting characters when you hit the keyboard and operating the screen with a mouse. Other than Linux, there are Mac and Windows as OS.
Features of Linux ・ Open source (Public code can be used, modified, and reused by anyone) -Can be operated with commands, easy to automate and easy to operate the server ・ Some license fees are not incurred ・ Many compatible software allows you to use high-quality software.
Package manager This is a program that installs, updates, or removes new software. Execute it using the yum command. -Yum install package name (package installation) ・ Yum update (package update) -Yum erase package name (delete package) -Yum lis (lists installed)
When working with Linux, type in a terminal and run the command. The software that interprets the command entered at this time is called a shell.
A list of directories and files that are one of the current directories is displayed. (A directory is a folder) There are more directories and files under the directory, and it has a hierarchical structure. ・. (Dot) Current directory (currently working) ・ .. Parent directory (directory one level higher) ・ ~ Home directory (when a new terminal is launched) -/ Root directory (top directory in hierarchical structure)
This is a command to copy a file. cp file name (copy source) File name (copy destination)
This command is used when you want to rename or move a file. mv Original file name File name with new name mv File you want to move Destination directory
mkdir directory name (create a new directory one level below) touch file name (create new file)
This command displays and combines the contents of files. cat file name cat file name File name (3 files can be combined)
tail -f error.log This command is for checking the error log in a file called error.log. -f is an option added, and the error log will be displayed automatically whenever a new error occurs. To end the error log display, press Carl + C. vi You need an editor when you want to edit a file on the server. Software called vi is installed as standard on CentOS and Amazon Linux, so we will use this. To use it, first open the file. You can start it by typing the vi file name and terminal. If the specified file does not exist, a new one will be created. If created, the terminal will display the file name New File.
The vi editor has two modes. ・ Normal mode : W Save created and edited files : Q end vi command : Q! Quit the vi command without saving the edited content : Wq Save the edited content and exit the vi command
・ Insert mode Since you cannot enter characters in normal mode, switch to insert mode. Must be Press i to enter insert mode. Esc switches to normal mode.
/ Is used to search for strings in the vi editor. Enter the character string you want to search after /.
u (Undo) can erase one action that affected the file from the time the character is inserted until after it is inserted.
Linux allows multiple users to work on one machine. Therefore, if there are files that you do not want other users to see, they may be viewed or edited.
Here we will write about users and permissions. ・ Root user You have view and edit permissions for everything, including other user files. ·General user Only permitted files can be viewed and edited.
The sudo command can execute commands on behalf of other users. You must be authorized to use sudo before you can do this.
The su command allows you to log in again as another user. You need to know the user's password before you can log back in.
Permission is permission information to allow who can operate a directory or file to what extent. For authority, ・ R Read (authority to see the contents of the file) -W write (authority to write to a file) -Execution x (permission to execute files) there is.
The user who created the file is called the owner, but if you do not want other users to edit it, you can give write permission only to the owner so that it will not be changed by other users.
If you want to check the permissions, ls -l You can check by entering the path of the file you want to check.
・ Chmod command It is a command to rewrite the access authority. chmod Privilege to give (r, w, x) Directory name or file name and input
・ Chown command A command to change the owner of a directory or file. chown owner directory name or file name and input
When building a server, you may need to check the commands you have executed. A process is a process that is processed by executing a command on Linux.
To see the process, run the ps command. When you run the command, you'll see a line-by-line process. Some ps command options are listed below.
-A Display processes of users other than yourself -R Show only running processes -U Username You can check the user name and the time of the executed process. · Aux Displayed with detailed information (CPU usage, etc.) for all running processes
To combine multiple commands, use what is called pipe processing. For pipe processing, enter | (shift key + ) as shown below.
-First command executed | Command that receives the command processing on the left and returns the final result Display the list in the directory like ls | grep p Make ls finally display files containing the character p. The grep command is a command for extracting those that contain a specific character.
-Kill command By specifying the process id, you can terminate or forcibly terminate the process.
kill process id (process end) kill -9 process id (process kill)
I reviewed it because I often use command input to build an application environment on an EC2 instance. I will continue to study.
Recommended Posts