跳转至

2019

给你的linux创建一个回收站

给你的linux创建一个垃圾篓/回收站,防误删

创建一个垃圾回收站,保存被删除距今3天的文件,过期则被删除

1. 在你的主目录下,创建文件夹 .trash

Bash
1
2
cd ~
mkdir .trash

2. 在你的常用脚本目录下创建这俩脚本

Bash
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#!/bin/bash
TRASH_DIR="/home/lixy/.trash"

for i in $*; do
    STAMP=`date +%s`
    fileName=`basename $i`
    if [[ -d $TRASH_DIR/$fileName.$STAMP  ]];then
        mkdir $TRASH_DIR/$fileName.$STAMP
    fi
    mv $i $TRASH_DIR/$fileName.$STAMP
done
Bash
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
##################################################
# File Name   : /home/lixy/bin/removeRF.sh
# Author      : biolxy
# E-mail      : biolxy@aliyun.com
# Created Time: Wed 17 Apr 2019 02:48:47 PM CST
##################################################
#!/bin/bash
# 该文件夹下文件名字格式为    : JZ201810081226.1555481687
# 文件夹即为你设置的垃圾箱地  : /home/lixy/.trash
inputdir=`realpath $1`
STAMP=`date +%s`
cd ${inputdir}
for i in `ls -a $inputdir `
do
    fileRemoveTime=${i##*.} # 表示从左边开始删除最后(最右边)一个 . 号及左边的所有字符
    #if [ $fileRemoveTime ]  # 检测字符串是否为空,不为空返回 true。
    # ${#fileRemoveTime} 返回字符串长度,也是一个str
    if [ ${#fileRemoveTime} = 10 ] # = 检测两个字符串是否相等,相等返回 true; 检测字符串长度是否等于10,等于则返回 true。
    then
        # echo $STAMP $fileRemoveTime
        # echo ${#fileRemoveTime}
        difference=$[ $STAMP - $fileRemoveTime ]  # 支持的运算符与let相同,但也只支持整数运算
        # echo $difference
        # 24 * 60 * 60 * 3 = 259200 s   即 3 天
        if [ $difference -gt 259200 ];then
            echo "# `date` : rm file $i"
            /usr/bin/rm -rf $i
        fi
    fi
done

3. 用 remove.sh 替换 rm

Bash
1
2
3
4
vim ~/.bashrc   # 你用的是zsh的话就改为 ~/.zshrc
chmod +x /home/lixy/bin/remove.sh   # 给remove.sh 添加可执行权限
alias rm='/home/lixy/bin/remove.sh'    # 替换rm, 保存退出
source ~/.bashrc  # 刷新环境变量
替换过之后,rm 删除的文件,会被移动到 /home/lixy/.trash 文件夹,并且会在文件后添加 .1555481687的后缀,该后缀为删除时的时间(秒)

4. 添加定时任务

Bash
1
30 6 * * * /bin/bash /home/lixy/bin/removeRF.sh /home/lixy/.trash  > /home/lixy/.trash/remove.log
每天早上6.30 调用脚本,删除指定的.trash 文件夹下的文件,脚本中会根据文件移动到.trash 时添加的后缀,判断移动时间,移动时间大于3天的,即被 /usr/bin/rm 强制删除

我的第一个Dockerfile

软件

该docker包含几个我常用的软件:

  • 基于 CentOS Linux release 7.3.1611 (Core)

  • axel 下载数据用

  • git
  • zsh-syntax-highlighting.git # git 插件 谁用谁知道
  • vim
  • gcc g++ make # 额这个没有,装这个 镜像体积太大了
  • zsh
  • miniconda 64bit python=2.7

Dockerfile 内容

Text Only
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
FROM centos:7.3.1611
MAINTAINER biolxy <biolxy@goodrain.com>

# Set timezone
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

RUN yum update -y
RUN yum install curl vim wget \
    gettext gettext-devel autoconf automake libtool openssl \
    openssl-devel zsh -y
RUN yum install bzip2 -y

# yum clean
RUN rm -rf /var/lib/apt/lists/*

# mkdir app
RUN mkdir -p /app
# Set WORKDIR
WORKDIR /app

# install axel
RUN git clone https://github.com/axel-download-accelerator/axel.git
RUN cd axel && autoreconf -i && ./configure && make && make install

# install zsh
RUN chsh -s `which zsh` root
COPY install.sh /app/install.sh
RUN chmod +x /app/install.sh
COPY oh-my-zsh /app/oh-my-zsh
RUN /app/install.sh
# install zsh-syntax-highlighting
RUN git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
# add plugins
RUN echo "plugins=(plugins zsh-syntax-highlighting)" >> ~/.zshrc
RUN echo "source \$ZSH/oh-my-zsh.sh" >> ~/.zshrc
# install conda
COPY Miniconda2-latest-Linux-x86_64.sh /app/Miniconda2-latest-Linux-x86_64.sh
RUN /bin/bash /app/Miniconda2-latest-Linux-x86_64.sh -b -p /opt/conda && \
    rm /app/Miniconda2-latest-Linux-x86_64.sh && \
    echo "export PATH=/opt/conda/bin:$PATH" >> ~/.zshrc
RUN echo "export PATH=/opt/conda/bin:$PATH" >> ~/.bashrc
RUN source ~/.bashrc && conda clean --all -y

创建docker image

Text Only
1
docker build -t devtools:v3.0 .

参考

  • https://www.oschina.net/question/584116_2209819

编程类开放书籍荟萃[转]

说明

原文地址在 这里,因为有的内容我不需要,所以只把对我有用留下,放在github是为了方便我自己查找。

操作系统

C/C++

计算机科学的基础

Python

Shell

AWK

R

Perl

编程艺术

web服务器

版本控制

NoSQL

MySQL

项目相关

生物信息学

书单

精品视频推荐

分类 课程名称 作者 来源 备注
C语言 程序设计入门 翁恺 MOOC https://yam.gift/2018/06/20/C/2018-06-20-C-Weng-ZhejiangUniversity/
C++ 面向对象程序设计_C++ 翁恺 MOOC https://github.com/Libaier/ABC/tree/master/c%2B%2B
操作系统 操作系统原理 向勇、陈渝 实验楼、MOOC、学堂在线 - 配套上机实验地址: https://www.shiyanlou.com/courses/221 github上的课程项目: https://github.com/chyyuu/os_course_info
C++ C++面向对象高级开发 Part1&2 侯捷 GeekBand、Boolan https://github.com/FangYang970206/Cpp-Notes
Java 面向对象程序设计 翁恺 MOOC https://www.icourse163.org/course/ZJU-1001542001 https://github.com/pageYe123/JavaMOOC_icourse
数据结构(C++) 数据结构(上&下) 邓俊辉 MOOC https://github.com/HuyuYasumi/DSA_CPP_Deng https://www.xuetangx.com/courses/course-v1:TsinghuaX+30240184+sp/about

github 优质资源

  1. freeCodeCamp/freeCodeCamp 免费代码训练营
  2. EbookFoundation/free-programming-book 免费编程图书
  3. CyC2018/CS-Notes 国人编写的计算机基础教程,中文
  4. jwasham/coding-interview-university 面试考点总结
  5. vinta/awesome-python Python 的一些优质资源. 前面提到的 awesome 系列列表,不再赘述
  6. github/gitignore GitHub 提供的各种项目的 gitignore 文件模板,省了自己写了