[Linux] Review of frequently used basic commands 2

This is a continuation of the previous Review of frequently used basic commands.

Standard input / output

The standard input, standard output, and standard error output are collectively called standard input / output. Since the command input / output destination is abstracted, input / output can be handled flexibly.

Standard input

Entering a program using the keyboard.

Standard output

The output of the program shown on the display.

Standard error output

Output of the error message shown on the display.

redirect

A command that can change the input / output destination.

Input redirection

Ability to type from a file instead of the keyboard.

#/etc/Execute the cat command with hosts as the input source
cat < /etc/hosts

Output destination redirect

A function that saves the command execution result to a file instead of displaying it on the screen.

#The output destination of the ls command is ls.Save as txt
ls > output.txt
cat > output.txt

Error output destination redirect

ls /hoge 2> erro.txt
cat error.txt

Add a redirect

echo Hello! >> output.txt

pipeline

You can type multiple commands. For example, use as follows.

ls/bin | less

Allow the contents of bin to be scrolled with less.

permission

File rights management. For each file, who can perform what kind of operation is decided.

File owner

The person who created the file becomes the owner of the file.

group

Create accounts and groups allowed by the owner.

ls -l
drwxr-xr-x@ 38 root  wheel  1216  4 12 14:39 bin

In this case, the root wheel will be the owner name and group name, respectively.

Confirmation of affiliation group

id
uid=501(hukushima) gid=20(staff) groups=20(staff),12(everyone)

Check all user ids

cat /etc/passwd

Authority management (permission) method

The following articles will be helpful for reading and settings. [Understanding] Linux permission basics and how to set them

File mode conversion (chmod command)

Convert with the chmod command. A command to set permissions.

chmod [ugoa][+-=][rwx]file name

Select and set one of the following symbols one by one.

symbol meaning
u Owner authority
g Group permissions
o Privileges of other users
a Privileges of all users
symbol meaning
+ Add permissions
- Remove permissions
= Change to the described authority
symbol meaning
r Read permission
w Write permission
x Execution authority

Example

chmod u+r file

Superuser

A user with administrator privileges. You can run it with superuser privileges using the sudo command.

sudo ls
Password:*******

You will be asked for a user password, so enter it.

Process and job management

process

A running program. You can check it with the ps command.

ps
  PID TTY           TIME CMD
 2625 ttys000    0:00.07 /bin/zsh -l
 2839 ttys001    0:00.16 -zsh

Use the aux option to get a detailed view of all users' processes. (*-Not required)

ps aux

To run in the background, hit as follows.

command&

job

Commands can be executed collectively in the background (⇄ foreground). You can check the processing currently being executed with the following command.

jobs
[1]  + suspended  man bash

The [1] part is the job ID.

fg command

Return the job to the foreground and operate it interactively.

fg %Job ID

bg command

By executing a process that takes a long time in the background, you do not have to wait for the command to finish.

bg %Job ID

By the way, you can pause the command with ** control + z **.

kill command

End a process or job.

kill (optional)%Job ID
kill (optional)%Process ID

Use the following options for forced termination.

kill -SIGKILL process ID

Summary

This completes the basic Linux commands.

It was too painful while I was playing with AWS, but I'm glad that I was able to do this kind of study as a result.

I want to cherish the thorough foundation so that it will not become a tower on the sand.

Recommended Posts

[Linux] Review of frequently used basic commands 2
[Linux] Review of frequently used basic commands
List of frequently used Linux commands
Frequently used Linux commands
Frequently used Linux commands
Frequently used linux commands
[Linux command] A memorandum of frequently used commands
Basic knowledge of Linux and basic commands
Linux Frequently Used Commands [Personal Memo]
[Linux] Frequently used Linux commands (file operation)
Frequently used Linux commands (for beginners)
[Anaconda3] Summary of frequently used commands
[Linux] Frequently used Linux commands (folder operation)
Basic LINUX commands
Summary of frequently used commands of django (beginner)
Summary of frequently used commands in matplotlib
[Linux] List of Linux commands used in practice
pyenv Frequently used commands
Frequently used tmux commands
Frequently used pip commands
[Linux] Review of commands for deploying on AWS
[Python/Django] Summary of frequently used commands (3) <Operation of PostgreSQL>
[Python/Django] Summary of frequently used commands (2) <Installing packages>
Summary of frequently used commands (with petit commentary)
[Python/Django] Summary of frequently used commands (4) -Part 2- <Production operation: Amazon EC2 (Amazon Linux 2)>
[Python/Django] Summary of frequently used commands (4) -Part 1- <Production operation: Amazon EC2 (Amazon Linux 2)>
A collection of commands frequently used in server management
Frequently used subpackages of SciPy
Frequently used commands in virtualenv
Display a list of frequently used commands on Zsh
8 Frequently Used Commands in Python Django
About Linux commands Super basic edition
Linux commands
Linux commands
linux commands
Basic commands
Linux commands
Linux commands
[Linux] Summary of middleware version confirmation commands
Basic usage of Btrfs on Arch Linux
Summary of petit techniques for Linux commands
[Linux] Learn the basics of shell commands
[Machine learning] List of frequently used packages
[Linux] Basic settings after OS installation of CentOS 7.3
Network Linux commands
Linux command <Basic 2>
Verbalize Linux commands
List of frequently used built-in functions and methods
Review of exceptions
Linux user commands
[Basic] linux command
New Linux commands! !!
This is the only basic review of Python ~ 1 ~
This is the only basic review of Python ~ 2 ~
Frequently used methods of Selenium and Beautiful Soup
Summary of frequently used Python arrays (for myself)
Linux command <Basic 1>
This is the only basic review of Python ~ 3 ~
Selenium webdriver Summary of frequently used operation methods
Various Linux commands
Typical Linux commands (7)