linux の備忘録

## 概要
linuxコマンドを忘れないように、もしくなるべく的確に思い出せるようにここに備忘録としてまとめていきます。随時更新していきます。

## 備忘録たち

### check cpu

```
sudo lshw -class processor
```

### check gpu

```
lspci | grep -i nvidia
```

### check memory


### mozc入力メソッドの切り替えを ctrl space に設定する

https://qiita.com/nabenabe0928/items/09affae67df9c150ad50
ここに従う。これをすることでかなりストレスがなくなる。

### count file

```bash
ls -1 | wc -l
```


### keyboard setting for ubuntu18.04

```bash
sudo dpkg-reconfigure keyboard-configuration
```

```bash
setxkbmap jp
```

この上の2つをとりあえず試してみる。

#### pyenv & virtualenv 環境　for ubuntu on docker

```bash
apt update &&apt install -y wget git&& apt install build-essential -y&& git clone https://github.com/pyenv/pyenv.git ~/.pyenv &&\
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile &&\
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile &&\
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.profile &&\
source ~/.profile &&\
apt install -y gcc make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev &&\
pyenv install 3.6.3 &&\
git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv &&\
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.profile &&\
source ~/.profile &&\
pyenv virtualenv 3.6.3 myenv && pyenv global 3.6.3
```

#### pyenv & virtualenv 環境　for ubuntu NOT on docker

```bash

sudo apt update &&sudo apt install -y wget git&&sudo  apt install build-essential -y&& git clone https://github.com/pyenv/pyenv.git ~/.pyenv &&\
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile &&\
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile &&\
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.profile &&\
source ~/.profile &&\
sudo apt install -y gcc make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev &&\
pyenv install 3.6.3 &&\
git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv &&\
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.profile &&\
source ~/.profile &&\
pyenv virtualenv 3.6.3 myenv && pyenv global 3.6.3
```



#### user 追加してsu権限付与

```bash

adduser username
usermod -G sudo username
```

#### ubuntu18.04 にpyodbcを入れる

```bash

apt-get install -y unixodbc unixodbc-dev &&\
pip3 install pyodbc==4.0.30
```

#### gmpy2を入れる (on docker)
```bash

cd ~/static &&apt update &&apt install -y wget && apt install build-essential -y&&\
wget https://ftp.gnu.org/gnu/m4/m4-1.4.18.tar.gz && tar xf ./m4-1.4.18.tar.gz && cd m4-1.4.18 && ./configure --prefix=/usr && make && make install &&\
cd .. && wget https://gmplib.org/download/gmp/gmp-6.0.0a.tar.bz2 && tar xf ./gmp-6.0.0a.tar.bz2 && cd gmp-6.0.0 && ./configure --prefix=$HOME/static --enable-static --disable-shared --with-pic && make &&make check&& make install &&\
cd .. && wget http://www.mpfr.org/mpfr-3.1.2/mpfr-3.1.2.tar.bz2 && tar xf ./mpfr-3.1.2.tar.bz2 && cd mpfr-3.1.2 && ./configure --prefix=$HOME/static --enable-static --disable-shared --with-pic --with-gmp=$HOME/static && make && make install &&\
cd .. && wget https://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz && tar xf ./mpc-1.0.3.tar.gz && cd mpc-1.0.3 && ./configure --prefix=$HOME/static --enable-static --disable-shared --with-pic --with-gmp=$HOME/static --with-mpfr=$HOME/static && make && make install &&\
cd .. && wget https://github.com/aleaxit/gmpy/releases/download/gmpy2-2.1.0a1/gmpy2-2.1.0a1.tar.gz && tar xf ./gmpy2-2.1.0a1.tar.gz && cd gmpy2-2.1.0a1 && source ~/.profile && python setup.py build_ext --static=~/static install

```
#### openssl 1.0.2 系を入れる (on docker)

```bash

 cd ~ && mkdir static && cd ~/static &&\
apt-get install -y build-essential wget m4 libgmp-dev file git vim libomp-dev&& cd ~/static && wget https://www.shoup.net/ntl/ntl-11.3.2.tar.gz && tar xf ntl-11.3.2.tar.gz && cd ntl-11.3.2/src && ./configure SHARED=on NTL_GMP_LIP=on NTL_THREADS=on NTL_THREAD_BOOST=on && make -j4 && make install&&\
cd ~/static && wget http://www.openssl.org/source/openssl-1.0.2a.tar.gz && tar -xvzf openssl-1.0.2a.tar.gz && cd openssl-1.0.2a && export CFLAGS=-fPIC && ./config shared --prefix=/usr && make && make install

```


#### docker & docker compose をubuntu18.04 にいれる
```
apt install -y \
     apt-transport-https \
     ca-certificates \
     curl \
     software-properties-common
```


```
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
```

```
add-apt-repository \
     "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
     $(lsb_release -cs) \
     stable"
```


```
apt update
```

```
apt-get install docker-ce docker-ce-cli containerd.io
```

```
service docker start
```


#### gmpy2 on ubuntu (not docker)
```bash

cd ~/static &&sudo apt update &&sudo apt install -y wget && sudo apt install build-essential -y&&wget https://ftp.gnu.org/gnu/m4/m4-1.4.18.tar.gz && tar xf ./m4-1.4.18.tar.gz && cd m4-1.4.18 && ./configure --prefix=/usr && make &&sudo make install &&cd .. && wget https://gmplib.org/download/gmp/gmp-6.0.0a.tar.bz2 && tar xf ./gmp-6.0.0a.tar.bz2 && cd gmp-6.0.0 && ./configure --prefix=$HOME/static --enable-static --disable-shared --with-pic && make &&make check&&sudo make install &&cd .. && wget http://www.mpfr.org/mpfr-3.1.2/mpfr-3.1.2.tar.bz2 && tar xf ./mpfr-3.1.2.tar.bz2 && cd mpfr-3.1.2 && ./configure --prefix=$HOME/static --enable-static --disable-shared --with-pic --with-gmp=$HOME/static && make &&sudo  make install &&cd .. && wget https://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz && tar xf ./mpc-1.0.3.tar.gz && cd mpc-1.0.3 && ./configure --prefix=$HOME/static --enable-static --disable-shared --with-pic --with-gmp=$HOME/static --with-mpfr=$HOME/static && make && sudo make install &&cd .. && wget https://github.com/aleaxit/gmpy/releases/download/gmpy2-2.1.0a1/gmpy2-2.1.0a1.tar.gz && tar xf ./gmpy2-2.1.0a1.tar.gz && cd gmpy2-2.1.0a1

sudo python3 setup.py build_ext --static=~/static install
```

#### openssl 1.0.2 on ubuntu (not docker)

```bash

cd ~/static &&sudo apt-get install -y build-essential wget m4 libgmp-dev file git vim libomp-dev&& cd ~/static && wget https://www.shoup.net/ntl/ntl-11.3.2.tar.gz && tar xf ntl-11.3.2.tar.gz && cd ntl-11.3.2/src && ./configure SHARED=on NTL_GMP_LIP=on NTL_THREADS=on NTL_THREAD_BOOST=on && make -j4 && sudo make install&&cd ~/static && wget http://www.openssl.org/source/openssl-1.0.2a.tar.gz && tar -xvzf openssl-1.0.2a.tar.gz && cd openssl-1.0.2a && export CFLAGS=-fPIC && ./config shared --prefix=/usr && make && sudo make install
```

#### 環境構築まとめ　on ubuntu (with gmpy2, openssl 1.0.2)

```bash


#Pyenv
sudo apt update &&sudo apt install -y wget git&&sudo  apt install build-essential -y&& git clone https://github.com/pyenv/pyenv.git ~/.pyenv &&\
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile &&\
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile &&\
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.profile &&\
source ~/.profile &&\
sudo apt install -y gcc make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev &&\
pyenv install 3.6.3 &&\
git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv &&\
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.profile &&\
source ~/.profile &&\
pyenv virtualenv 3.6.3 myenv && pyenv global 3.6.3 &&\


#Openssl
cd ~ && mkdir static&&cd ~/static &&sudo apt-get install -y build-essential wget m4 libgmp-dev file git vim libomp-dev&& cd ~/static && wget https://www.shoup.net/ntl/ntl-11.3.2.tar.gz && tar xf ntl-11.3.2.tar.gz && cd ntl-11.3.2/src && ./configure SHARED=on NTL_GMP_LIP=on NTL_THREADS=on NTL_THREAD_BOOST=on && make -j4 && sudo make install&&cd ~/static && wget http://www.openssl.org/source/openssl-1.0.2a.tar.gz && tar -xvzf openssl-1.0.2a.tar.gz && cd openssl-1.0.2a && export CFLAGS=-fPIC && ./config shared --prefix=/usr && make && sudo make install &&\

#GMPY2
cd ~/static &&sudo apt update &&sudo apt install -y wget && sudo apt install build-essential -y&&wget https://ftp.gnu.org/gnu/m4/m4-1.4.18.tar.gz && tar xf ./m4-1.4.18.tar.gz && cd m4-1.4.18 && ./configure --prefix=/usr && make &&sudo make install &&cd .. && wget https://gmplib.org/download/gmp/gmp-6.0.0a.tar.bz2 && tar xf ./gmp-6.0.0a.tar.bz2 && cd gmp-6.0.0 && ./configure --prefix=$HOME/static --enable-static --disable-shared --with-pic && make &&make check&&sudo make install &&cd .. && wget http://www.mpfr.org/mpfr-3.1.2/mpfr-3.1.2.tar.bz2 && tar xf ./mpfr-3.1.2.tar.bz2 && cd mpfr-3.1.2 && ./configure --prefix=$HOME/static --enable-static --disable-shared --with-pic --with-gmp=$HOME/static && make &&sudo  make install &&cd .. && wget https://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz && tar xf ./mpc-1.0.3.tar.gz && cd mpc-1.0.3 && ./configure --prefix=$HOME/static --enable-static --disable-shared --with-pic --with-gmp=$HOME/static --with-mpfr=$HOME/static && make && sudo make install &&cd .. && wget https://github.com/aleaxit/gmpy/releases/download/gmpy2-2.1.0a1/gmpy2-2.1.0a1.tar.gz && tar xf ./gmpy2-2.1.0a1.tar.gz && cd gmpy2-2.1.0a1 && source ~/.profile && python setup.py build_ext --static=~/static install &&\

#ORCL
sudo mkdir -p /opt/oracle &&\
cd /opt/oracle &&\
sudo wget https://download.oracle.com/otn_software/linux/instantclient/19600/instantclient-basic-linux.x64-19.6.0.0.0dbru.zip&&\
sudo apt-get install unzip &&\
sudo unzip instantclient-basic-linux.x64-19.6.0.0.0dbru.zip &&\
sudo apt-get install libaio1 &&\
sudo sh -c "echo /opt/oracle/instantclient_19_6 > /etc/ld.so.conf.d/oracle-instantclient.conf" &&\
sudo ldconfig && export LD_LIBRARY_PATH=/opt/oracle/instantclient_19_6:$LD_LIBRARY_PATH &&\

# temp done
###必要なもの１をgit　clone
source ~/.profile && pip install cython setuptools==44.0.0&& python setup.py build_ext install
###必要なもの2をgit　clone 

```

#### 環境構築まとめ(分けた場合)　on ubuntu (with gmpy2, openssl 1.0.2)

```bash


#Pyenv
sudo apt update &&sudo apt install -y wget git&&sudo  apt install build-essential -y&& git clone https://github.com/pyenv/pyenv.git ~/.pyenv &&\
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile &&\
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile &&\
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.profile &&\
source ~/.profile &&\
sudo apt install -y gcc make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev &&\
pyenv install 3.6.3 &&\
git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv &&\
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.profile &&\
source ~/.profile &&\
pyenv virtualenv 3.6.3 myenv && pyenv global 3.6.3 &&\


###必要なもの2をgit　clone 
source ~/.profile && bash build_exe.sh &&

#Openssl
cd ~ && mkdir static&&cd ~/static &&sudo apt-get install -y build-essential wget m4 libgmp-dev file git vim libomp-dev&& cd ~/static && wget https://www.shoup.net/ntl/ntl-11.3.2.tar.gz && tar xf ntl-11.3.2.tar.gz && cd ntl-11.3.2/src && ./configure SHARED=on NTL_GMP_LIP=on NTL_THREADS=on NTL_THREAD_BOOST=on && make -j4 && sudo make install&&cd ~/static && wget http://www.openssl.org/source/openssl-1.0.2a.tar.gz && tar -xvzf openssl-1.0.2a.tar.gz && cd openssl-1.0.2a && export CFLAGS=-fPIC && ./config shared --prefix=/usr && make && sudo make install &&\

#GMPY2
cd ~/static &&sudo apt update &&sudo apt install -y wget && sudo apt install build-essential -y&&wget https://ftp.gnu.org/gnu/m4/m4-1.4.18.tar.gz && tar xf ./m4-1.4.18.tar.gz && cd m4-1.4.18 && ./configure --prefix=/usr && make &&sudo make install &&cd .. && wget https://gmplib.org/download/gmp/gmp-6.0.0a.tar.bz2 && tar xf ./gmp-6.0.0a.tar.bz2 && cd gmp-6.0.0 && ./configure --prefix=$HOME/static --enable-static --disable-shared --with-pic && make &&make check&&sudo make install &&cd .. && wget http://www.mpfr.org/mpfr-3.1.2/mpfr-3.1.2.tar.bz2 && tar xf ./mpfr-3.1.2.tar.bz2 && cd mpfr-3.1.2 && ./configure --prefix=$HOME/static --enable-static --disable-shared --with-pic --with-gmp=$HOME/static && make &&sudo  make install &&cd .. && wget https://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz && tar xf ./mpc-1.0.3.tar.gz && cd mpc-1.0.3 && ./configure --prefix=$HOME/static --enable-static --disable-shared --with-pic --with-gmp=$HOME/static --with-mpfr=$HOME/static && make && sudo make install &&cd .. && wget https://github.com/aleaxit/gmpy/releases/download/gmpy2-2.1.0a1/gmpy2-2.1.0a1.tar.gz && tar xf ./gmpy2-2.1.0a1.tar.gz && cd gmpy2-2.1.0a1 && source ~/.profile && python setup.py build_ext --static=~/static install &&\


#pyodbc
sudo apt-get install -y unixodbc unixodbc-dev &&\

#ORCL
sudo mkdir -p /opt/oracle &&\
cd /opt/oracle &&\
sudo wget https://download.oracle.com/otn_software/linux/instantclient/19600/instantclient-basic-linux.x64-19.6.0.0.0dbru.zip&&\
sudo apt-get install unzip &&\
sudo unzip instantclient-basic-linux.x64-19.6.0.0.0dbru.zip &&\
sudo apt-get install libaio1 &&\
sudo sh -c "echo /opt/oracle/instantclient_19_6 > /etc/ld.so.conf.d/oracle-instantclient.conf" &&\
sudo ldconfig && export LD_LIBRARY_PATH=/opt/oracle/instantclient_19_6:$LD_LIBRARY_PATH &&\

# temp done
###必要なもの１をgit　clone
cd ~/static/cython_ope-from-cryptdb && source ~/.profile && pip install cython setuptools==44.0.0&& python setup.py build_ext install && cp build/lib.linux-x86_64-3.6/cython_ope.cpython-36m-x86_64-linux-gnu.so /sdb/ && cp /home/ubuntu/static/gmpy2-2.1.0a1/build/lib.linux-x86_64-3.6/gmpy2.cpython-36m-x86_64-linux-gnu.so /sdb/


```


### ssh をやろうとして鍵のチェックで怒られてめんどくさい時

https://qiita.com/hnw/items/0eeee62ce403b8d6a23c　この記事を参考にする。