缘起
如果将一个root属主的可执行文件,添加一个属主的粘滞位,那么,由该程序创建的其它进程的euid还是root吗?
测试
test.php
1 2 3 4 |
#!/usr/bin/env php <?php echo "euid: ".posix_geteuid(),"\n"; echo "uid: ". posix_getuid(), "\n"; |
看来是不好使的,即: 粘滞位是不能在程序间继承的
DevOps
如果将一个root属主的可执行文件,添加一个属主的粘滞位,那么,由该程序创建的其它进程的euid还是root吗?
test.php
1 2 3 4 |
#!/usr/bin/env php <?php echo "euid: ".posix_geteuid(),"\n"; echo "uid: ". posix_getuid(), "\n"; |
看来是不好使的,即: 粘滞位是不能在程序间继承的
有100个日志文件,每个文件大约1G,每条日志都以 “H:i:s” 的时间格式开头,如:
1 |
05:02:04 xxx yyy zzz |
因为是日志文件,所以肯定以时间为顺序的,现在可以确定的是,在某个文件中存在一条 01:02:03 这个时间点的关于xxx的日志,要找出来 ,如何做?
1 |
# for f in *; do awk '/^01:02:03/{}' $f |grep xxx; done |
虽然我们的正则是只匹配行首,算是很快的了,但是,我们还是扫描了整个的100个文件;考虑到每个文件肯定都是有时间顺序的,我们做了大量的无用的工作,其实完全可以提前退出的,加入每10分钟都会有日志出现,则可以优化如下:
1 |
# for f in *; do awk '/^01:02:03/{} /^01:1/{exit}' $f |grep xxx; done |
这样的话,没个文件只扫描很少的一部分就可以了
该题的sed解法:
1 |
# for f in *; do sed -n '/^01:02:03/p; /^01:1/q}' $f |grep xxx; done |
当然,将 xxx 并入正在表达式也是可以的(只是没有上面看起来更一目了然):
1 |
# for f in *; do sed -n '/^01:02:03.xxx/p; /^01:1/q}' $f ; done |
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
phpor@phpor-Latitude-E6440:~$ echo -e "a\nb\n"|sed -n '1p' # -n 默认不输出 a phpor@phpor-Latitude-E6440:~$ echo -e "a\nb\n"|sed '$d' a b phpor@phpor-Latitude-E6440:~$ echo -e "a\nb\n"|sed '1d' b phpor@phpor-Latitude-E6440:~$ echo -e "a\nb\n"|sed '2,$d' a phpor@phpor-Latitude-E6440:~$ echo -e "a\nb\n"|sed '/a/d' b phpor@phpor-Latitude-E6440:~$ echo -e "a\nb\n"|sed '/^$/d' a b phpor@phpor-Latitude-E6440:~$ echo -e "a\nb\n"|sed '2,$d' a phpor@phpor-Latitude-E6440:~$ echo -e "a\nb\n"|sed '/a/d' b phpor@phpor-Latitude-E6440:~$ echo -e "a\nb\n"|sed '/^$/d' a b phpor@phpor-Latitude-E6440:~$ echo -e "a\nb\n"|sed 's/ //' a b phpor@phpor-Latitude-E6440:~$ echo -e "a b\nb\n"|sed 's/ //' ab b phpor@phpor-Latitude-E6440:~$ echo -e "a b c\nb\n"|sed 's/ //' ab c b phpor@phpor-Latitude-E6440:~$ echo -e "a b c\nb\n"|sed 's/ //g' abc b phpor@phpor-Latitude-E6440:~$ echo -e "a b c\nb\n"|sed 's/^a/&mm/' amm b c b phpor@phpor-Latitude-E6440:~$ echo -e "a b c a c\nb\n"|sed 's/^a/&mm/' amm b c a c b phpor@phpor-Latitude-E6440:~$ echo -e "a b c a c\nb\n"|sed 's/a/&mm/g' amm b c amm c b phpor@phpor-Latitude-E6440:~$ echo -e "a\nb\n"|sed '/a/a\ >m' a m b phpor@phpor-Latitude-E6440:~$ echo -e "a\nb\n"|sed '/a/a\ #在匹配到的行后插入新行,添加多行时,每行(除最后一行)后面都要用 \ 续行 > m\ > n\ > p' a m n p b phpor@phpor-Latitude-E6440:~$ echo -e "a\nb\n"|sed '/a/i\ #在匹配到的行前插入新行 >m\ >n\ >p' m n p a b phpor@phpor-Latitude-E6440:~$ echo -e "a\nb\n"|sed '/a/c\ #用新行替换掉匹配到的行 >m\ >n\ >p' m n p b phpor@phpor-Latitude-E6440:~$ echo -e "a1b2c3\n" |sed -e 's/a//' -e 's/b//' -e's/c//' #使用 -e 选项对统一行进行多次处理 123 phpor@phpor-Latitude-E6440:~$ echo -e "123\n456\n789\nabc" | sed -n '/456/{n;p}' #打印匹配到的那行的下一行 789 phpor@phpor-Latitude-E6440:~$ echo -e "123\n456\n789\nabc" | sed -n '/456/{n;n;p}' #打印匹配到的那行的下一行的下一行 abc phpor@phpor-Latitude-E6440:~$ echo -e "badc\n"|sed 'y/abcd/ABCD/' #该命令与UNIX/Linux中的tr命令类似,字符按照一对一的方式从左到右进行转换 BADC sed -i '/sudo route add/r /tmp/updatephplib.txt' /tmp/Vagrantfile #匹配到某一行后,把制定文件的内容append进去;注意: 1. r命令不能用在花括号中 2. 文件名后面不能有空格 |
在匹配到的行尾添加:
删除匹配后的N行(delete n lines following a pattern)or (delete n lines after match/matches)
1 2 |
echo -e "1\n2\n3\n3\n4\n"|sed '/2/,+2d' 1 |
如果匹配到的行不需要删除
正则替换:
将 “craete time: 1988-02-02 11:22:12″ 替换为”craete time: 1988-02-02T11:22:12”
1 |
sed -r 's/(-[0-9]{2})\ ([0-9]{2})/\1T\2/' |
参考资料: http://blog.csdn.net/holandstone/article/details/8488434
http://stackoverflow.com/questions/4396974/sed-or-awk-delete-n-lines-following-a-pattern
http://stackoverflow.com/questions/8323287/how-can-i-use-sed-to-delete-2-lines-after-match-matches
svn cp $from $to
其中: $from $to 都可以是url或本地路径, 如果 $to 是本地路径,则还需一次 commit, 如果 $to 是url 则是直接提交
http://svnbook.red-bean.com/en/1.7/
Your Subversion repository is like a time machine. It keeps a record of every change ever committed and allows you to explore this history by examining previous versions of files and directories as well as the metadata that accompanies them. With a single Subversion command, you can check out the repository (or restore an existing working copy) exactly as it was at any date or revision number in the past. However, sometimes you just want to peer into the past instead of going into it.
Several commands can provide you with historical data from the repository:
SVN是以版本号(revision number)来记录版本库的每一次改变,一般的SVN操作不需要用到版本号,但是有些SVN操作需要指定版本号。我们可以指定一个明确的整数版本号,但是也可以使用SVN关键字来指代某个特殊的版本号,SVN会真正计算出它所指代的实际整数版本号:
HEAD:版本库中最新的版本;
BASE:某个工作副本项的版本,注意这个是你上次update该项时的版本号,可能晚于当前最新的版本号;
COMMITTED:某个工作副本项最近修改的版本,与BASE相同或更早;
PREV:COMMITTED – 1。
HEAD针对于版本库,另外3个针对于某个工作副本目录或文件。
示例:
$ svn diff -r PREV:COMMITTED foo.c
# shows the last change committed to foo.c
$ svn log -r HEAD
# shows log message for the latest repository commit
$ svn diff -r HEAD
# compares your working copy (with all of its local changes) to the latest version of that tree in the repository
$ svn diff -r BASE:HEAD foo.c
# compares the unmodified version of foo.c with the latest version of foo.c in the repository
$ svn log -r BASE:HEAD
# shows all commit logs for the current versioned directory since you last updated
$ svn update -r PREV foo.c
# rewinds the last change on foo.c, decreasing foo.c’s working revision
$ svn diff -r BASE:14 foo.c
# compares the unmodified version of foo.c with the way foo.c looked in revision 14
原文链接: http://www.cnblogs.com/frydsh/archive/2012/08/25/2655569.html