命令行解释器读取用户的一行输入，然后在操作系统或者脚本语言给定的上下文中解释执行它。这些操作可以通过 command-line interface 进行. 用得更多, 但可能并不很严谨例子是 console 或 shell.
OpenWrt标准的 unix shell 是分支自 Busybox 的在 Debian 上实现的 Almquist shell (see → http://www.in-ulm.de/~mascheck/various/ash/#busybox). 如果你愿意来了解一下的话.
But most devices you run OpenWrt on, 既没有键盘也没有显示器. So we need to access it over the serial port (=local) or over the Ethernet port (= 通过网络).
To gain access to a shell over the network, you obviously need some other programs to help you with that. And the whole data exchange (aka communication) has to involve some kind of network protocol.
Network protocols of choice are telnet and SSH. Both follow the server ↔ client scheme. On the device running OpenWrt we deploy
telnetd for the telnet protocol and
dropbear for for the SSH protocol. Try PuTTY for the real look-and-feel, but you should definitely also checkout WinSCP! The latter won't work quite correctly, however Konqueror with
fish:// does! See FISH (Files transferred over shell protocol).
For more clients, see Comparison_of_SSH_clients.
(OpenWrt does also include a SSH-client
ssh and a telnet-client
telnet, in case you want to login from it to somewhere else.)
|Note: Before firstlogin only
In case of a successful login
dropbear will (generate a LOG and) spawn an instance of the specified shell (more shells can be installed simultaneously) with the users ID.
In OpenWrt this is done in the file:
/etc/profile by setting environment variables and aliases. It comes (of course) pre-configured and will work out-of-the-box, but you can alter and augment it's configuration:
- you can configure the command prompt via the variable
PS1. see → http://controlc.de/2010/03/12/bash-shell-einrichten/ and many many many other pages in the web on help with that
- you change the content of existent variables and can define new ones
When in PuTTY, you can mark text content with the mouse and, without pressing any key (like [Ctrl]+[c]), it is being automatically stored. You can then insert it the usual way (with [Ctrl]+[v]) in an other windows, e.g. an open firefox. The other way around, you copy text the usual way [Ctrl]+[c]) and then paste it in PuTTY by pressing the [right mouse button]!
In PuTTY goto "Terminal" ⇒ "Features" and check "Disable application keypad mode".
At login you will be in your $HOME directory, which is
/root for user root and would be
/home/user1 for user1, etc. Commands:
||print working directory||prints out the current directory you are in|
||change directory||move through the file system directory tree:
||list||print the content of the current directory,
||concatenate||printing the content of a file on screen: cat
||copy||creates a copy of the specified file,
||move||creates a copy of the specified file and deletes the original,
||disk free||Shows you available space. Again, see flash.layout for understanding
||about free RAM|
||time elapsed since last boot|
||print or control the kernel ring buffer|
||Shows the messages from syslogd (using circular buffer)|
|more detailed data uppon RAM usage|
|about your CPU|
There is a ton of commands with a ton of options. On a full blown Linux distribution you would issue a
man command to learn about the command and its options. However OpenWrt is minimalistic and thus does not contain this functionality. So either read the man-pages (manual pages) on another GNU/Linux machine or read them online: e.g. at http://man.cx/. Man pages are in the process of being translated.
Tip In firefox, you can use keywords to simplify the usage. Create a new bookmark, use
http://man.cx/?page=%s as address and
man as keyword.
To edit a file you need an editor, to edit a text file, you would use a text editor.
The standard text editor included is
vi. Until you get used to it, vi is neither intuitive nor pretty.
vihas two modes: command mode and insert mode.
- to enter command mode press [Esc] (escape key)
- to enter insert mode press either [i] for insert or [a] for append
vistarts out in command mode
vi /etc/config/network or
vi firewall.user if you are already in the same directory.
In order to edit the file, you have to be in insert mode. Press [i] or [a].
In order to get out of vi, you have to be in command mode. Press [Esc] (the escape key). Then issue one of the following commands:
:wto write the current file to disc, this will overwrite the old file
:qto quit without writing
:wq!to (forcefully) write to disk and then quit vi
:%s/string1/string2/greplace string1 with string2 in the whole file
Vi can be configured in command mode by setting certain variables:
:set aiuse auto indentation (sometimes annoying default)
:set noaiNO auto indentation
If you do not like
- and there may be other text editors available in the OpenWrt repos
- when logged in via WinSCP/Konqueror you can also use some Editor on your PC
Shell scripts can be executed with:
After changing the executable bit its also possible to run it without the sh in front:
chmod +x /path/to/script.sh
zh-cn/doc/howto/user.beginner.cli.txt · Last modified: 2013/11/15 10:29 by lorema