I want children who are inexperienced and newly participating in the project to remember I will describe the Linux command.
・ Inexperienced new engineer
Pipes can pass command I / O to the (next) command. It is used when using a combination of commands. I use it very often. command | command
① $ ps -ef UID PID PPID C STIME TTY TIME CMD ... root 1 0 0 Mar09 ? 00:00:02 /usr/lib/systemd/systemd --switc root 2 0 0 Mar09 ? 00:00:00 [kthreadd] root 4 2 0 Mar09 ? 00:00:00 [kworker/0:0H] root 6 2 0 Mar09 ? 00:00:00 [mm_percpu_wq] root 7 2 0 Mar09 ? 00:00:00 [ksoftirqd/0] root 8 2 0 Mar09 ? 00:00:00 [rcu_sched] Inon 11129 10953 0 04:51 pts/0 00:00:00 ps -ef ... ② $ ps -ef | grep apache UID PID PPID C STIME TTY TIME CMD apache 11256 11255 0 04:53 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 11257 11255 0 04:53 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 11258 11255 0 04:53 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 11259 11255 0 04:53 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 11260 11255 0 04:53 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND root 11304 11133 0 04:53 pts/0 00:00:00 grep --color=auto apache ③ $ ps -ef | grep -v grep | grep apache UID PID PPID C STIME TTY TIME CMD apache 11256 11255 0 04:53 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 11257 11255 0 04:53 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 11258 11255 0 04:53 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 11259 11255 0 04:53 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 11260 11255 0 04:53 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
When you want to check the Apache process, use the ps command to check the process. It is troublesome to search for Apache one by one from the many displayed processes, so at that time pipe (and You can save time by using the grep command). ps -ef | grep apache Output the process being executed by the ps -ef command, and from the output result The part corresponding to apache is output by the grep command.
Pipes are used really often and need to be remembered.
** Command to move directories **.
$ pwd /tmp/test/app/logs $ cd .. $ pwd /tmp/test/app
This command moves the directory up one level. It's convenient to remember.
$ pwd /var/log $ cd /tmp/test/app/logs/ $ pwd /tmp/test/app/logs $ cd - /var/log
cd-can go back to the previous directory. In the above case, I was originally in / var / log and moved to / tmp / test / app / logs / It looks like a log again in / var / log! It can be used when it becomes. I use it once in a while.
ls A command that displays files, directories, and detailed information about them.
$ ls test test1.tar test3.tar
If there is no option, only files / directories will be displayed.
$ ls -l total 24 -rw-r--r-- 1 root root 0 Mar 11 10:47 nemui111 drwxrwxr-x 3 ec2-user ec2-user 17 Mar 10 05:40 test -rw-r--r-- 1 root root 0 Mar 11 10:47 test111 -rw-r--r-- 1 root root 10240 Mar 11 09:54 test1.tar -rw-r--r-- 1 root root 10240 Mar 11 10:06 test3.tar
$ ls -ltr total 24 drwxrwxr-x 3 ec2-user ec2-user 17 Mar 10 05:40 test -rw-r--r-- 1 root root 10240 Mar 11 09:54 test1.tar -rw-r--r-- 1 root root 10240 Mar 11 10:06 test3.tar -rw-r--r-- 1 root root 0 Mar 11 10:47 test111 -rw-r--r-- 1 root root 0 Mar 11 10:47 nemui111
If you do not add the option -r, the files and directories will be displayed in order from the top. In order to reverse the order, -r is added so that it can be seen immediately from the bottom.
This command displays the contents of the file.
$ cat test1 Hello World!
If you cat a file called test1 that says Hello World! The output result will be as shown above.
$ cat -n test1 1 root cd 2 Inon exit 3 root view 4 root tar 5 6 Inon ps 7 Inon grep 8 Inon cat 9 Inon vi
The -n option can be displayed with a line number at the beginning of the line. Even if there is a blank line, it will be displayed with a line number.
$ cat -b test1 1 root cd 2 Inon exit 3 root view 4 root tar 5 Inon ps 6 Inon grep 7 Inon cat 8 Inon vi
The -b option allows blank lines to be displayed without line numbers.
All you have to do is remember the above.
A command to start a text editor. If the file exists, open it for editing, otherwise create a new one. Other than vi, there are also nano commands. vi may be hard to remember at the beginning, but commands you absolutely must remember So let's do our best to remember it.
vi has the following two modes
|Edit mode||This mode is for entering characters in a file.|
|Command mode||This mode is used to execute commands.|
Enter characters in edit mode, save in command mode, or search for characters in a file. You can switch from edit mode to command mode with the ** ESC key **. In command mode When you enter, the input result is displayed in the lower left.
The commands in command mode are listed below.
|End||:q||Exit without saving|
|End||:q!||Edited but exited without saving|
|End||:w||Save and continue editing|
|End||:wq! / ZZ||Save and exit|
|Move to edit mode||i||Insert characters from the current cursor position|
|Move to edit mode||A||Insert character from the end of the current cursor line|
|Move to edit mode||a||Insert characters from behind the current cursor position|
|Move to edit mode||O||Insert line before the current cursor|
|Move to edit mode||o||Insert line next to the current cursor|
|Move||1G||Move to the beginning of the sentence|
|Move||G||Move to the end of the sentence|
|Move||0||Move to the beginning of the line|
|Move||&||Move to the end of line|
|Move||ctrl + f||Move to the next screen|
|Move||ctrl + b||Move to the previous screen|
|Search||n||/Or?After searching with, search for the next candidate in succession|
|Search||N||/Or?After searching with, search for the previous candidate in succession|
There are many others, but I wonder if I should remember the above for the time being.
view Browsing command. The basic operation of command mode is the same as vi and cannot be edited.
This command searches for and outputs a character string in a file.
$ grep root test1 root cd root view root tar root rm root df root cd
In this case, we are looking for the string root in file test1. Another option I often use is the option **-e **, which is used when using regular expressions for searching. grep is often used in the form ** command1 | grep XX **.
ps It is used when checking the process.
$ ps PID TTY TIME CMD 3377 pts/0 00:00:00 bash 3560 pts/0 00:00:00 ps
It looks like this with only ps. The following ** options ** are often used by me.
|-e(-A)||Show all processes|
$ ps -ef UID PID PPID C STIME TTY TIME CMD root 1 0 0 08:08 ? 00:00:01 /usr/lib/systemd/systemd --switc root 2 0 0 08:08 ? 00:00:00 [kthreadd] apache 3567 3566 0 09:08 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND root 3640 2 0 09:14 ? 00:00:00 [kworker/0:1] ec2-user 3641 3377 0 09:15 pts/0 00:00:00 ps -ef
Then, display and use only the process you want to check with pipe and grep. I often go there.
df This command checks the free disk space.
$ df Filesystem 1K-blocks Used Available Use% Mounted on devtmpfs 485480 0 485480 0% /dev tmpfs 503480 0 503480 0% /dev/shm tmpfs 503480 408 503072 1% /run tmpfs 503480 0 503480 0% /sys/fs/cgroup /dev/xvda1 8376300 1437988 6938312 18% / tmpfs 100700 0 100700 0% /run/user/1000
option I often use **-h ** as an option.
|-h||Display in optimal units|
|-k||Display in KB|
|-m||Display in MB|
$ df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 475M 0 475M 0% /dev tmpfs 492M 0 492M 0% /dev/shm tmpfs 492M 408K 492M 1% /run tmpfs 492M 0 492M 0% /sys/fs/cgroup /dev/xvda1 8.0G 1.4G 6.7G 18% / tmpfs 99M 0 99M 0% /run/user/1000
du This command checks the disk usage. option
|-h||Display in optimal units|
|-k||Display in KB|
|-m||Display in MB|
|-s||Show only directory totals|
$ du -sh /var/ 214M /var/
tar A command to create / extract / decompress an archive. option
|-f||File name specification|
|-v||View processed files|
|-x||Extract from archive|
|-z||Compress archive in gzip format/Defrost|
$ tar -cvf test1.tar test test/ test/app/ test/app/conf/ test/app/logs/ test/app/bin/
$ tar -xvf test1.tar test/ test/app/ test/app/conf/ test/app/logs/ test/app/bin/
You can see that it can be compressed / decompressed by using the ls command respectively.
$ tar -zcvf TEST.tar.gz test01 test01/ test01/app/ test01/app/conf/ test01/app/logs/ test01/app/bin/
$ tar -zxvf DD.tar.gz test01/ test01/app/ test01/app/conf/ test01/app/logs/ test01/app/bin/
You can see that it can be compressed / decompressed by using the ls command respectively. For tar, you should remember to create .tar and .tar.gz, decompress, compress and decompress.
whoami This command displays the current user name.
$ whoami Inon
If you execute the command as an Inon user, Inon will be returned. The user is correct before work, isn't it? It is used when confirming.
It's important for inexperienced / novice engineers (as well as me) to remember the commands Above all, I think it is most important to make sure to report, contact, and consult.