几个网站

几个网站,喜欢linux,shell的可以看一下 shell-fu http://www.commandlinefu.com/ http://snipt.net/public/tag/bash?page=2 good coders code, great reuse

January 6, 2010 · notsobad

备忘:linux下文件名中出现空格的处理

find 中的print0会使用nul字符来做分割结果。 xargs中又-0参数,可以获取结果。 find . -type f -print0 | xargs -0 -I {} mv {} {}.bak 一些复杂的处理可以用while+read来做 /usr/bin/find /usr/dirName -type f -mtime 0 \ | while read LINE; do cp -rf "$LINE" /home/BackupDirName done 我处理sony 505阅读器里的文件,为了防止丢书,需要给每个文件名前加个英文字符。 ...

January 4, 2010 · notsobad

django备忘

备忘: save() got an unexpected keyword argument ‘force_insert’ 解决: save时需要带上 *args, **kwargs def save(self, *args, **kwargs): #... super(SiteUser, self).save(*args, **kwargs) [参考](http://groups.google.com/group/django- users/browse_thread/thread/2471efd68d56ad59/a8c000a383db3f63?lnk=raot) 另: relation “django_admin_log” does not exist 这是因为启用了admin,但是没有syncdb 运行: ./manage.py syncdb

December 31, 2009 · notsobad

vi的自动折行

vi的自动折行太贱了,写代码还好,我一个字符串很长,它也给我截断,字符串一截就给加了换行和tab 我忘了在哪里里配置的了,没办法,临时取消折行: set textwidth=99999

December 30, 2009 · notsobad

linux的ls命令

ls谁都会用,但是你真的很熟吗? ls -r -d -1 proxy_* 2>/dev/null | sed -n '1s/^proxy_//p' 544 /media/sda6/collection/music>ls --help 用法:ls [选项]... [文件]... 列出<文件>的信息 (默认为目前的目录)。 如果不指定 -cftuvSUX 或 --sort 任何一个选项,则根据字母大小排序。 长选项必须用的参数在使用短选项时也是必需的。 -a, --all 不隐藏任何以 . 字符开始的项目 -A, --almost-all 列出除了 . 及 .. 以外的任何项目 --author 和 -l 同时使用时列出每个文件的作者 -b, --escape 以八进制溢出序列表示不可打印的字符 --block-size=大小 块以指定<大小>的字节为单位 -B, --ignore-backups 不列出任何以 ~ 字符结束的项目 -c 配合 -lt:根据 ctime 排序及显示 ctime (文件 状态最后更改的时间) 配合 -l:显示 ctime 但根据名称排序 否则:根据 ctime 排序 -C 每栏由上至下列出项目 --color[=WHEN] 控制是否使用色彩分辨文件。WHEN 可以是 "never"、"always"或"auto"其中之一 -d, --directory 当遇到目录时列出目录本身而非目录内的文件 -D, --dired 产生适合Emacs 的dired 模式使用的结果 -f 不进行排序,-aU 选项生效,-lst 选项失效 -F, --classify 加上文件类型的指示符号(*/=@| 其中一个) --format=关键字 交错-x,逗号分隔-m,水平-x,长-l, 单栏-1,详细-l,垂直-C --full-time 即-l --time-style=full-iso -g 类似 -l,但不列出属主 --group-directories-first 在文件前分组目录。此选项可与--sort 一起使用, 但是一旦使用--sort=none (-U)将禁用分组 -G, --no-group 以一个长列表的形式,不输出组名 -h, --human-readable 与-l 一起,以易于阅读的格式输出文件大小 (例如 1K 234M 2G) --si 同上面类似,但是使用1000 为基底而非1024 -H, --dereference-command-line 跟随命令行列出的符号链接 --dereference-command-line-symlink-to-dir 跟随命令行列出的目录的符号链接 --hide=PATTERN 隐藏符合PATTERN 模式的项目 (-a 或 -A 将覆盖此选项) --indicator-style=方式 指定在每个项目名称后加上指示符号方式: none (默认),classify (-F),file-type (-p) -i, --inode 显示每个文件的inode 号 -I, --ignore=PATTERN 不显示任何符合指定shell PATTERN 的项目 -k 即--block-size=1K -l 使用较长格式列出信息 -L, --dereference 当显示符号链接的文件信息时,显示符号链接所指示 的对象而并非符号链接本身的信息 -m 所有项目以逗号分隔,并填满整行行宽 -n, --numeric-uid-gid 类似 -l,但列出UID 及GID 号 -N, --literal 输出未经处理的项目名称 (如不特别处理控制字符) -o 类似 -l,但不列出有关组的信息 -p, --indicator-style=slash 对目录加上表示符号"/" -q, --hide-control-chars 以 ? 字符代替无法打印的字符 --show-control-chars 直接显示无法打印的字符 (这是默认方式,除非调用 的程序名称是“ls”而且是在终端机画面输出结果) -Q, --quote-name 将项目名称括上双引号 --quoting-style=方式 使用指定的 quoting <方式>显示项目的名称: literal、locale、shell、shell-always、c、escape -r, --reverse 排序时保留顺序 -R, --recursive 递归显示子目录 -s, --size 以块数形式显示每个文件分配的尺寸 -S 根据文件大小排序 --sort=WORD 以下是可选用的WORD 和它们代表的相应选项: extension -X status -c none -U time -t size -S atime -u time -t access -u version -v use -u --time=WORD 和-l 同时使用时显示WORD 所代表的时间而非修改时 间:atime、access、use、ctime 或status;加上 --sort=time 选项时会以指定时间作为排序关键字 --time-style=STYLE 和-l 同时使用时根据STYLE 代表的格式显示时间: full-iso、iso、locale、posix-iso、+FORMAT。 FORMAT 即是"date"所用的时间格式;如果FORMAT 是FORMAT1<换行>FORMAT2,FORMAT1 适用于较旧 的文件而FORMAT2 适用于较新的文件;如果STYLE 以"posix-"开头,则STYLE 仅在POSIX 语系之外 生效。 -t 根据修改时间排序 -T, --tabsize=宽度 指定制表符(Tab)的宽度,而非8 个字符 -t 按修改时间排序 -T, --tabsize=COLS 指定制表符(Tab)的宽度,而非8个字符 -u 同-lt 一起使用:按照访问时间排序并显示 同-l一起使用:显示访问时间并按文件名排序 其他:按照访问时间排序 -U 不进行排序;按照目录顺序列出项目 -v 在文本中进行数字(版本)的自然排序 -w, --width=COLS 自行指定萤幕宽度而不使用目前的数值 -x 逐行列出项目而不是逐栏列出 -X 根据扩展名排序 -1 每行只列出一个文件 --help 显示此帮助信息并退出 --version 输出版本信息并退出 [大小]可以是以下的单位(单位前可加上整数): kB 1000,K 1024,MB 1000000,M 1048576,还有 G、T、P、E、Z、Y。 默认情况下不使用色彩来区别文件,此方式等于使用了 --color=none 选项。若使用 --color 选项但不指定 WHEN 参数则等于--color=always。当使用 --color=auto 时, 只当输出至终端(tty)时才会显示色彩。 退出状态: 0 正常 1 一般问题 (例如:无法访问子文件夹) 2 严重问题 (例如:无法使用命令行参数)

December 28, 2009 · notsobad

登录shell和非登录shell

所谓的登录shell和非登录shell的区别: 发信人: edyfox (滇狐), 信区: LinuxApp 标 题: Re: 为什么我的gnome- terminal启动的时候.bash_profile没有被执 发信站: 水木社区 (Wed Apr 18 18:22:06 2007), 站内 1. 登录方式执行 bash 时只运行 .bash_profile 2. 非登录方式执行 bash 时只运行 .bashrc 3. 按照大家的习惯,建议把配置写在 .bashrc 中, 而在 .bash_profile 中 source ~/.bashrc。 4. gnome- terminal 默认使用非登录方式执行 bash。 5. 要改为登录方式执行 bash 可以: 编辑 -> 当前配置文件 -> 标题和颜色 选中“以登录 Shell 方式执行命令” 【 在 beninu (葛之覃兮) 的大作中提到: 】 : 说说吧 只要将本文转载或手动贴到本站其它版面,系统就会自动将你的文章数 +1。 我刚试验了,绝对是真的! ※ 来源:·水木社区 newsmth.net·[FROM: 166.111.68.*] ...

December 25, 2009 · notsobad

split and sort

网上看到的一道题,不知道愿意是不是让用shell来做。 老实说,我也不知道这样写速度是否真的会快一点。没有这样的数据来测试。 # 有一千万条短信,有重复,以文本文件的形式保存,一行一条,有重复。 # 请用5分钟时间,找出重复出现最多的前10条 set -x # 拆分为10000行一个的文件。 split msg_file -l 10000 for i in x*;do sort $i | tail -10 > ${i}_tmp & done sleep 5 # Wait for the sort cat x*_tmp | sort | tail -10 > out.txt rm x*_tmp rm x*

December 25, 2009 · notsobad

awk中使用shell变量

511 ~$who | awk '/^'"$USER"'/' wang tty7 2009-12-23 09:00 (:0) wang pts/0 2009-12-23 09:00 (:0) 511 ~$who| awk '/^'"$USER"'/' wang tty7 2009-12-23 09:00 (:0) wang pts/0 2009-12-23 09:00 (:0) 较新版本的awk可以这样: nawk 'END { print "Your path variable is " ENVIRON["PATH"] }' #如下: ~$awk --version GNU Awk 3.1.6 ~$export b=2; ~$awk 'END { print "Your path variable is " ENVIRON["b"] }' /dev/null Your path variable is 2 参考文章 3.12) Is it possible to pass shell variable settings into an awk program? There are two different ways to do this. The first involves simply expanding the variable where it is needed in the program. For example, to get a list of all ttys you’re using: who | awk ‘/^’"$USER"’/ { print $2 }’ (1) Single quotes are usually used to enclose awk programs because the character ‘$’ is often used in them, and ‘$’ will be interpreted by the shell if enclosed inside double quotes, but not if enclosed inside single quotes. In this case, we want the ‘$’ in “$USER” to be interpreted by the shell, so we close the single quotes and then put the “$USER” inside double quotes. Note that there are no spaces in any of that, so the shell will see it all as one argument. Note, further, that the double quotes probably aren’t necessary in this particular case (i.e. we could have done who | awk ‘/^’$USER’/ { print $2 }’ (2) ), but they should be included nevertheless because they are necessary when the shell variable in question contains special characters or spaces. The second way to pass variable settings into awk is to use an often undocumented feature of awk which allows variable settings to be specified as “fake file names” on the command line. For example: who | awk ‘$1 == user { print $2 }’ user="$USER" - (3) Variable settings take effect when they are encountered on the command line, so, for example, you could instruct awk on how to behave for different files using this technique. For example: awk ‘{ program that depends on s }’ s=1 file1 s=0 file2 (4) Note that some versions of awk will cause variable settings encountered before any real filenames to take effect before the BEGIN block is executed, but some won’t so neither way should be relied upon. Note, further, that when you specify a variable setting, awk won’t automatically read from stdin if no real files are specified, so you need to add a “-” argument to the end of your command, as I did at (3) above. A third option is to use a newer version of awk (nawk), which allows direct access to environment vairables. Eg. nawk ‘END { print “Your path variable is " ENVIRON[“PATH”] }’ /dev/null ...

December 23, 2009 · notsobad

linux创建备份文件

linux系统管理员应该有的一个习惯就是随时备份文件,通常cp -rf a a.xxx, 但是为备份文件起个名字得花时间想以下,最好是能够自动的创建文件名。 #备份文件用,放入 ~/.bashrc中 #支持文件和目录 #By notsobad # usage: bak test_file bak(){ to="`echo $1 | sed 's#/*$##g'`.`date +%Y%m%d%H%M`"; [ -e "$to" ] && rm -rf $to; cp -rf "$1" $to; } 使用: ...

December 23, 2009 · notsobad

php中的allow_url_include

allow_url_include 如果打开,则可以include远程文件 这是个很古老的安全问题了,今天做了下实验,才意识到危害性。 以前一位include 只是取到静态html内容,把它原样输出,没想到它会对获取倒内容中的php代码进行解释执行,很危险。 机器a上: wang@wang-desktop:~/www$ cat inc.php EOF ?> 然后在另一台机器b上: ...

December 17, 2009 · notsobad