Linux common operations, commands

Every time I go to the Internet to search, organize it and use it as a dictionary.

1. Unzip

tar zxvf xxxx.tar.gz ---- extract to the current folder
tar zxvf xxxx.tar.gz -C /usr/local/bin/ ---- extract to /usr/local/bin/

 2. Move files/folders/rename

mv src dst

 3. Copy

    local copy

cp src dst ---- local copy
    Remote Copy (remote -> local)
scp account@ip: remote path local path----copy file
scp -r account@ip:remote path local path----copy folder
    Remote replication (local -> remote)
scp local path account@ip:remote path----copy file
scp -r local path account@ip:remote path----copy folder
4. Open ports
vi /etc/sysconfig/iptables --> Edit the file and add the following
    -A INPUT -m state --state NEW -m tcp -p tcp --dport port number -j ACCEPT
service iptables restart --> restart the firewall (iptables) to make it take effect

   centos7

firewall-cmd --list-ports #View open ports
firewall-cmd --zone=public --add-port=80/tcp --permanent #Open port
firewall-cmd --reload #Restart firewall
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #Prohibit firewall from starting

 

 5. Set environment variables (global)

vi /etc/profile --> Edit the file and add the following
export JAVA_HOME=...
export classpath=.:$JAVA_HOME/dt/jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin/:$PATH
keep
source /etc/profile --> make environment variables take effect immediately

 6.vi common operations

    Display line numbers (all of the following will work)

ctrl+g
:not
: set no

     Skip line (any of the following will do)

:0 -> line 1
:12 -> line 12
:$ -> last line
1G -> line 1
12G -> line 12
G -> last line

 7.ssh remote connection

ssh [email protected]

 8.vi batch replacement

:%s/123/abc/g --> 123 is replaced by abc

 9. Check whether the service is installed (such as checking ssh)

rpm -qa | grep ssh

 10. Find

find / -name 'XX'| xargs rm -rf ---- delete after finding

 11. Fixed IP configuration

vi /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE = yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE = yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=2dfca251-cc0a-4063-a28a-ad921a058649
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.1.220
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
vi /etc/resolv.conf
nameserver 192.168.1.1
     Restart the network after modification
service network restart
 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326608534&siteId=291194637