[LINUX] A collection of commands frequently used in server management
There was a request from our young people, so I summarized it.
File related
- cd
Move - directory. dd>
```
cd /home/okuno/
```
- cat
Display the contents of the - file. Display one screen at a time with less. dd>
```
cat access.log | less
```
- tail
- Display the latest 〇 items in the file. Updated in real time with the f option. dd>
```
tail -1000 access.log | less
tail -f access.log
```
- vim
- vi uses vim because some distributions have a traditional keyboard layout (which isn't the case these days). dd>
```
vim /etc/apache2/httpd.conf
```
- cp
Copy the - file. Often the whole copy is done with -a. dd>
```
#Whole copy
cp -a /from/* /to/
```
- mv
- Move the file. dd>
```
mv /from/file.txt /to/
```
- tar
Unzip the - file. Learn as a set with options. dd>
```
tar zxvf hoge.tar.gz
```
- rm
Delete the - file. The -f option has excellent destructive power, so refrain from executing it as root as much as possible. Relative paths are somewhat more secure. dd>
```
#Superlative command
rm -rf gomi
```
- df
- Check the disk capacity. Optimize display capacity with -h. dd>
```
df -h
```
- du
- Check the capacity for each layer. Since it is often summarized in the first layer, copy it. dd>
```
du --max-depth=1 -h
```
- locate
Search - files fast. updatedb will create the latest database. dd>
```
locate sagashimono.txt
```
- find
Search for - files. Please note that it may take some time. dd>
```
#Find by date
find ./* -newermt '20190517 17:00'
```
## Process management
- ps
- Show running processes. In many cases, ax and grep are used. dd>
```
ps ax | grep apache2
```
- kill
- Terminate the running process. I often use forced termination and restart. dd>
```
#forced termination
kill -9 [Process number]
#Reboot
kill -HUP [Process number]
```
- uptime
- Displays the current time, server operating time, number of connected users, and load status (load average). dd>
```
uptime
```
Login relationship
- last
- Display login history. Display one screen at a time with more. dd>
```
last | more
```
- who
- Show the currently logged in user. dd>
```
who
```
- vlock
- Lock the console screen. You will need to enter the password to start again, and you can prevent mistakes while working at the same time. dd>
```
vlock
```
## Communication relations
- ping
- Simple communication confirmation. dd>
```
ping ww-system.com
```
- netstat
- Check the communication connected to the server. dd>
```
netstat
```
- traceroute
- Check the communication path. dd>
```
traceroute ww-system.com
```
- dig
- Check DNS. dd>
```
#When specifying a DNS server
dig @localhost ww-system.com
```
- nslookup
- Check DNS. Part 2. mx Used when checking records. dd>
```
nslookup
>set type=mx
>ww-system.com
>Exit with exit
```
- mail
- Confirm the sending of the email. dd>
```
mail
[email protected]
Subject:test [Ctrl + D]
Cc:[Enter]
Null message body; hope that's ok sends a simple email with a blank body
```
- wget
- Get the file from an external server. dd>
```
wget https://hogefuga.loc/piyo.tar.gz
```
- iptable
- Implement a firewall with software. There are many IP denials. Recent Debian is managed by ufw, so use it conveniently. dd>
```
#Deny IP
iptables -I INPUT -s ***.***.***.*** -j DROP
```
## Package management
- systemctl
- Start / stop the service. dd>
```
systemctl start apache2
```
- cpan
- Perl module management. Recently, the number of modules that can be managed by yum has increased. dd>
```
cpan
```