for i in {1..999}; do curl -L -O http://baidu.com/images/pic_$(printf "%0.4d" $i).jpg; done
Showing posts with label shell. Show all posts
Showing posts with label shell. Show all posts
Friday, April 6, 2012
批量下载某个网站 0001.jpg 到 0999.jpg 图片的shell脚本
Wednesday, October 13, 2010
PHP加Shell实现多进程
看到这个标题,大家可能要说我没常识,php根本不支持多线程啊,没错,php本身是不支持多线程,但是别忘了php的好搭档,apache和linux可是支持的,呵呵,lamp才是最佳组合,还在使用win服务器的现在知道为什么要用linux吧?好久没在phpchina说教了,今天水一帖,写个简单的代码演示下如何借助shell脚本实现多线程。
先写个简单的php代码,这里为了让脚本执行时间更长,方便看效果,sleep一下,呵呵!先看下test.php的代码:
[cc lang='php' line_numbers='false']
for ($i=0;$i<10;$i++) {
echo $i;
sleep(10);
}
[/cc]
在看下shell脚本的代码,非常简单
[cc lang='bash' line_numbers='false']#!/bin/bash
for i in 1 2 3 4 5 6 7 8 9 10
do
/usr/bin/php -q /var/www/html/test.php &
done[/cc]
注意到在请求php代码的那行有一个&符号吗,这个是关键,不加的话是不能进行多线程的,&表示讲服务推送到后台执行,因此,在shell的每次的循环中不必等php的代码全部执行完在请求下一个文件,而是同时进行的,这样就实现了多线程,下面运行下shell看下效果,这里你将看到10个test.php进程再跑,再利用linux的定时器,定时请求这个shell,在处理一些需要多线程的任务,例如,批量下载时,非常好用!
先写个简单的php代码,这里为了让脚本执行时间更长,方便看效果,sleep一下,呵呵!先看下test.php的代码:
[cc lang='php' line_numbers='false']
for ($i=0;$i<10;$i++) {
echo $i;
sleep(10);
}
[/cc]
在看下shell脚本的代码,非常简单
[cc lang='bash' line_numbers='false']#!/bin/bash
for i in 1 2 3 4 5 6 7 8 9 10
do
/usr/bin/php -q /var/www/html/test.php &
done[/cc]
注意到在请求php代码的那行有一个&符号吗,这个是关键,不加的话是不能进行多线程的,&表示讲服务推送到后台执行,因此,在shell的每次的循环中不必等php的代码全部执行完在请求下一个文件,而是同时进行的,这样就实现了多线程,下面运行下shell看下效果,这里你将看到10个test.php进程再跑,再利用linux的定时器,定时请求这个shell,在处理一些需要多线程的任务,例如,批量下载时,非常好用!
Thursday, February 25, 2010
Bash Shell Keyboard shortcuts
The following shortcuts work when using default (Emacs) key bindings. Vi-bindings can be enabled by running [cci]set -o vi[/cci].
[cci]Tab ⇆[/cci] : Autocompletes from the cursor position.
[cci]Ctrl+a[/cci] : moves the cursor at the beginning of the line (equivalent to the key [cci]Home[/cci]).
[cci]Ctrl+e[/cci] : (end) moves the cursor at the line end (equivalent to the key [cci]End[/cci]).
[cci]Ctrl+p[/cci] : (previous) recalls the previous command (equivalent to the key [cci]↑[/cci]).
[cci]Ctrl+n[/cci] : (next) recalls the next command (equivalent to the key [cci]↓[/cci]).
[cci]Ctrl+r[/cci] : (research) recalls the last command including the specified character(s). A second [cci]Ctrl+r[/cci] recalls the next anterior command which corresponds to the research
[cci]Ctrl+s[/cci] : Go back to the next more recent command of the research (beware to not execute it from a terminal because this command also launches its XOFF). If you changed that XOFF setting, use [cci]Ctrl+q[/cci] to return.
[cci]Ctrl+o[/cci] : executes the found command from research.
[cci]Ctrl+l[/cci] : clears the screen content (equivalent to the command clear).
[cci]Ctrl+u[/cci] : clears the line content before the cursor and copy it in the clipboard.
[cci]Ctrl+k[/cci] : clears the line content after the cursor and copy it in the clipboard.
[cci]Ctrl+w[/cci] : clears the word before the cursor and copy it in the clipboard.
[cci]Ctrl+y[/cci] : (yank) adds the clipboard content from the cursor position.
[cci]Ctrl+d[/cci] : sends an EOF marker, which (unless disabled by an option) closes the current shell (equivalent to the command exit).
[cci]Ctrl+c[/cci] : sends the signal SIGINT to the current task, which aborts and closes it.
[cci]Ctrl+z[/cci] : sends the signal SIGTSTP to the current task, which suspends it. To return to it later one can enter fg 'process name' (foreground).
[cci]Ctrl+x Ctrl+x[/cci] : (because x has a crossing shape) alternates the cursor with its old position.
[cci]Ctrl+x Ctrl+e[/cci] : (editor because it takes the $EDITOR shell variable) edits the current line in vi.
[cci]Alt+f[/cci] : (forward) moves forward the cursor of one word.
[cci]Alt+b[/cci] : (backward) moves backward the cursor of one word.
[cci]Alt+Del[/cci] : cuts the word before the cursor.
[cci]Alt+d[/cci] : cuts the word after the cursor.
[cci]Alt+u[/cci] : capitalizes every character from the cursor's position to the end of the current word.
[cci]Alt+l[/cci] : lowers the case of every character from the cursor's position to the end of the current word.
[cci]Alt+c[/cci] : capitalizes the character under the cursor and moves to the end of the word.
[cci]Alt+r[/cci] : cancels the changes and put back the line as it was in the history.
[cci]Tab ⇆[/cci] : Autocompletes from the cursor position.
[cci]Ctrl+a[/cci] : moves the cursor at the beginning of the line (equivalent to the key [cci]Home[/cci]).
[cci]Ctrl+e[/cci] : (end) moves the cursor at the line end (equivalent to the key [cci]End[/cci]).
[cci]Ctrl+p[/cci] : (previous) recalls the previous command (equivalent to the key [cci]↑[/cci]).
[cci]Ctrl+n[/cci] : (next) recalls the next command (equivalent to the key [cci]↓[/cci]).
[cci]Ctrl+r[/cci] : (research) recalls the last command including the specified character(s). A second [cci]Ctrl+r[/cci] recalls the next anterior command which corresponds to the research
[cci]Ctrl+s[/cci] : Go back to the next more recent command of the research (beware to not execute it from a terminal because this command also launches its XOFF). If you changed that XOFF setting, use [cci]Ctrl+q[/cci] to return.
[cci]Ctrl+o[/cci] : executes the found command from research.
[cci]Ctrl+l[/cci] : clears the screen content (equivalent to the command clear).
[cci]Ctrl+u[/cci] : clears the line content before the cursor and copy it in the clipboard.
[cci]Ctrl+k[/cci] : clears the line content after the cursor and copy it in the clipboard.
[cci]Ctrl+w[/cci] : clears the word before the cursor and copy it in the clipboard.
[cci]Ctrl+y[/cci] : (yank) adds the clipboard content from the cursor position.
[cci]Ctrl+d[/cci] : sends an EOF marker, which (unless disabled by an option) closes the current shell (equivalent to the command exit).
[cci]Ctrl+c[/cci] : sends the signal SIGINT to the current task, which aborts and closes it.
[cci]Ctrl+z[/cci] : sends the signal SIGTSTP to the current task, which suspends it. To return to it later one can enter fg 'process name' (foreground).
[cci]Ctrl+x Ctrl+x[/cci] : (because x has a crossing shape) alternates the cursor with its old position.
[cci]Ctrl+x Ctrl+e[/cci] : (editor because it takes the $EDITOR shell variable) edits the current line in vi.
[cci]Alt+f[/cci] : (forward) moves forward the cursor of one word.
[cci]Alt+b[/cci] : (backward) moves backward the cursor of one word.
[cci]Alt+Del[/cci] : cuts the word before the cursor.
[cci]Alt+d[/cci] : cuts the word after the cursor.
[cci]Alt+u[/cci] : capitalizes every character from the cursor's position to the end of the current word.
[cci]Alt+l[/cci] : lowers the case of every character from the cursor's position to the end of the current word.
[cci]Alt+c[/cci] : capitalizes the character under the cursor and moves to the end of the word.
[cci]Alt+r[/cci] : cancels the changes and put back the line as it was in the history.
Subscribe to:
Posts (Atom)