I've summarized what I've learned about Linux. Feel free to point out any incorrect information!
RedHat system |
---|
Red Hat Enterprise Linux |
CentOS |
Fedora |
Debian system |
---|
Debian GNU/Linux |
Ubuntu |
Windows |
---|
PuTTY |
TeraTerm |
MacOS |
---|
Terminal |
iTerm2 |
Linux |
---|
GNOME terminal |
Konsole |
shell | Commentary |
---|---|
sh | AT&Shell developed by Steven Bourne of T-Bell Labs Sometimes called the Bourne shell or the B shell The oldest shell Fewer features Very inconvenient to use interactively |
csh | Old shell C shell Interactive operation is more convenient than sh The grammar is very different from sh and is flawed It is rarely used because it has tcsh as a successor |
tcsh | C shell type shell developed as a successor to csh Not often used now |
bash | Shell with extended functions based on sh Backwards compatible with sh It has enough functions for interactive operation and Used as the default login shell in many Linux environments Also suitable for writing shell scripts |
zsh | New shell A shell that actively incorporates the functions of other shells such as bash and tcsh, and adds its own extensions. Has so many features It takes time to master all the features, but once you get used to it, you can work very efficiently, which is a popular shell. Not a shell for beginners |
We recommend using a bash shell that is backwards compatible with sh. There is no reason to start using tcsh or csh zsh is highly functional
the term | meaning | Remarks |
---|---|---|
yank | About paste | |
Hard link | Give the file an alias | A concept that is probably not for mac or windows 全てのHard linkが削除されることでそのファイルが削除される |
Symbolic link | Shortcuts for mac and windows | ショートカット先のファイルが消えると該当のSymbolic linkはエラーとなる |
alias | Functions to make commands easier to use | |
Locale | Identifier to identify language, country, region, etc. | |
External command | Commands that exist on the file system | |
Built-in commands | Commands built into the shell itself | |
Environment variable | Variables that can be referenced from external commands | |
permission | A representation of access privileges -Represented by 10 characters, such as rwxrwxrwx The first character is-Normal file, d directory, l symbolic link The 2nd to 4th characters indicate the owner's access authority, the 5th to 7th characters indicate the group access authority, and the 8th to 10th characters indicate the other user's access authority. r is an abbreviation for read, w is an abbreviation for write, and x is an abbreviation for execute. |
|
process | A unit of processing as seen from the Linux kernel. Has a unique system-wide ID | |
job | A unit of processing as seen from the shell. Have a unique ID for each shell | |
channel(Channel) | channel. Data flow path | |
stdin | Standard input | I / O channel is 0 |
stdout | Standard output | I / O channel is 1 |
stderr | Standard error output | I / O channel is 2 |
redirect | A function to change the standard input / output destination | |
pipeline | Connect the standard output of a command to the standard input of another command | |(Half size)use |
filter | A command that takes standard input as input and outputs it to standard output | |
Interactive editor | Open the file in an editor, edit and save | |
Non-interactive editor | Performs processing for the given command and outputs |
command | meaning | Remarks |
---|---|---|
shutdown -h now | shut down | nowの部分は何分後にshut downするかを指定できる Now means right now |
shutdown -r now | Reboot | nowの部分は何分後にRebootするかを指定できる Now means right now |
date | Display date | Sunday, October 25, 2020 01:20:18 JST |
echo | Display of character string | |
chsh | Switch shell | You may not be able to log in, so use is not recommended. |
reset | Terminal reset | |
printenv | List environment variables | |
pwd | Show current directory | |
ls -l | View files and folders in the current directory | ls stands for list |
mkdir | Create directory | -pをつけると一気に深いところまでCreate directory可能 |
rm | File deletion | |
rm -r | File+Directory deletion | |
cat | View the contents of the file | con"cat"Abbreviation for enate Meaning to connect |
cat -n | Display the contents of the file with line numbers | |
less | Show the contents of the file by scrolling | Operation during less f 1 Scroll down the screen b 1 Scroll on screen j Scroll down one line k Scroll up one line 1 end /String search n Move to next search result N Move to previous search result |
cp | copy | |
mv | File name change | |
mv | Move file | |
ln | Create a hard link | ln Link source name |
ln -s | Create a symbolic link | ln -s Link source name |
command--help | Show command usage | |
man command | View how to use commands in the online manual(I don't connect to the internet to see it) | Operations in man f 1 Scroll down the screen b 1 Scroll on screen j Scroll down one line k Scroll up one line 1 end /String search n Move to next search result N Move to previous search result |
which | Environment variable$Display the full path of the first command found under the directory pointed to by PATH | Environment variable$Searching under the directory pointed to by PATH |
which -a | Environment variable$Display the full path of all commands under the directory pointed to by PATH | Environment variable$Searching under the directory pointed to by PATH |
Variable name=value | 変数にvalueを入れる | var1='test variable' =Do not leave spaces on the left and right of |
locale -a | Display a list of locales available on your system | |
type command | Check if it is an alias or a built-in command | |
alias name=command | commandを名前のエイリアスにする | |
unalias name | Remove the alias | |
command command | Run the command without an alias | |
\command | エイリアスなしでcommandを実行する | |
set | Display variable list | |
unset | Delete variable | |
set -o Option name | Turn on the option | The options of the set command are summarized in a separate table. |
set +o Option name | Turn off the option | The shopt command options are listed separately. |
shopt -s option name-v Option name | -Turn on the option specified by s,-Turn off the option specified by v | |
export shell variable name | Set the shell variable name as an environment variable | |
source file name | Execute the contents described in the file directly on the command line | |
groups | Show which group you currently belong to | |
chmod [ugoa][+-=][rwx] |
Change permissions in symbol mode [ugoa] u:Owner g:group o:Other users a:ugo all(If omitted, it becomes a) [+-=] +:Add permissions -:Prohibit authority =:Equal to the specified authority [rwx] r:reading w:writing x:Run |
[command] chmod ugo=rw [meaning]Owner、group、その他ユーザーのパーミッションをrwにする |
chmod 3-digit octadecimal file name | rwx rwx Specify 777 when specifying rwx | |
su | Switch to superuser | Abbreviation for switch user |
su - | Initialize and switch to the superuser environment | -If you do not add, the environment variables will be inherited and it may not work well depending on the application. Normally-Execute with |
sudo | Run the command as superuser | Used when you want to temporarily execute commands as superuser Whether it can be used or not/etc/to sudoers%wheel ALL=(ALL)Whether it is described as ALL* Do not modify with vim. What to do with the visudo command |
visudo | While checking for syntax errors/etc/Rewrite sudoers | |
ps | View running processes | x:View all processes of the user who executed ux:View all processes of the running user with detailed information ax:View processes for all users aux:View all users' processes with detailed information auxww:Display all without limiting the display width(Other than that, it is the same as aux) |
jobs | Display job list | -The process ID is also displayed with the l option. |
fg %Job number | Bring a stopped job to the foreground | Job numberを省略するとjobsで+The current job with is in the foreground |
bg %Job number | Run a stopped job in the background | Job numberを省略するとjobsで+The current job with is in the background |
command& | Run in the background | |
kill %Job number | End the job | |
kill process number | End the process | Another user's process cannot be terminated. However, the superuser can terminate the process for all users |
kill -Signal process number | Send a signal to the process | The signals are summarized as a list of signals available with the kill command. |
command<File | Execute command by changing standard input from keyboard to file | commandファイルと同じ動作 |
command>File | Change the standard output from the display terminal to a file and execute the command | The file is automatically generated, so there is no need to create it in advance. |
command>File 2>Error file | Change the standard output from the display terminal to a file, change the standard error output from the display terminal to the error file, and execute the command. | |
command>File 2>&1 | Display standard output and standard error output together Change from terminal to file and execute command | &1 refers to standard output |
command>>File | Change the standard output from the display terminal to a file by adding it to the end of the file and execute the command | |
head | A command that outputs only the specified number of lines from the beginning of the file to standard output | |
tail | A command that outputs only the specified number of lines from the end of the file to standard output | -If f is added, it will be monitored every time it is added. |
grep | Show only lines that match the specified search pattern | |
sort | Sort in order | |
uniq | Remove duplicate lines | -Count duplicate lines with c |
taq | Output in reverse order | |
wc | Output the number of lines and bytes | Display in the order of the number of lines, the number of words, and the number of bytes.-Output only the number of lines with l,-Output only the number of words with w,-Output only the number of bytes with c |
du -b | Display the used capacity of the specified file or directory in bytes | |
diff | Compare files | |
sed | Edit the file using a non-interactive editor | You can delete or replace lines using regular expressions in scripts |
awk | It is suitable for displaying the number of data to be displayed separated by spaces. | Read as oak Scripting languages such as Ruby and Python are often used for full-scale text processing. |
variable | Explanation | Remarks |
---|---|---|
PS1 | The string displayed at the prompt By default[\u@\h \W]$It has become Result is[root@localhost work]#become |
\u:username \w:Current directory \h The first of the host names.Part up to \d:date \H:hostname \n:new line \t:HH:MM:Current time in SS format \W:Current directoryの末尾のディレクトリ名 \\$:For root user#, For other users$ \\:Itself |
PS2 | A character string displayed at the prompt, such as waiting for input By default>Is becoming |
|
PATH | The directory where the shell looks for commands:Strings concatenated by delimiters | PATH if you want to add a directory to the end="$PATH: ~/bin"To do |
LANG | Locale. The language to display and the date format are decided | |
HISTFILE | File name to save command line history | The default is~/.bash_history |
HISTFILESIZE | Maximum number of lines of command line history to save in a history file | |
HISTSIZE | Maximum number of lines to save command line history | |
HOME | Home directory | |
SHELL | Login shell path | |
PWD | Current directory | |
LESS | Environment variables that represent options that are automatically executed when less is executed | The default is empty |
operation | meaning | Remarks |
---|---|---|
control+b | Move the cursor one left | b is back(back)means |
control+f | Move the cursor one left | f is forward(Previous)means |
control+a | Move the cursor to the beginning | |
control+e | Move the cursor to the end | |
Press and release esc b | Move the cursor word by word to the left | b is back(back)means |
Press esc and then release f | Move the cursor word by word to the right | f is forward(Previous)means |
control+w | Delete from the cursor position to the left space | |
control+k | Delete from the cursor position to the end of the line | |
control+u | Delete from the cursor position to the beginning of the line | |
control+y | yank(pasting) | |
control+l | Clear display characters | Use quite often |
control+r | Incremental search for commands | Operations during incremental search Search by entering a character string control+r Search one before esc Return with the currently displayed command control+g Discard search results and return |
control+z | Stop the command | The command is not terminated, but can be resumed with the fg command. |
directory | meaning |
---|---|
/bin | Contains the minimum important commands required for the operation of Linux systems |
/dev | Stores device files prepared so that hardware such as disks and keyboards can be treated as files. |
/etc | Directory for placing configuration files Files related to the settings of Linux itself are also in this directory |
/home | Home directory Below this is a directory for each user ユーザーはこのHome directory内に自由にファイルやディレクトリを作成して作業を行うことができる |
/sbin | Directory for placing executable files Contains commands for admin users |
/tmp | Directory for temporary files Files in this directory are set to be deleted regularly |
/usr | Directory for storing various applications and their accompanying files |
/var | Directory for storing changing data |
symbol | meaning | Remarks |
---|---|---|
$ | General user | |
# | Superuser | |
. | Current directory | |
/ | File path delimiter | |
* | Arbitrary string | |
? | Any one character |
Uninflected form of find to search files.sample
find <① Search start directory> <② Search conditions> <③ Action>
① Search start directory | meaning |
---|---|
. | Current directory |
② Search conditions | meaning | Remarks |
---|---|---|
-name "*.txt" | Case sensitive.Search for files ending in txt | |
-iname "*.txt" | Case insensitive.Search for files ending in txt | |
-type f | Search for regular files | |
-type d | Search directory | |
-type l | Search for symbolic links | |
-type f -a -name '*.txt' | The file name is a normal file.Search for files ending in txt | -a means and By the way-a can be omitted |
③ Action | meaning | Remarks |
---|---|---|
Display the path name | If you omit the action-become print |
Use locate for high-speed file search Unlike find, it uses the database after creating it in advance, so unlike find, which starts searching on the spot, file search can be performed at a considerably high speed. Not available by default Run locate --version and if nothing is found you need to install with yum or apt-get
For centos.sample
sudo su
yum -y install mlocate
for ubuntu.sample
sudo su
apt-get install mlocate
After installing mlocate, register the file path list in the database with updatedb After executing it once, the database is automatically updated by the locate command, so there is no need to execute it again.
Common to centos and ubuntu.sample
updatedb
When searching for files with locate, use the following format
Uninflected form of locate for file search.sample
locate [① Option]<② Search pattern>
① Option | Explanation | Remarks |
---|---|---|
-i | Case insensitive | i is ignore_Abbreviation for case |
-b | Search only file names | b is an abbreviation for basename |
-a | AND search |
② Search pattern | Explanation |
---|---|
"*.txt" | .Search for files containing txt |
"bash" "doc" | "bash"Or"doc"Search for files containing |
the term | Explanation | Remarks |
---|---|---|
delete | About the cut | |
yank | About copying | ややこしいけどLinuxでのyankとまた意味が異なる |
Put | About paste |
command | Explanation | Remarks |
---|---|---|
vim --version | Check vim version | Version is not displayed if it is not installed |
yum install vim | install vim(CentOS) | |
apt-get install vim | install vim(Ubuntu) | |
vim filename | Open text in vim | |
vimtutor | Start vim tutorial | If you are new to vim, you should definitely give it a try. |
Normal mode
command | Explanation | Remarks |
---|---|---|
h | ← | Faster than cursor keys once you get used to it |
j | ↓ | Faster than cursor keys once you get used to it |
k | ↑ | Faster than cursor keys once you get used to it |
l | → | Faster than cursor keys once you get used to it |
x | Delete one character | Same operation as dl |
i | Put in insert mode | Abbreviation for insert |
a | Put in insert mode | The difference from i is that the cursor is on the right side of the cursor position. |
0 | To the beginning of the line | |
$ | To the end of the line | |
w | Move the cursor to the right with a symbol delimiter | |
b | Move cursor to the left separated by symbols | |
W | Move cursor to the right separated by spaces | |
B | Move cursor to the left separated by spaces | |
gg | Jump to the first line | |
100G | Jump to line 100 | |
G | Jump to the last line | |
:q | Exit without saving | |
:q! | Forced termination without saving | |
:w | Save | |
:w file name | Save as | |
:wq | Save and exit | |
dd | Line delete | |
d$ | Delete until the end of the line | |
d0 | Delete to the beginning of the line | |
dl | 1 character delete | |
dw | Delete one word | |
dgg | Delete to the first line | |
dG | Delete to the last line | |
yy | Line Yank | |
y$ | Yank until the end of the line | |
y0 | Yank to the beginning of the line | |
yl | 1 letter yank | |
yw | One word yank | |
ygg | Yank to the first line | |
yG | Yank to the last line | |
p | Delete, put yanked string(pasting) | |
J | Concatenate the current line and the line immediately below | If it is x, the line break cannot be erased, so use it at that time. |
u | undo | Undoing the last operation |
control+r | Redou | Canceling undo |
/Search string | Search for strings downwards | Search from the current cursor position, so enter gg before searching. n for next, N for previous |
?Search string | Search for strings upwards | Search from the current cursor position n for next, N for previous |
:%s/Replacement source string/Character string after replacement/g | ||
:help | Help command | Since there is a link, control on the link+]You can fly by pressing Control to return from the link+t |
:help command | Display command help |
Insert mode
command | Explanation | Remarks |
---|---|---|
esc | To normal mode |
option | Operation when ON | Remarks |
---|---|---|
ignoreeof | control+Pressing D does not exit the shell | |
noclobber | Do not overwrite existing files with redirects | |
noglob | Disable pathname expansion | As it isbecome |
option | Operation when ON | Remarks |
---|---|---|
autocd | When you execute the command with the directory name, it is executed as specified in the argument of the cd command. | |
dotglob | *Or?As a result of the pass name store meeting using.Include files starting with | |
cdspell | When executing the cd command, automatically correct a small mistake and execute it. | |
globstar | By expanding the path name**Uses the pattern to match all files, including subdirectories | |
histappend | When exiting bash, add the command history to the history file and do not overwrite it | |
sourcepath | Do not search the search path with the source command |
setting file | Explanation | Remarks |
---|---|---|
/etc/profile | The shell script that is called first when the shell starts | Appropriate settings are pre-written for each distribution and do not need to be modified |
~/.bash_profile | /etc/Shell script called after profile | Loaded only when logged in |
~/.bashrc | fundamentally~/.bash_Shell script called from profile It's also a shell script that is loaded every time you start bash |
fundamentallyこのファイルだけ修正すればいい |
signal | number | Explanation | Remarks |
---|---|---|---|
SIGKILL | 9 | Kill the process | Last resort when the process does not end |
SIGTERM | 15 | End the process | Default signal for kill command |
SIGTSTP | 20 | Pause the process | control+Same as z |
SIGINT | 2 | End the process | control+Same as c |
Other | Commentary |
---|---|
ls -File type displayed by F | Normal file without symbol /directory *Executable @Symbolic link |
Behavior when a command succeeds on Linux | Success if nothing is displayed |
-r | Mostly recursive options(Means to target files and folders under the directory) |
The meaning of links in Linux | alias |
Linux Japanese manual | http://linuxjm.sourceforge.jp/ |
To execute a command without an alias | Execute the command with the full path |
source ~/.bashrc | Without restarting bash.Execute when you want to reflect the bashrc settings immediately |
/dev/null | A special file called a special file. No content is returned even if it is specified as an input destination. Even if you specify it as the output destination, the written data will not be saved anywhere and will disappear |
Recommended Posts