分类目录工具

ubuntu zip文件

1.功能作用:解压缩zip文件

2.位置:/usr/bin/unzip

3.格式用法:unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]

4.主要参数

-c 将解压缩的结果显示到屏幕上,并对字符做适当的转换
-p 与-c参数类似,会将解压缩的结果显示到屏幕上,但不会执行任何的转换。
-l 显示压缩文件内所包含的文件
-f 更新现有的文件
-t 检查压缩文件是否正确,但不解压
-u 与-f参数类似,但是除了更新现有的文件外,也会将压缩文件中的其他文件解压缩到目录中
-z 仅显示压缩文件的备注文字
-v 执行是时显示详细的信息。或查看压缩文件目录,但不解压
-T 将压缩文件内的所有文件的最新变动时间设为解压缩时候的时间
-x 指定不要处理.zip压缩文件中的哪些文件
-d 指定文件解压缩后所要存储的目录
-n 解压缩时不要覆盖原有的文件
-q 安静模式,执行时不显示任何信息
-o 不必先询问用户,unzip执行后覆盖原有文件
-a 对文本文件进行必要的字符转换
-j 不处理压缩文件中原有的目录路径
-aa 把所有的文件目录当作文本处理
-U use escapes for all non-ASCII Unicode
-UU 忽略Unicode编码字符
-C 压缩文件中的文件名称区分大小写
-L 将压缩文件中的全部文件名改为小写
-X 解压缩时同时回存文件原来的UID/GID
-V 保留VMS的文件版本信息
-K 保留文件的setuid/setgid/tacky属性
-M 将输出结果送到more程序处理
-O 指定字符编码为DOS,Windows和OS/2
-I 指定字符编码为UNIX

5.应用实例
1、把文件解压到当前目录下

unzip test.zip

2、如果要把文件解压到指定的目录下,需要用到-d参数。

unzip -d /temp test.zip

3、解压的时候,有时候不想覆盖已经存在的文件,那么可以加上-n参数

unzip -n test.zip
unzip -n -d /temp test.zip

4、只看一下zip压缩包中包含哪些文件,不进行解压缩

unzip -l test.zip

5、查看显示的文件列表还包含压缩比率

unzip -v test.zip

6、检查zip文件是否损坏

unzip -t test.zip

7、将压缩文件test.zip在指定目录tmp下解压缩,如果已有相同的文件存在,要求unzip命令覆盖原先的文件

Git

官网地址

https://git-scm.com/downloads

安装

apt install git
git --version

git config --global user.name "sweet"
git config --global user.email "root@xxx.net"

使用

git config --list
git remote rm origin

开始一个工作区(参见:git help tutorial)
clone 克隆一个仓库到一个新目录
init 创建一个空的 Git 仓库或重新初始化一个已存在的仓库

在当前变更上工作(参见:git help everyday)
add 添加文件内容至索引
mv 移动或重命名一个文件、目录或符号链接
reset 重置当前 HEAD 到指定状态
rm 从工作区和索引中删除文件

检查历史和状态(参见:git help revisions)
bisect 通过二分查找定位引入 bug 的提交
grep 输出和模式匹配的行
log 显示提交日志
show 显示各种类型的对象
status 显示工作区状态

扩展、标记和调校您的历史记录
branch 列出、创建或删除分支
checkout 切换分支或恢复工作区文件
commit 记录变更到仓库
diff 显示提交之间、提交和工作区之间等的差异
merge 合并两个或更多开发历史
rebase 在另一个分支上重新应用提交
tag 创建、列出、删除或校验一个 GPG 签名的标签对象

协同(参见:git help workflows)
fetch 从另外一个仓库下载对象和引用
pull 获取并整合另外的仓库或一个本地分支
push 更新远程引用和相关的对象

命令 'git help -a' 和 'git help -g' 显示可用的子命令和一些概念帮助。
查看 'git help <命令>' 或 'git help <概念>' 以获取给定子命令或概念的帮助。

分支与合并

分支在本地完成,速度快。要创建一个新的分支,我们使用branch命令。
git branch test

branch命令不会将我们带入分支,只是创建一个新分支。所以我们使用checkout命令来更改分支。
git checkout test

第一个分支,或主分支,被称为"master"。
git checkout master

对其他分支的更改不会反映在主分支上。如果想将更改提交到主分支,则需切换回master分支,然后使用合并。
git checkout master
git merge test

如果您想删除分支,我们使用-d标识。
git branch -d test

刚创建的github版本库,在push代码时遇到以上错误:

Updates were rejected because the tip of your current branch is behind

有如下几种解决方法:
1,push前先将远程repository修改pull下来
$ git pull origin master
$ git push -u origin master

2,使用强制push的方法:
$ git push -u origin master -f
这样会使远程修改丢失,一般是不可取的,尤其是多人协作开发的时候。

3,若不想merge远程和本地修改,可以先创建新的分支:
$ git branch [name] 创建新的分支
$ git push -u origin [name] 提交对分支

4.新版git
git pull origin master --allow-unrelated-histories
git push -u origin master

intellij idea 出现Push rejected的解决方法

这个问题主要是初次上传到远程仓库,远程仓库需要先拉下来跟本地合并,然后才能上传。
git pull
git pull origin master
git pull origin master –allow-unrelated-histories
查看状态信息
git status
检查远程仓库配置
git remote -v
如果远程仓库信息有误,则删除本地仓库配置,并且设置相关地址

git remote rm origin
git remote add origin XXXX

当执行git中的“git pull origin master –allow-unrelated-histories”命令时,会出现“ couldn’t find remote ref –allow-unrelated-histories”的错误,输入如下命令即可解决:
git pull –rebase origin master
强制覆盖已有的分支(可能会丢失改动)
git push -u origin master -f

如何从从detached HEAD状态解救出来

  • 基于本次提交创建临时分支
    输入 $git branch temp fef4501 使用git branch 分支名 操作ID 这句命令能够创建一个新的分支,但要注意此时我们还没有切换到这个分支上,这个分支上面代码跟我刚才提交完之后的一样.
  • 切换到工作分支并合并代码
    输入 $git checkout ask_11_16 意味着我已经切换到ask_11_16分支,这个分支是我之前想要提交的分支. 然后 $git merge temp 这行命令过后我们已经上次commit合并到ask_11_16上了,此时终端状态为 Your branch is ahead of ‘origin/ask_11_16’ by 1 commit. 我们只需要$git push即可把本次提交push到远程分支. 这时候检查代码,perfect!正式我们想要的状态.
  • 删除temp分支
    大功告成,至于temp分支已经没有了利用价值,本着过河拆桥的精神我不得不输入 $git branch -d temp 来删除temp分支.

分支管理与合并(merge与rebase)

gitee.com

创建 git 仓库:
mkdir eureka-client
cd eureka-client
git init
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin https://gitee.com/xxx/eureka-client.git
git push -u origin master
已有仓库?
cd existing_git_repo
git remote add origin https://gitee.com/xxx/eureka-client.git
git pull origin master
git push -u origin master
git push -u origin master -f (强制上传会造成服务器的文件丟失,只适合初始化使用)

分支提交合并
在码云上先新建分支 test
git pull 本地获取同步服务器上的分支
git checkout test 切换支新的分支
git push  提交保存到新的分支
确认新功能开发完成后,切换回主分支,合并后再提交
git checkout master
git merge origin/test
git push

Gitlab Create a new repository

git clone http://xxx/root/test.git
cd test
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

Push an existing folder

cd existing_folder
git init
git remote add origin http://xxx/root/test.git
git add .
git commit -m "Initial commit"
git push -u origin master

Push an existing Git repository

cd existing_repo
git remote rename origin old-origin
git remote add origin http://xxx/root/test.git
git push -u origin --all
git push -u origin --tags

Docker

官网 https://www.docker.com/
安装 https://docs.docker.com/v17.09/engine/installation/linux/docker-ce/ubuntu/#docker-ee-customers
镜像市场 http://hub.docker.com
教程 https://www.runoob.com/docker/docker-tutorial.html
国内高速下载Docker 以及 docker-compose 地址
http://get.daocloud.io
https://blog.csdn.net/nklinsirui/article/details/80610058

Aliyun Ubuntu 14.04/16.04(使用 apt-get 进行安装)

# step 1: 安装必要的一些系统工具
sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
# step 2: 安装GPG证书
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# Step 3: 写入软件源信息
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# Step 4: 更新并安装Docker-CE
sudo apt-get -y update
sudo apt-get -y install docker-ce

# 安装指定版本的Docker-CE:
# Step 1: 查找Docker-CE的版本:
# apt-cache madison docker-ce
#   docker-ce | 17.03.1ce-0ubuntu-xenial | http://mirrors.aliyun.com/docker-ce/linux/ubuntu xenial/stable amd64 Packages#   docker-ce | 17.03.0ce-0ubuntu-xenial | http://mirrors.aliyun.com/docker-ce/linux/ubuntu xenial/stable amd64 Packages
# Step 2: 安装指定版本的Docker-CE: (VERSION例如上面的17.03.1ce-0ubuntu-xenial)
# sudo apt-get -y install docker-ce=[VERSION]

Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket.

#使用快速安装ubuntu 18
sudo apt install docker.io

增加配制:自己的仓库地址,镜像仓库地址X需更改,使用systemd与K8s同样配制

增加配制:3自己的仓库地址,镜像仓库地址X需更改,使用systemd与K8s同样配制 /etc/docker/daemon.json
{
 "insecure-registries":["harbor.com","192.168.88.128:5000"],
 "registry-mirrors":["https://cuzn52fX.mirror.aliyuncs.com","https://reg-mirror.qiniu.com","https://registry.docker-cn.com"],
 "exec-opts": ["native.cgroupdriver=systemd"],
 "storage-driver": "overlay2",
 "storage-opts": ["overlay2.override_kernel_check=true"],
 "log-driver": "json-file",
 "log-opts": {
    "max-size": "100m",
    "max-file": "3"
    },
 "max-concurrent-downloads": 5,
  "max-concurrent-uploads": 5
}

# 将Docker加入开启启动
$ sudo systemctl enable docker
# 启动Docker
$ sudo systemctl start docker
systemctl daemon-reload 重新加载
systemctl restart docker 重启docker

建立Docker用户组
默认情况下,docker命令会使用Unix Socket与Docker引擎通信,只有root用户和docker组的用户才可以访问Docker引擎的Unix Socket。出于安全考虑,一般不会直接使用root用户,所以需要先建立docker组,并将当前用户添加到docker组中。
$ sudo groupadd docker
$ sudo usermod -aG docker $USER

docker info

docker version

docker ps -a

docker images

docker exec -it container-id /bin/bash       exit

docker logs -f container-id

docker stop -f container-id

docker rmi Image-file

docker rm container-id

docker login

bocker build -t coustName:tag .

bocker build -t coustName:tag -f path

docker tag mysql:5.6 myreg/mysql:1.0

docker push myreg/mysql:1.0

Dockerfile

常用其它镜像地址:

七牛 quay-mirror.qiniu.com

卸载旧版本:

sudo systemctl stop docker
sudo apt-get purge docker-ce

sudo apt-get remove docker docker-ce docker-io

Buffalo LS-WVL/E上安装git

所需工具

PuTTY.exe

acp_commander

一。改机root
1. 在盘位1装上一块全新硬盘(没分区的盘)。

2. 启动NAS,然后按下机器后面function,这会把机器还原为出厂设置并格式化硬盘(慎:这会清除硬盘上的所有数据,如果你的硬盘上有数据,要先备份)。过了几分钟,设置完成后NAS自动重启。打开浏览器,输入NAS的地址(默认是192.168.1.100),如果能打开设置界面,就表示NAS准备就绪了。

不能进入先需安装系统- NASNAVI
点击NASNAVI软件的REFRESH,刷新会提示找到带有EM字样的NAS图标,此时NAS会显示NAS获取到的IP,暂时还不能访问到NAS的页面。如果提示更改IP,请直接取消,因为NAS已经从路由器上获得了IP。确认IP为以前路由器分配的以后,进入下一步。

安装系统-上传系统进入解压好的固件目录内,运行LSUpdater.exe,上传(UPDATE)固件,稍等即可。此过程可能持续20分钟。直到提示升级成功。

安装系统-改LSUpdater.ini【可选,改了以后记得重新打开LSUPDATER.EXE】

  1. [Application]
  2. Title = BUFFALO LinkStation Series Updater Ver.1.70
  3. WaitReboot = 1200
  4. WaitFormat = 600
  5. WaitFileSend = 600
  6. WaitDiscover = 120
  7. [Target]
  8. ProductID = 0x00000011
  9. ProductID2 = 0x00000012
  10. ProductID3 = 0x00000013
  11. ProductID4 = 0x00000014
  12. ProductID5 = 0x00003006
  13. ProductID6 = 0x00003007
  14. ProductID7 = 0x00000015
  15. ProductID8 = 0x00000016
  16. ProductID9 = 0x00003008
  17. ProductID10 = 0x00004001
  18. ProductID11 = 0x00000017
  19. ProductID12 = 0x00000019
  20. ProductID13 = 0x00000020
  21. ProductID14 = 0x00003010
  22. Name = LinkStation
  23. [Flags]
  24. VersionCheck = 0
  25. NoFormatting = 0

复制代码

VersionCheck = 1————1表示检查版本、0表示不检查版本,0用于降级
NoFormatting = 1———–1表示不格式化硬盘、0表示格式化硬盘

3. 准备一台windows机器,关闭windows防火墙。安装jre,地址http://java.com/zh_CN/download/manual.jsp

4. 下载acp_commander.jar。打开windows命令行,切换到acp_commander.jar所在的目录,输入以下命令以测试机器能否破解

java -jar acp_commander.jar -t 192.168.1.100 -ip 192.168.1.100 -pw password -c “ls /”
注意-pw后的参数”password”是web设置界面admin用户的登录密码,默认就是password,如果成功的话就能看到输出的根目录列表了!

5. 把root密码改为123456,你也可以改成别的。

java -jar acp_commander.jar -t 192.168.1.100 -ip 192.168.1.100 -pw password -c “(echo sweetopen;echo sweetopen)|passwd”
6. 修改sshd设置以允许root用户登录

java -jar acp_commander.jar -t 192.168.1.100 -ip 192.168.1.100 -pw password -c “sed -i ‘s/PermitRootLogin no/PermitRootLogin yes/g’ /etc/sshd_config”
7. 修改sshd设置,关闭PAM

java -jar acp_commander.jar -t 192.168.1.100 -ip 192.168.1.100 -pw password -c “sed -i ‘s/UsePAM yes/UsePAM no/g’ /etc/sshd_config”
8. 重启ssh服务

java -jar acp_commander.jar -t 192.168.1.100 -ip 192.168.1.100 -pw password -c “/etc/init.d/sshd.sh restart”
现在你可以用ssh登录LS-WVL了。

(注:以上几条命令可能会出错,注意看屏幕输出。如果对还有什么疑问,可以参考这篇文章http://i.592.net/?post=360,或者google一下,网上有很多关于改机的文章。)

二。安装git软件
1. 用PuTTY登录LS-WVL/E(默认地址192.168.1.100),用户root,密码是你在第一部分的步骤5设置的。

2.输入以下命令:

mkdir /mnt/disk1/temp
cd /mnt/disk1/temp
wget http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/stable/ls-mvkw-bootstrap_1.2-7_arm.xsh
sh ./ls-mvkw-bootstrap_1.2-7_arm.xsh

做了阵列的

mkdir /mnt/array1/tmp
cd /mnt/array1/tmp/
wget http://ipkg.nslu2-linux.org/feeds/optware/cs05q3armel/cross/stable/teraprov2-bootstrap_1.2-7_arm.xsh
sh ./teraprov2-bootstrap_1.2-7_arm.xsh

ipkg update
ipkg upgrade
ipkg install git
三。配置
这部分操作是创建并配置好一个用户,使其能通过ssh登录系统,专门用于进行git相关操作

1. 以root登录,创建git用户

groupadd git(创建组git)
useradd -g git -m git(创建用户git,属于组git,同时创建用户主目录/home/git)
passwd git(设置git用户密码)
然后根据提示输入两遍密码

2. 修改ssh服务器的配置文件/etc/sshd_config,输入

vi sshd_config
然后编辑如下参数设置

StrictModes no(如果.ssh目录及相关文件的权限和拥有人owner等都能严格正确设置,可以设为yes)

UsePrivilegeSeparation no(这是必须的,否则git用户无法登录)

PermitUserEnvironment yes(必须的,使ssh加载用户自定义的环境配置文件)

3. 配置git用户环境变量文件,设置PATH(如果不设置好用户的PATH,运行git命令将提示”command not found”)。

输入如下命令:

cd /home/git(进入用户git的主目录)
mkdir .ssh
echo PATH=/mnt/disk1/.optware/bin:/opt/bin:/opt/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin >> .ssh/environment

echo PATH=/mnt//array1/.optware/bin:/opt/bin:/opt/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin >> .ssh/environment
chown -R git.git .ssh(更改.ssh目录及其中文件的owner为用户git)
chmod 700 .ssh(更改.ssh目录的权限)
chmod 600 .ssh/environment
4. 创建git项目的存储目录。输入命令

mkdir -m 777 /mnt/disk1/gits(创建目录gits来存放所有的git项目,权限777)

mkdir -m 777 /mnt/array1/gits
5. 重启sshd(见第一部分步骤8),然后用PuTTY以git用户登录,应该就能登上了。

四。测试
1.通过ssh以用户git登录,创建一个git项目testproj。输入命令

mkdir /mnt/disk1/gits/testproj.git(创建项目的目录)
cd /mnt/disk1/gits/testproj.git
git init –bare(初始化git仓库)
2. 在windows客户机上安装tortoiseGit和mysisgit并设置好,你就可以从服务器上clone项目testproj了。(具体操作不在本文讨论范围,请自行google之)

如果客户机是linux或mac,并且安装好了git,你可以直接输入命令

git clone git@192.168.1.100:/mnt/disk1/gits/testproj.git
回车后输入用户git的密码,就把testproj项目给clone下来了

五。其它
一开始我按照网上的很多教程root后,发现只有root用户能够通过ssh登录,其它用户都不能登录。经过几天在网上苦苦的搜寻,终于找到了原因和解决办法:ssh服务器在底层使用了sftp这个工具,这个工具有一个配置文件/etc/sftponly_config,这个配置文件里禁止了用户(在Buffalo LS-WVL的Web配置页面能看到的所有用户和组)的ssh登录,而且这个配置文件每次ssh服务器启动时都会重新生成,所以你改这个配置文件也没有用。
解决办法有两个:
1. 既然在Web配置页面能看到的所有用户和组(默认有用户admin,guest,组包括admin,guest,hdusers)都不能ssh登录,那么Web配置页面里看不到的用户和组,不就不受这个限制了吗。所以解决方法就是通过ssh以root登录,新建一个组git,然后再创建一个用户git,使其属于这个新建的组(创建用户时如果不指定其所属的组,就默认属于hdusers组,这个是配置文件/etc/sftponly_config里面禁止ssh登录的),这样这个用户git就可以登录了。(具体操作见上文第三部分步骤1)
2. 第二个解决方法就是想办法修改这个配置文件/etc/sftponly_config。打开ssh服务器的启动脚本/etc/init.d/sshd.sh,你可以在启动ssh服务器的代码前找到这样一行“nas_configgen -c sftp”,就是这行代码重新生成了配置文件/etc/sftponly_config,只要在这一行后面再加一行代码,把sftponly_config改一改,把所有的”allowssh no”全部改成”allowssh yes”,问题不就解决了吗。
(事实上这是我最开始找到的办法,但是由于操作比较复杂,而且有一定的安全隐患,所以还是建议使用第一个解决方法)
用vi来编辑/etc/init.d/sshd.sh,输入以下命令

vi /etc/init.d/sshd.sh
移动光标,在sshd_start()方法中找到“nas_configgen -c sftp”这一行,将光标移至行末,按a键,然后在这行之后插入一行:

sed -i ‘s/allowssh no/allowssh yes/g’ /etc/sftponly_config
按ESC键,输入”:wq”(双引号中间的3个字母)然后回车,这就保存退出了。

Ubuntu18 VsCode搭建C++编译环境

安装C++插件


  • 安装一系列C++的插件,我安装的有:
    C/C++
    C/C++ Intellisense
    

重点


两种方法编译C++文件

第一种:安装C/C++ Compile Run插件(简单,推荐)

  • 人生苦短,何必浪费时间在环境搭建上~
  • 虽然只支持单文件(single file)的编译和运行,但是日常使用足够了啊
  • 打开C++文件F6即可运行
  • 官方使用手册:

    Requirements
    If you are on linux you must install gcc
    If you are on window you must install mingw
    How to use
    Make sure you have .c or .cpp file open and press “F6”, this will compile the file. If you want to register gcc/g++ path manually you can set it under settings. You can also set to save file before compiling.

第二种:手动添加task.json和launch.json

  • 打开C++文件,切换到Debug下,运行一次,他会创建一个默认文件,改成如下即可:
    {
      "version": "0.2.0",
      "configurations": [
          {
              "name": "(gdb) Launch",
              "type": "cppdbg",
              "request": "launch",
              "program": "${workspaceRoot}/${fileBasenameNoExtension}.o",
              "args": [],
              "stopAtEntry": false,
              "cwd": "${workspaceRoot}",
              "environment": [],
              "externalConsole": true,
              "preLaunchTask": "build",  
              "MIMode": "gdb",
              "setupCommands": [
                  {
                      "description": "Enable pretty-printing for gdb",
                      "text": "-enable-pretty-printing",
                      "ignoreFailures": true
                  }
              ]
          }
      ]
    }
    
  • 然后切回C++文件,Ctrl + Shift + B build >> 选择other新建一个 >> 修改tasks.json如下:
    {  
      "version": "0.1.0",  
      "showOutput": "always",  
      "tasks": [
          {
              "taskName": "build",
              "command": "g++",
              "isShellCommand": true,
              "showOutput": "always",
              "args": [
                  "-g",
                  "${file}",
                  "-o",
                  "${workspaceRoot}/${fileBasenameNoExtension}.o"
              ],
              "problemMatcher": [
                  "$g++"
              ]
          }
      ]  
    }
    

最后

  • Ctrl + Shift + B build
  • 点击debug下的绿色箭头即可运行