Category: Linux

a categories to hold all the basic and avanced linux command for the computer learning users

Recent Posts

CentOS 7中如果使用yum命令提示如下信息,即為數據庫損壞:
error: db5 error(28) from dbenv->open: No space left on device
error: cannot open Packages index using db5 – No space left on device (28)
error: cannot open Packages database in /var/lib/rpm
CRITICAL:yum.main:
Error: rpmdb open failed

解決方法:
cd /var/lib/rpm/
mv __db* /tmp/
rm __db.* -rf
rpm –rebuilddb
yum clean all

基本安裝:
wget http://www.rarlab.com/rar/rarlinux-x64-5.3.0.tar.gz
tar -zxvf rarlinux-x64-5.3.0.tar.gz
cd rar && make

———-List in the Console————–
mkdir -p /usr/local/bin
mkdir -p /usr/local/lib
cp rar unrar /usr/local/bin
cp rarfiles.lst /etc
cp default.sfx /usr/local/lib
—————-End———————–
現在已經成功安裝RAR/UNRAR

基本使用:
rar a test.rar test
把test文件壓縮為test.rar
rar a -p test.rar
把test.rar設置密碼
rar a -v49m test.rar file
把file文件分卷打包成每卷49mbs的rar文件,名字為test01.rar、test02.rar…(不足49mbs的話只分一卷)

unrar l test.rar
把test.rar裡面的東西列出來
unrar x test.rar
把test.rar解壓縮(保留文件結構)
unrar x test.rar ./dir
把test.rar解壓縮到本地文件夾下的dir文件夾

. – Any Character Except New Line
\d – Digit (0-9)
\D – Not a Digit(0-9)
\w – Word Character (a-z, A-Z, 0-9, _)
\W – Not a Word Character
\s – Whitespace (space, tab, newline)
\S – Not Whitespace (space, tab, newline)

\b – Word Boundary
\B – Not a Word Boundary
^ – Beginning of a String
$ – End of a String

[] – Mathes Characters in brackets
[^ ] – Matches Characters NOT in bracket
| – Either Or
( ) – Group

Quantifiers:
* – 0 or More
+ – 1 or More
? – 0 or One
{3} – Exact Number
{3,4} – Range of Numbers (Minimum, Maximum)

import re

text_to_search = ”’
abcdefghijklmnopqurtuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1234567890
Ha HaHa
Meta Characters(need to be escaped):
. ^ $ * + ? { } [ ] \ | ( )
http://v2rayz.me


321-555-4321
123.555.12342343
123*555*1234234234
800-555-123454554654
900-555-1234332423


Mr Smith
Ms Davis
Mrs. Robinson
Mr. Ferrari JR.
Mr. T

[email protected]
[email protected]
[email protected]
[email protected]

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
安裝Docker

docker pull [image name]
下載鏡像(image name:latest)

docker pull ubuntu

docker run –name Myubuntu1 -it ubuntu bash
在Container中運行ubuntu,進入bash,並使用interative mode

docker run -it –name [tag] -p 1234:80 -v $PWD/.:/home/test [name]
Interactively地去運行一個Container,端口指定

docker run -d -it –name [container name] -p 192.168.2.1:80:80 [image name]


docker help
一般性幫助
docker [command] –help
尋求幫助

docker images
查看所有鏡像

docker start [name]
運行Container

docker ps -a
列出所有Container

docker attach [name]
重新进入该Container

top -b
查看正在運行的進程

ctl+p & ctl+q
退出Container,進程繼續

exit
退出Container,進程結束

docker exec -it [name] [command]
在Container裡執行命令Without結束其他進程

docker stop [name]
結束Container

docker rm [name]
刪除Container

docker rmi [name]
刪除鏡像

docker inspect [name] | grep [content]
在鏡像信息裡查找需要的Content

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

docker build [path]
docker build .
建立鏡像

docker tag 40d13af0eebd [image name]
命名鏡像


sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
卸載Docker

docker -v
查看版本


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Dockerfile的用法


From [image name]

MAINTAINER [email protected]

RUN yum -y install httpd

COPY index.html /var/www/html

EXPOSE 80 443 8080/tcp 5000/udp

CMD [“bash”, “/script.sh”]

以上命令都幹了什麼事情:
從dockerhub載入image
註明作者
運行命令
從本地copy一個文件到Contianer的路徑
打開80 443 8080的tcp端口和5000端口
執行bash /script.sh

yum install -y wget

安装wget

yum update

升级系统版本

cat /etc/redhat-release

查看系统版本

wget -N --no-check-certificate "https://raw.githubusercontent.com/chiakge/Linux-NetSpeed/master/tcp.sh" && chmod +x tcp.sh && ./tcp.sh

下载并执行安装bbr魔改版内核脚本

./tcp.sh

在tcp.sh目录下运行,并输入对应数字,使用暴力BBR魔改版加速(不支持部分系统)


pidof firefox
查找程序PID方法1
ps aux | grep -i firefox
查找程序PID方法2
pgrep firefox
查找程序PID方法3

pgrep firefox

查找程序PID

$ date
查看时间

$ timedatectl set-timezone Asia/Shanghai
调节时间为上海时区

$ uname -r
查看内核版本

shopt -s extglob
$ rm -v !(“filename”)
enable the extglob shell option , remove everything except a filename

cat /etc/os-release
查看Linux版本

yum install epel-release
CentOS7’s depending pip repositories
yum -y install python-pip
install python pip

$ jq . config.json
检查语法错误

1、查找文件

find / -name ‘filename’ or find -name ‘filename’

2、查找目录

find / -name ‘path’ -type d

3、查找内容

find . | xargs grep -ri ‘content’
//find . | xargs grep -ril ‘content’ 只显示文件名称

pwd: print current dir
ls -l: show details
ls -a: show hidden
ls -la: both hidden and details
clear: clear terminal
cd: just type cd to home directory
cd: change dir
cd..: go up once
cd ../..: go up twice
cd /: to the ver top

———————————————-
/soft/shadowsocks/userapiconfig.py

mkdir dirname: make dir
rmdir dirname: remove an empty dir

rm -rf dirname: remove an non-empty dir

touch filename: create file
rm filename: remove file
cp oldfilename newfilename: copy a file
mv oldfilename newfilename: rename a file
mv file dir: move a file to dir
cat file: read the file
grep content file: global regular expression print(search content in file)

name=ryan: store a variable called name as ryan
echo hello: print hello
echo $name: echo out the variable

cd bin dir
bash pycharm.sh: to run pycharm on linux

info commandName: print out the help document of a command
ctrl+ c: back to home

ls > filename: to copy all the ls result to a file(overwritten)
ls >> filename: to append all the result to a file (not over written)

-rw: means file
drw: means dir
rwx: means read, write, execute
-rwxrw-r-x: means a file, owner can rwx it, group can read write it, the rest of users can read and execute it
u – user
g – group
o – others

ryan ryan: first is the owner of the file, second is the group it belong to
sudo useradd Bucky: to add a new user named Bucky
sudo passwd Bucky: change passwd for Bucky
sudo groupadd hacker: add a group called hacker
sudo usermod -a -G hacker Bucky: append Bucky to hacker group(not removing the group it belongs before)
sudo usermod -a -g hacker Bucky: append Bucky to hacker group(removing the group it belongs before)
sudo userdel Bucky: delete Bucky user
———————————————————————————–

chmod o+w filename: to change the permission while others can write
chmod 754 filename: to change a file to -rwx r-x –r
7, 5, 4 represents user, group, others
4 – read
2 – write
1 – execute
0 – no permissions
chmod 777 filename: all permissions to all people

————————————–
sha1sum file: to get the hash number of the file

————————————————
compress and decompress:

gzip Grocery\ List: when there is a space in filename, need to backslash
gzip filename: to zip a file to filename.gz
gunzip story: to unzip a file

tar cvf target.tar fileA fileB:
make a target.tar to include fileA and fileB
cvf – create, visualize, file
xvf – extract, visualize, file

——————————————–
apt: avanced package tool
sudo: super user do

sudo apt-get update
sudo apt-get install python3

java -version: print the version of java

——————————————-
SSH: Secure Shell
Set up ssh private and public keys:
in the local machines:
ssh-keygen -t rsa: create a private key, saved in /home/user/.ssh/id_rsa.pub
ssh-copy-id [email protected]’s IP: to add copy of private key to the server
ssh [email protected]’s IP: to connect to the server, and automatically add
in the server:
nano /etc/ssh/sshd_config
find #Authentication:
PermitRootLogin without-password
reload ssh: to restart the ssh service, when configuration is made

———————————————
Transfer files using SFTP
sftp [email protected]’s IP
cd TargetDir
put Desktop/file: put the local file into the server via sftp
put -r Desktop/dir: to put a dir recursively (file in it included) to the working directory
get file Desktop/File: get the file from the server to the local machine and rename it as ‘File’
get -r dir Desktop/Dir: get the dir recursively from the server to the desktop and rename it as ‘Dir’
exit: to quit from ssh or sftp

——————————————————-
Partitioning:
sudo apt-get install gparted: to install an visualized app for partitioning
sudo gparted

——————————————————-
Command Shell:
#!/bin/sh:
adding to the header of a script, and make Linux run the following command
chmod +rx file: to change the permission of a file to readable and executable
bash script: to run the script

———————————————————-
Processes:
ps: to list the processes that we owned and controlled manually
ps -ax: list all the processes in the background including the system processes
PID TTY Time CMD
ProcessID Terminal 00:00:00(time of cpu comsummed) Name of command

without finishing the process, no control of the terminal, eg. xlogo
ctrl + c: interrupt the process in the foreground
cmd &: to run the cmd in the background
[1] 2710: JobNumber, PID
jobs: to list the current jobs(a special type of process)
fg %1: to turn the background job to the foreground
bg %1: to turn the background job to the foreground
ctrl + z: to pause the current foreground job
kill PID: to kill the process
kill JobNumber: to kill the job
kill -STOP cmd: to freeze the process
kill -CONT cmd: to unfreeze the process

————————————————————
Crontab: