This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
使用 rsync 进行拷贝: | |
rsync 本来是文件同步备份的工具,相对于普通的 cp 命令,rsync 在控制方面就强多了,而且 rsync 对遍历目录也支持,有 --exclude 参数可以忽略指定的文件或文件夹。 | |
rsync -vaP --exclude=".*" --exclude="Makefile" dir1 /home/dir2 | |
如上面演示的就可以排除掉隐藏文件和 Makefile 文件,-a 参数已经包含遍历处理参数 -r。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>>crazystring = ‘dade142.;!0142f[.,]ad’ | |
>>> filter(str.isdigit, crazystring) ‘1420142’ #只保留数字 | |
>>> filter(str.isalpha, crazystring) ‘dadefad’ #只保留字母 | |
>>> filter(str.isalnum, crazystring) ‘dade1420142fad’ #只保留字母和数字 | |
#如果想保留数字0-9和小数点’.’ 则需要自定义函数 | |
>>> filter(lambda ch: ch in ‘0123456789.’, crazystring) ‘142.0142.’ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [20]: is_fat = True | |
In [21]: state = "fat" if is_fat else "not fat" | |
In [22]: state | |
Out[22]: 'fat' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [1]: import glob | |
In [2]: %pwd | |
Out[2]: u'/Users/ayuliao/Desktop/workplace/9377code/agent_flask' | |
In [3]: f1 = glob.glob(r'/Users/ayuliao/Desktop/workplace/9377code/agent_flask') #没有使用正则,则什么都不返回 | |
...: | |
In [4]: print(f1) | |
['/Users/ayuliao/Desktop/workplace/9377code/agent_flask'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import traceback | |
def fun(): | |
# 代码栈,其中包含调用该方法的方法名称 | |
s = traceback.extract_stack() | |
print '%s Invoked me!'%s[-2][2] | |
>>> def a():fun() | |
>>> def b():fun() | |
>>> a() | |
a Invoked me! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import fcntl | |
class Lock(object): | |
def __init__(self, filename): | |
self.filename = filename | |
self.handle = open(filename,'w') | |
def acquire(self): | |
# if you need a non-blocking lock, use fcntl.LOCK_NB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
delname=$1 | |
if [ ! -n "$1" ]; then | |
echo "Usages: mydel need one params which you want delelte" | |
exit 0 | |
fi | |
# 将要删除的文件移动到创建好的垃圾桶目录 | |
mv $delname /xxx/trash/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
realpath = os.path.realpath(__file__) # 当前py文件路径 | |
current_path = os.path.dirname(realpath) # 当前py所在的文件夹 | |
globalconf = current_path+'/config/global.json' | |
with open(globalconf, 'r') as f: | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bash -v stop_ssdb.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//原生JS定义方法 | |
var x = function (a, b) {return a * b}; | |
var z = x(4, 3); | |
//定义多个方法,将方法统一放到一个对象里,以传递一个字符串为例: | |
//方法定义 ,需要导入jquery | |
$.func = { |