This is a continuation of the previous Review of frequently used basic commands.
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.
Entering a program using the keyboard.
The output of the program shown on the display.
Output of the error message shown on the display.
A command that can change the input / output destination.
Ability to type from a file instead of the keyboard.
#/etc/Execute the cat command with hosts as the input source
cat < /etc/hosts
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
ls /hoge 2> erro.txt
cat error.txt
echo Hello! >> output.txt
You can type multiple commands. For example, use as follows.
ls/bin | less
Allow the contents of bin to be scrolled with less.
File rights management. For each file, who can perform what kind of operation is decided.
The person who created the file becomes the owner of the file.
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.
id
uid=501(hukushima) gid=20(staff) groups=20(staff),12(everyone)
cat /etc/passwd
The following articles will be helpful for reading and settings. [Understanding] Linux permission basics and how to set them
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
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.
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&
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.
Return the job to the foreground and operate it interactively.
fg %Job ID
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 **.
End a process or job.
kill (optional)%Job ID
kill (optional)%Process ID
Use the following options for forced termination.
kill -SIGKILL process ID
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