WordPress: UNIX Shell Skills:修订间差异

来自站长百科
跳转至: 导航、​ 搜索
无编辑摘要
无编辑摘要
 
第144行: 第144行:
  drwxr-xr-x      2 domain60 vweb    4096  六月 29 18:46 wp-includes
  drwxr-xr-x      2 domain60 vweb    4096  六月 29 18:46 wp-includes
</pre>
</pre>
The permissions are displayed in the string of letters in the first column. The very first letter of that column indicates whether it is a file, a link, or a directory.  A <tt style="font-weight:bold; color:#036">d</tt> denotes a directory, a <tt style="font-weight:bold; color:#036">l</tt> denotes a link, a hyphen denotes a file.


权限显示在第一个栏中的字母串中。那个栏中的第一个字母暗示了字母串是文件,链接还是目录。<tt style="font-weight:bold; color:#036">d</tt>表示目录,<tt style="font-weight:bold; color:#036">l</tt>表示链接,一个破折号表示一个文件。
权限显示在第一个栏中的字母串中。那个栏中的第一个字母暗示了字母串是文件,链接还是目录。<tt style="font-weight:bold; color:#036">d</tt>表示目录,<tt style="font-weight:bold; color:#036">l</tt>表示链接,一个破折号表示一个文件。
The permissions are declared with the following nine letters, which are shown in groups of three.  The first group of three concerns the owner, the second the group he belongs to (this is unlikely to concern you as a web host user), and the third concerns everyone else.  Note that people with root access (administrators) have access to all files on the system.


权限是用下面九个字母公告的,这九个字母作为三组显示。第一组的三个字母,涉及所有者,第二组他所属于的那个组(不可能设计到你,一个网络主机用户),第三组涉及到其他所有的人。注意拥有根权限(管理员)的人能够访问系统上的所有文件。
权限是用下面九个字母公告的,这九个字母作为三组显示。第一组的三个字母,涉及所有者,第二组他所属于的那个组(不可能设计到你,一个网络主机用户),第三组涉及到其他所有的人。注意拥有根权限(管理员)的人能够访问系统上的所有文件。
The letters <tt style="font-weight:bold; color:#036">r</tt>, <tt style="font-weight:bold; color:#036">w</tt> and <tt style="font-weight:bold; color:#036">x</tt> stand for read, write and execute; if the file is a directory, executable means traversible, that is, that you can move into that directory with the <tt style="font-weight:bold; color:#036">cd</tt> command. Where a hyphen is shown in the permissions list, the permission is absent.


字母<tt style="font-weight:bold; color:#036">r</tt>, <tt style="font-weight:bold; color:#036">w</tt> 和 <tt style="font-weight:bold; color:#036">x</tt>代表着阅读,写和执行;如果文件是一个目录,可执行的指的是可移动的,意思是你可以用<tt style="font-weight:bold; color:#036">cd</tt>命令,移动到那个目录上。当权限列表上出现一个破折号的时候,这个权限不存在。
字母<tt style="font-weight:bold; color:#036">r</tt>, <tt style="font-weight:bold; color:#036">w</tt> 和 <tt style="font-weight:bold; color:#036">x</tt>代表着阅读,写和执行;如果文件是一个目录,可执行的指的是可移动的,意思是你可以用<tt style="font-weight:bold; color:#036">cd</tt>命令,移动到那个目录上。当权限列表上出现一个破折号的时候,这个权限不存在。
You change permissions with the <tt style="font-weight:bold; color:#036">chmod</tt> command. You may, in fact, not have to change the permissions at all; some hosts automatically set certain permissions on any file in the web directory. Your host may also tell you what permissions need to be set on your server.


你用<tt style="font-weight:bold; color:#036">chmod</tt>命令更改权限。事实上,你可能不需要更改权限;一些主机在网络目录上的任何文件上,自动地设置某个权限。你的主机可能会通知你,你的服务器上需要设置什么权限。
你用<tt style="font-weight:bold; color:#036">chmod</tt>命令更改权限。事实上,你可能不需要更改权限;一些主机在网络目录上的任何文件上,自动地设置某个权限。你的主机可能会通知你,你的服务器上需要设置什么权限。
The <tt style="font-weight:bold; color:#036">chmod</tt> command can be used to set permissions in two ways: with letters or with numbers. If you use letters, you could type <pre>chmod o+w filename</pre> 
This grants write privileges to everyone with access to the system. The first letter can be u (user), g (group) or o (other), or a combination; the + (grant) can also be - (withhold), and the third can also be r or x (read or execute).


<tt style="font-weight:bold; color:#036">chmod</tt>命令可以用来以两种方式设置权限:用字母或者用数字来设置权限。如果你使用字母,你可以输入<pre>chmod o+w 文件名</pre>   
<tt style="font-weight:bold; color:#036">chmod</tt>命令可以用来以两种方式设置权限:用字母或者用数字来设置权限。如果你使用字母,你可以输入<pre>chmod o+w 文件名</pre>   
这赋予每个人使用系统的特权。第一个字母可以使u(用户),g(小组)或者o(其它的),或者一个组合;the + (grant) 也可以是 be - (withhold), 第三个字母也可以是 r 或者 x (阅读或者执行)。
这赋予每个人使用系统的特权。第一个字母可以使u(用户),g(小组)或者o(其它的),或者一个组合;the + (grant) 也可以是 be - (withhold), 第三个字母也可以是 r 或者 x (阅读或者执行)。
If you use numbers, all permissions for a file are set in one go. An example:
<pre>chmod 755 wp-images</pre>
sets the permssions of the <tt style="font-weight:bold; color:#036">wp-images</tt> directory to 755, whereby the first number (the "hundreds") is for the user, the second (the "tens") is for the group and the third (the "units") is for everyone else.


如果你使用数字,文件的所有权限都可以一次设置好。如:
如果你使用数字,文件的所有权限都可以一次设置好。如:
<pre>chmod 755 wp-images</pre>  
<pre>chmod 755 wp-images</pre>  
设置了<tt style="font-weight:bold; color:#036">wp-images</tt>目录的权限为755,然后第一个数字("百位数")是为用户设置的,第二位数("十位数")是为小组设置的,第三位数("个位数")是为其他所有的人设置的。
设置了<tt style="font-weight:bold; color:#036">wp-images</tt>目录的权限为755,然后第一个数字("百位数")是为用户设置的,第二位数("十位数")是为小组设置的,第三位数("个位数")是为其他所有的人设置的。
'''More about numerical permissions settings:''' To add 4 in any of the fields grants read privileges; to add 2 grants write and to add 1 grants executability; each combination has a unique number. The directories in the example above have the permission set 755, which is common for web-available directories, in which the user has full privileges while others have read and execute only; the files in the example have the permission set 644, in which the user can read and write while others can only read.


'''更多关于数字权限设置的内容:'''在任何区域中添加4,赋予了阅读权限;添加2赋予了编写的权限,而添加1赋予了执行的权限;每个组合都有一个独特的数字。上述例子中的目录,将权限设置为755,对于网络上可以使用的目录,这个权限非常常见,用户拥有所有的特权,而其他人只有阅读和执行的权限;上述例子中的文件的权限设置为644,用户可以阅读和编写文件,而其他人只能够阅读文件。
'''更多关于数字权限设置的内容:'''在任何区域中添加4,赋予了阅读权限;添加2赋予了编写的权限,而添加1赋予了执行的权限;每个组合都有一个独特的数字。上述例子中的目录,将权限设置为755,对于网络上可以使用的目录,这个权限非常常见,用户拥有所有的特权,而其他人只有阅读和执行的权限;上述例子中的文件的权限设置为644,用户可以阅读和编写文件,而其他人只能够阅读文件。
第189行: 第171行:
  drwxr-xr-x  2 domain60 vweb  4096 Jun 29 18:46 wp-includes
  drwxr-xr-x  2 domain60 vweb  4096 Jun 29 18:46 wp-includes
</pre>
</pre>
<pre style="font-size: 0.9em">
  6  4  4
  420400400
-rw-r--r--  1 domain60 vweb  840  Feb 21 06:38 wp-config-sample.php
  7  5  5
  421401401
drwxr-xr-x  2 domain60 vweb  4096 Jun 29 18:46 wp-includes
</pre>


=== wget ===
=== wget ===
=== wget ===
The <tt style="font-weight:bold; color:#036">wget</tt> command downloads a file if you put a web location (URI) after it. To download the latest WordPress release type <pre>wget http://wordpress.org/latest.tar.gz</pre>


如果你在<tt style="font-weight:bold; color:#036">wget</tt>命令后,加上一个网络地址(URI),这个命令就会下载一个文件。要下载最新发行的WordPress版本,请输入<pre>wget http://wordpress.org/latest.tar.gz</pre>
如果你在<tt style="font-weight:bold; color:#036">wget</tt>命令后,加上一个网络地址(URI),这个命令就会下载一个文件。要下载最新发行的WordPress版本,请输入<pre>wget http://wordpress.org/latest.tar.gz</pre>
== Upgrading WordPress from the Shell ==


== 从Shell中升级WordPress ==
== 从Shell中升级WordPress ==
Let's use the example of upgrading WordPress using the command line. First, establish the location of your WordPress on your web server's filesystem. This example assumes it is located at <tt style="font-weight:bold; color:#036">~/public_html/blog</tt>.


让我们来使用,用命令行升级WordPress的例子。首先,在你的网络服务器的文件系统上确立你的WordPress的位置。这个例子中假如WordPress位于<tt style="font-weight:bold; color:#036">~/public_html/blog</tt>。
让我们来使用,用命令行升级WordPress的例子。首先,在你的网络服务器的文件系统上确立你的WordPress的位置。这个例子中假如WordPress位于<tt style="font-weight:bold; color:#036">~/public_html/blog</tt>。


<ol>
<li>Download the current version of WordPress to your shell account's home directory and unzip it: <pre>wget http://wordpress.org/latest.tar.gz
tar -zxvf latest.tar.gz</pre>
<ol>
<ol>
<li>为你的shell帐户的主页目录下载当前的WordPress版本并且将这个版本解压:<pre>wget http://wordpress.org/latest.tar.gz
<li>为你的shell帐户的主页目录下载当前的WordPress版本并且将这个版本解压:<pre>wget http://wordpress.org/latest.tar.gz
tar -zxvf latest.tar.gz</pre>
tar -zxvf latest.tar.gz</pre>
The WordPress archive will be unpacked into a new directory named <tt style="font-weight:bold; color:#036">/wordpress</tt>.</li>
<li>Enter the new directory with the following command: <pre>cd wordpress</pre></li>


WordPress存档文件会被解压到一个新的目录,目录名为<tt style="font-weight:bold; color:#036">/wordpress</tt>.</li>
WordPress存档文件会被解压到一个新的目录,目录名为<tt style="font-weight:bold; color:#036">/wordpress</tt>.</li>
<li>用下面的命令输入新的目录:<pre>cd wordpress</pre></li>
<li>用下面的命令输入新的目录:<pre>cd wordpress</pre></li>
<li>Remove <tt style="font-weight:bold; color:#036">wp-config-sample.php</tt>: <pre>rm wp-config-sample.php</pre> (We will use our current <tt style="font-weight:bold; color:#036">wp-config.php</tt> instead)</li>


<li>移除 <tt style="font-weight:bold; color:#036">wp-config-sample.php</tt>: <pre>rm wp-config-sample.php</pre> (取而代之,我们会看到当前的<tt style="font-weight:bold; color:#036">wp-config.php</tt>)</li>
<li>移除 <tt style="font-weight:bold; color:#036">wp-config-sample.php</tt>: <pre>rm wp-config-sample.php</pre> (取而代之,我们会看到当前的<tt style="font-weight:bold; color:#036">wp-config.php</tt>)</li>
<li>Remove the entire <tt style="font-weight:bold; color:#036">/wp-content</tt> directory from the new directory (we will replace it with the one from our WordPress blog directory): <pre>rm -rf wp-content</pre></li>


<li>将整个<tt style="font-weight:bold; color:#036">/wp-content</tt> 目录,从新的目录中移除 (我们会用WordPress博客中的目录来代替这个目录): <pre>rm -rf wp-content</pre></li>
<li>将整个<tt style="font-weight:bold; color:#036">/wp-content</tt> 目录,从新的目录中移除 (我们会用WordPress博客中的目录来代替这个目录): <pre>rm -rf wp-content</pre></li>
<li>Copy the blog's <tt style="font-weight:bold; color:#036">wp-config.php</tt> and <tt style="font-weight:bold; color:#036">.htaccess</tt> file to the new directory: <pre>cp ~/public_html/blog/wp-config.php .


<li>将博客的<tt style="font-weight:bold; color:#036">wp-config.php</tt> 和<tt style="font-weight:bold; color:#036">.htaccess</tt> 文件复制到新的目录中: <pre>cp ~/public_html/blog/wp-config.php .
<li>将博客的<tt style="font-weight:bold; color:#036">wp-config.php</tt> 和<tt style="font-weight:bold; color:#036">.htaccess</tt> 文件复制到新的目录中: <pre>cp ~/public_html/blog/wp-config.php .


 
cp ~/public_html/blog/.htaccess .</pre> 注意: 不要忘了两个命令后面的点号!</li>
cp ~/public_html/blog/.htaccess .</pre> Note: Don't forget the dot at the end of both commands!</li>
 
cp ~/public_html/blog/.htaccess .</pre> 注意: 不要网络两个命令后面的点号!</li>
 
 
<li>Copy the <tt style="font-weight:bold; color:#036">wp-content</tt> directory to the new directory (it contains all our themes and plugins): <pre>cp -rf ~/public_html/blog/wp-content/ .</pre> Again, note the dot at the end of the command.</li>


<li>将<tt style="font-weight:bold; color:#036">wp-content</tt>目录复制到新的目录(包含了我们所有的主题和插件): <pre>cp -rf ~/public_html/blog/wp-content/ .</pre> 再一次地注意,命令结尾的点号。</li>
<li>将<tt style="font-weight:bold; color:#036">wp-content</tt>目录复制到新的目录(包含了我们所有的主题和插件): <pre>cp -rf ~/public_html/blog/wp-content/ .</pre> 再一次地注意,命令结尾的点号。</li>
<li>Remove the entire contents of your WordPress blog directory: <pre>rm -rf ~/public_html/blog/*</pre></li>


<li>移除你的WordPress博客目录中的所有内容: <pre>rm -rf ~/public_html/blog/*</pre></li>
<li>移除你的WordPress博客目录中的所有内容: <pre>rm -rf ~/public_html/blog/*</pre></li>
<li>Finally, copy the entire contents of the new directory to your main blog directory: <pre>cp -rf * ~/public_html/blog</pre></li>
</ol>


<li>最后,将新目录的所有内容复制到你的主要博客目录中: <pre>cp -rf * ~/public_html/blog</pre></li>
<li>最后,将新目录的所有内容复制到你的主要博客目录中: <pre>cp -rf * ~/public_html/blog</pre></li>
</ol>
</ol>
== SFTP Shell Commands ==


== SFTP Shell 命令 ==
== SFTP Shell 命令 ==
SFTP stands for Secure File Transfer Protocol.  It is an encrypted replacement for FTP, and as with FTP, you may use a shell-based client or one of the graphical clients mentioned at the top of this article. If your host supports SSH, it also supports SFTP.


SFTP代表安全文件传输协议,是加密的FTP形式,如FTP,你可以使用在这篇文章的顶端所提到的一个shell为基础的client或者一个图形client。如果你的主机支持SSH,主机就同样支持SFTP。
SFTP代表安全文件传输协议,是加密的FTP形式,如FTP,你可以使用在这篇文章的顶端所提到的一个shell为基础的client或者一个图形client。如果你的主机支持SSH,主机就同样支持SFTP。


=== Shell-identical commands ===
=== 与Shell一样的命令===
=== 与Shell一样的命令===


 
Shell类型支持的命令,类似于用在bash中的命令。这些包括 <tt style="font-weight:bold; color:#036">cd</tt>, <tt style="font-weight:bold; color:#036">ls</tt>, <tt style="font-weight:bold; color:#036">mkdir</tt>, <tt style="font-weight:bold; color:#036">rm</tt> 和 <tt style="font-weight:bold; color:#036">rmdir</tt>。也支持 <tt style="font-weight:bold; color:#036">ln</tt>, 不同的是,你不需要使用<tt style="font-weight:bold; color:#036">-s</tt> 选项来创建symlinks; 在sftp中, <tt style="font-weight:bold; color:#036">ln</tt> 命令使得symlinks 是默认的。所有这些命令对于你的主机系统上的文件都起作用。
Shell-type SFTP clients support commands similar to those used in bash.  These include <tt style="font-weight:bold; color:#036">cd</tt>, <tt style="font-weight:bold; color:#036">ls</tt>, <tt style="font-weight:bold; color:#036">mkdir</tt>, <tt style="font-weight:bold; color:#036">rm</tt> and <tt style="font-weight:bold; color:#036">rmdir</tt>. It also supports <tt style="font-weight:bold; color:#036">ln</tt>, with the difference that you do not need to use the <tt style="font-weight:bold; color:#036">-s</tt> option to create symlinks; in sftp, the <tt style="font-weight:bold; color:#036">ln</tt> command makes symlinks by default. All of these work on files on your host's system.
 
 
Shell类型支持的命令,类似于用在bash中的命令。这些包括 <tt style="font-weight:bold; color:#036">cd</tt>, <tt style="font-weight:bold; color:#036">ls</tt>, <tt style="font-weight:bold; color:#036">mkdir</tt>, <tt style="font-weight:bold; color:#036">rm</tt> 和 <tt style="font-weight:bold; color:#036">rmdir</tt>。也支持 <tt style="font-weight:bold; color:#036">ln</tt>, 不同的是,你不需要使用<tt style="font-weight:bold; color:#036">-s</tt> 选项来创建symlinks; 在sftp中, <tt style="font-weight:bold; color:#036">ln</tt> 命令使得symlinks 是默认的。所欲这些命令对于你的主机系统上的文件都起作用。


=== put and mput ===
=== put and mput ===
=== put and mput ===
These two commands transfer to your host (i.e. upload) a single file (<tt style="font-weight:bold; color:#036">put</tt>) or any files that match the pattern you supply (<tt style="font-weight:bold; color:#036">mput</tt>); the wildcards <tt style="font-weight:bold; color:#036">*</tt> and <tt style="font-weight:bold; color:#036">?</tt> described above can be used here.


这两个命令转移到你的主机(例如上传)一个单独的文件(<tt style="font-weight:bold; color:#036">put</tt>)或者任何与你支持的模式相匹配的文件(<tt style="font-weight:bold; color:#036">mput</tt>);以上所描述的通配符<tt style="font-weight:bold; color:#036">*</tt> 和<tt style="font-weight:bold; color:#036">?</tt>可以用在这儿。
这两个命令转移到你的主机(例如上传)一个单独的文件(<tt style="font-weight:bold; color:#036">put</tt>)或者任何与你支持的模式相匹配的文件(<tt style="font-weight:bold; color:#036">mput</tt>);以上所描述的通配符<tt style="font-weight:bold; color:#036">*</tt> 和<tt style="font-weight:bold; color:#036">?</tt>可以用在这儿。


=== get and mget ===
=== get and mget ===
=== get and mget ===
These two commands transfer from your host to your local computer (i.e. download) a single file (<tt style="font-weight:bold; color:#036">get</tt>) or any files that match the supplied pattern (<tt style="font-weight:bold; color:#036">mget</tt>).  As with <tt style="font-weight:bold; color:#036">mput</tt>, <tt style="font-weight:bold; color:#036">*</tt> and <tt style="font-weight:bold; color:#036">?</tt> can be used.


这两个命令从你的主机转移到你的本地电脑上(例如下载)一个单一的文件(<tt style="font-weight:bold; color:#036">get</tt>)或者任何匹配支持的模式的文件(<tt style="font-weight:bold; color:#036">mget</tt>)。与<tt style="font-weight:bold; color:#036">mput</tt>一样,可以使用<tt style="font-weight:bold; color:#036">*</tt> 和 <tt style="font-weight:bold; color:#036">?</tt>。
这两个命令从你的主机转移到你的本地电脑上(例如下载)一个单一的文件(<tt style="font-weight:bold; color:#036">get</tt>)或者任何匹配支持的模式的文件(<tt style="font-weight:bold; color:#036">mget</tt>)。与<tt style="font-weight:bold; color:#036">mput</tt>一样,可以使用<tt style="font-weight:bold; color:#036">*</tt> 和 <tt style="font-weight:bold; color:#036">?</tt>。


=== cd, mkdir, ls ===
=== cd, mkdir, ls ===
=== cd, mkdir, ls ===
These commands are identical to their bash shell counterparts: change the current directory, make a new directory, and list the contents of the current directory. To do the same things within SFTP on your own machine, add an <tt style="font-weight:bold; color:#036">l</tt> to the front of the commands: <tt style="font-weight:bold; color:#036">lcd</tt>, <tt style="font-weight:bold; color:#036">lmkdir</tt>, <tt style="font-weight:bold; color:#036">lls</tt>.


这些命令与命令的bash shell命令是相同的:更改当前的目录,创建一个新的目录,列出当前目录的内容。在你自己的电脑的SFTP内部执行同样的操作,在命令的前面添加一个<tt style="font-weight:bold; color:#036">l</tt>:<tt style="font-weight:bold; color:#036">lcd</tt>, <tt style="font-weight:bold; color:#036">lmkdir</tt>, <tt style="font-weight:bold; color:#036">lls</tt>。
这些命令与命令的bash shell命令是相同的:更改当前的目录,创建一个新的目录,列出当前目录的内容。在你自己的电脑的SFTP内部执行同样的操作,在命令的前面添加一个<tt style="font-weight:bold; color:#036">l</tt>:<tt style="font-weight:bold; color:#036">lcd</tt>, <tt style="font-weight:bold; color:#036">lmkdir</tt>, <tt style="font-weight:bold; color:#036">lls</tt>。
== Further Reading ==


==深入阅读 ==
==深入阅读 ==
[http://catcode.com/teachmod/ chmod tutorial]
[http://catcode.com/teachmod/ chmod 指南]
[http://catcode.com/teachmod/ chmod 指南]
[http://www.classical-webdesigns.co.uk/resources/whatchmod.html What chmod?] online file permissions calculator
[http://www.classical-webdesigns.co.uk/resources/whatchmod.html 什么 chmod?]在线文件权限计算器
[http://www.classical-webdesigns.co.uk/resources/whatchmod.html 什么 chmod?]在线文件权限计算器
== See also ==


== 也看看 ==
== 也看看 ==
[[WordPress:Changing File Permissions]]
[[WordPress:htaccess for subdirectories]]


[[WordPress:Changing File Permissions|更改文件权限]]
[[WordPress:Changing File Permissions|更改文件权限]]


[[WordPress:htaccess for subdirectories|子目录的htaccess]]
[[WordPress:htaccess for subdirectories|子目录的htaccess]]

2008年7月1日 (二) 14:58的最新版本

注意: 这篇文章包含一个高级主题。

如果你最近从一个托管的写博客的solution,如Blogger或者TypePad中进入了WordPress,你可能对于管理网络空间和博客的任务不太熟悉。WordPress是以PHP为基础的; 许多托管服务使用服务器运行Linux 和Apache; 许多网络服务器不仅向它们的顾客提供以网络为基础的 控制界面 还提供 shell权限 或者命令行界面。许多WordPress用户对于使用shell 来管理文件系统,可能不熟悉。这篇文章介绍了更加常用的UNIX命令并且示范了一个常规的管理任务是如何运行的,如一个小型的WordPress升级,就是在shell上执行的。

The bash shell[ ]

你的网络主机提供的shell很可能是bash,bash指的是"Bourne Again Shell",是以编写了original 现代 Unix shellStephen Bourne 命名的。bash是由免费软件基金会来命名的。有许多不同的Unix shells。下面简单描述的命令行几乎对于所有的Unix shells都是适用的。

ssh, 安全 shell[ ]

安全 Shell (ssh)是用于远程管理你的站点的一套完整的工具。包含有SFTP (安全文件传输协议)用来向你的主机上传文件。使用ssh的主要好处是,通过与一个远程的服务器接触来增加安全性。与其它的服务器访问工具一起,你的登录密码可能通过一个纯文本在因特网上传输,可能会被截取。

在Windows下,使用 ssh , 使用 PuTTY 或者Cygwin, 为Widows使用一个类似UNIX的环境。The FileZilla ftp client 通过ssh-2也支持sftp 。

要在一个运行OS X的Mac上使用ssh , 使用Mac OS X 支持的,以终端为基础的SSH程序或者下载Fugu

在 Linux 或者以 UNIX为基础的操作系统上, 你可以从终端上使用以文本为基础的SSH和SFTP clients,如Konsole, Gnome Terminal 或者xterm。 图画式的 FTP clients 如KBear and gFTP 也支持sftp

你的主机公司会提供用户名你和主机的详细信息,使用这些信息是必要的。这些信息可能与你在控制面板上使用的信息有所不同。要使用这些信息,在Terminal prompt 输入

ssh username@host

or

sftp username@host

术语[ ]

在开始处理一些UNIX commands之前,让我们来阅读一些术语。

目录? 文件夹?

;目录与文件夹指的是同一样的内容。目录可以包含有子目录。

  • 点(句点或者句号)指的是当前的目录;两个点指的是当前目录的上级目录。
  • 曲线字符(~)指的是你的主页目录。
  • 用户名后面的曲线字符(如在~username)指的是用户的主页目录。
句点标记和曲线符号都可以看作为目录名称。例如, ../config.php指的是当前目录的上一次目录上的文件 config.php。目录 ./functions.php 指的是当前目录中的 functions.php。而且 ~/public_html or ~/htdocs (通常)是你的主要网页目录的名称,这个名称很可能是你的主页目录的一个子目录的名称。显示在你的网络服务器的地址框中域 URI 指的是主要的网页目录,而不是站点所有者的主页目录。
前斜线(/)

:前斜线的功能与前斜线在网站URI上的功能相同:it shows the item after to be in a subdirectory or the directory before it.斜线本身代表根目录,在文件系统的顶上方

目录名字符规则和空格

:文件或者目录名称可以包含任何标准的字符,但是一个前斜线&mdash除外;空格也除外。然而,当输入shell 命令行的时候,你用空格将命令行,参数,和文件分开。如果你的文件或者目录名中有一个空格,你需要在空格的前面使用一个前斜线。或者在文件或目录名称的周围加上一个引号。一个称为我的图片的目录,会以

"我的图片"

或者

我的\ 图片

输入。

*和? 符号: *? 符号称为通配符 可以用在任何处理文件的命令行中。* 指的是许多字符。?指的是一个字符。注意Linux 文件名是区分大小写的— 规范的形式是小写形式。所有的命令行都是小写的。

命令选项:命令通常接受选项或者参数, 这些选项和字符以一个连字号开始,挨次给出。如果你想为一个命令设置选项b, r and f,输入

command -brf

,其它的详细信息,例如文件名,在选项的后面。

Shell 命令[ ]

下面简要介绍一些有用的UNIX shell命令。

ls[ ]

这个命令显示了一个目录的内容的列表。为更改前,命令显示了当前目录的内容;你可以特别规定列出另一个目录的内容。一些有用的选项是:

  • ls -l

:如果列表很长,你可以在网页上显示列表。输入

ls -l |less

,执行这一步

(注意: 竖线 |也成为一个 UNIX pipe). pipe bar 指的是来自ls -l的输出,提交到了一个程序 less, 这个程序显示了任何收到的输入内容。你可以点击空白处,来访问下一个网页,或者点击箭头,向上或者向下翻看。
  • ls -la
包含隐藏文件 (例如,以一个圆点开始的文件,像目录列表中的 .htaccess)。
  • ls -l g*

:指定任何其它的目录或者文件组列在选项的后面,在一个例子中,会列出所有以g开始的文件,然而ls public_html会列出public_html的内容。

cd[ ]

cd命令更改了当前的目录。要从当前的目录切换到一个子目录中,将子目录的名称放到命令行的后面。要变成一个子目录wp-content,你需要输入

cd wp-wp-content


要进入当前目录的上级目录,请输入:

cd ..


要从当前目录切换到你的主目录中,输入

cd

mkdir[ ]

mkdir命令创建了一个在当前目录内部创建了一个新的目录。要在当前的目录中,创建一个名为audio目录,请输入

mkdir audio

要移除一个空目录,请输入rmdir directoryname例如;

rmdir audio

rm[ ]

rm命令删除('移除')一个文件。要一次地删除整个目录以及目录中所包含的内容,输入rm -rf directoryname。要删除当前目录中的所有内容,使用

rm -rf *

要谨慎—一旦某个内容以这样的方式删除掉了,这个内容就永远都不会返回了。

离开当前命令行外壳[ ]

exit命令结束了你的shell部分。

mv[ ]

mv命令将文件从一个位置移到了另一个位置;同时还会重新命名文件。输入

mv file new-location

如果 new-location 参数是当前文件系统中的一个 (有效的) 目录,文件就会被移动到这个目录;如果目录不是有效地目录 (而且目录名不与当前的文件名相冲突的话), 文件 就会被重新命名为 new-location。你也可以使用一个命令,移动和重新命名一个文件:

mv file ~/path/to/new-file-name

cp[ ]

cp命令复制文件或者目录。要复制一个目录和目录的全部内容,请使用

cp -rf source-file destination

ln[ ]

ln命令创建链接。与我们的目标相关的链接是"符号链接" 或者 symlinks —文件系统中 "指向" 其它文件或者目录的文件。当你访问一个 symlink的时候,你真正是在使用原始文件。如果你想要将你的WordPress目录的位置,如从/wordpress/ 改到/blog/中,你可以创建一个如下的symlinks:

ln -s wordpress blog

然后通过文件或者目录真正的名称来访问— wordpress —或者通过链接名— blog。在WordPress管理面板选项面板中,设置"博客地址(URI)"区,来显示symlink取代目录名。

tar and unzip[ ]

tarunzip 命令是用来压缩和解压"归档"文件的。存档指的是已经被"压缩的"文件或者文件加 — 例如,文件按大小得到了压缩— 通常是用来发行或者作为备份用的。解压 命令是用来将文件以.zip结束; the tar 命令是用来将文件以.tgz 或者 .tar.gz结束.

解压文件:如果文件是一个.tar.gz归档,请输入

tar -zxvf file.tar.gz

如果文件是压缩归档,你可能要创建一个临时的目录,你将文件的内容解压到这个目录中(否则,文件就会解压到当前的目录中)。

chmod和文件权限[ ]

chmod更改了一个特定的文件的权限。UNIX 文件权限规定了谁可以对文件进行什么样的处理。ls -l 命令告诉了你一个文件或者目录拥有什么权限:

 -rw-r--r--      1 domain60 vweb     840   二月 21 06:38 wp-config-sample.php
 -rw-r--r--      1 domain60 vweb     826   六月 29 20:31 wp-config.php
 drwxr-xr-x      4 domain60 vweb     4096  六月 29 20:30 wp-content
 -rw-r--r--      1 domain60 vweb     762   三月 29 16:05 wp-feed.php
 drwxr-xr-x      3 domain60 vweb     4096  六月 29 18:46 wp-images
 drwxr-xr-x      2 domain60 vweb     4096  六月 29 18:46 wp-includes

权限显示在第一个栏中的字母串中。那个栏中的第一个字母暗示了字母串是文件,链接还是目录。d表示目录,l表示链接,一个破折号表示一个文件。

权限是用下面九个字母公告的,这九个字母作为三组显示。第一组的三个字母,涉及所有者,第二组他所属于的那个组(不可能设计到你,一个网络主机用户),第三组涉及到其他所有的人。注意拥有根权限(管理员)的人能够访问系统上的所有文件。

字母r, wx代表着阅读,写和执行;如果文件是一个目录,可执行的指的是可移动的,意思是你可以用cd命令,移动到那个目录上。当权限列表上出现一个破折号的时候,这个权限不存在。

你用chmod命令更改权限。事实上,你可能不需要更改权限;一些主机在网络目录上的任何文件上,自动地设置某个权限。你的主机可能会通知你,你的服务器上需要设置什么权限。

chmod命令可以用来以两种方式设置权限:用字母或者用数字来设置权限。如果你使用字母,你可以输入

chmod o+w 文件名

这赋予每个人使用系统的特权。第一个字母可以使u(用户),g(小组)或者o(其它的),或者一个组合;the + (grant) 也可以是 be - (withhold), 第三个字母也可以是 r 或者 x (阅读或者执行)。

如果你使用数字,文件的所有权限都可以一次设置好。如:

chmod 755 wp-images

设置了wp-images目录的权限为755,然后第一个数字("百位数")是为用户设置的,第二位数("十位数")是为小组设置的,第三位数("个位数")是为其他所有的人设置的。

更多关于数字权限设置的内容:在任何区域中添加4,赋予了阅读权限;添加2赋予了编写的权限,而添加1赋予了执行的权限;每个组合都有一个独特的数字。上述例子中的目录,将权限设置为755,对于网络上可以使用的目录,这个权限非常常见,用户拥有所有的特权,而其他人只有阅读和执行的权限;上述例子中的文件的权限设置为644,用户可以阅读和编写文件,而其他人只能够阅读文件。

   6  4  4
  420400400
 -rw-r--r--  1 domain60 vweb  840  Feb 21 06:38 wp-config-sample.php

   7  5  5
  421401401
 drwxr-xr-x  2 domain60 vweb  4096 Jun 29 18:46 wp-includes

wget[ ]

如果你在wget命令后,加上一个网络地址(URI),这个命令就会下载一个文件。要下载最新发行的WordPress版本,请输入

wget http://wordpress.org/latest.tar.gz

从Shell中升级WordPress[ ]

让我们来使用,用命令行升级WordPress的例子。首先,在你的网络服务器的文件系统上确立你的WordPress的位置。这个例子中假如WordPress位于~/public_html/blog

  1. 为你的shell帐户的主页目录下载当前的WordPress版本并且将这个版本解压:
    wget http://wordpress.org/latest.tar.gz
    tar -zxvf latest.tar.gz
    WordPress存档文件会被解压到一个新的目录,目录名为/wordpress.
  2. 用下面的命令输入新的目录:
    cd wordpress
  3. 移除 wp-config-sample.php:
    rm wp-config-sample.php
    (取而代之,我们会看到当前的wp-config.php)
  4. 将整个/wp-content 目录,从新的目录中移除 (我们会用WordPress博客中的目录来代替这个目录):
    rm -rf wp-content
  5. 将博客的wp-config.php.htaccess 文件复制到新的目录中:
    cp ~/public_html/blog/wp-config.php .
    
    cp ~/public_html/blog/.htaccess .
    注意: 不要忘了两个命令后面的点号!
  6. wp-content目录复制到新的目录(包含了我们所有的主题和插件):
    cp -rf ~/public_html/blog/wp-content/ .
    再一次地注意,命令结尾的点号。
  7. 移除你的WordPress博客目录中的所有内容:
    rm -rf ~/public_html/blog/*
  8. 最后,将新目录的所有内容复制到你的主要博客目录中:
    cp -rf * ~/public_html/blog

SFTP Shell 命令[ ]

SFTP代表安全文件传输协议,是加密的FTP形式,如FTP,你可以使用在这篇文章的顶端所提到的一个shell为基础的client或者一个图形client。如果你的主机支持SSH,主机就同样支持SFTP。

与Shell一样的命令[ ]

Shell类型支持的命令,类似于用在bash中的命令。这些包括 cd, ls, mkdir, rmrmdir。也支持 ln, 不同的是,你不需要使用-s 选项来创建symlinks; 在sftp中, ln 命令使得symlinks 是默认的。所有这些命令对于你的主机系统上的文件都起作用。

put and mput[ ]

这两个命令转移到你的主机(例如上传)一个单独的文件(put)或者任何与你支持的模式相匹配的文件(mput);以上所描述的通配符*?可以用在这儿。

get and mget[ ]

这两个命令从你的主机转移到你的本地电脑上(例如下载)一个单一的文件(get)或者任何匹配支持的模式的文件(mget)。与mput一样,可以使用*?

cd, mkdir, ls[ ]

这些命令与命令的bash shell命令是相同的:更改当前的目录,创建一个新的目录,列出当前目录的内容。在你自己的电脑的SFTP内部执行同样的操作,在命令的前面添加一个llcd, lmkdir, lls

深入阅读[ ]

chmod 指南 什么 chmod?在线文件权限计算器

也看看[ ]

更改文件权限

子目录的htaccess