User Tools

Site Tools



命令行解释器读取用户的一行输入,然后在操作系统或者脚本语言给定的上下文中解释执行它。这些操作可以通过 command-line interface 进行. 用得更多, 但可能并不很严谨例子是 consoleshell.

OpenWrt标准的 unix shell 是分支自 Busybox 的在 Debian 上实现的 Almquist shell (see → 如果你愿意来了解一下的话.


启动过程结束的时候, init daemon 启动, 这个进程可能是 initsystemdupstart, 等等. OpenWrt现在采用的是 busybox-init. 根据 /etc/rd.d 中的启动脚本, init 将会打开各种程序, 其中就包括设定的 shell . 它将会等待键盘输入然后再已经连接的显示器上显示一个或多或少彩色的命令行界面.

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 telnetd will run, and after only dropbear.

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:

复制 & 粘贴

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]!

Numpad in PuTTY while using Vi

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:

命令 Memorize 详细描述
pwd print working directory prints out the current directory you are in
cd change directory move through the file system directory tree: cd .., cd /, cd /etc/init.d, cd /tmp
ls list print the content of the current directory, ls -l /etc
cat concatenate printing the content of a file on screen: cat /etc/config/network, cat /tmp/dhcp.leases
cp copy creates a copy of the specified file, cp network network.bak
mv move creates a copy of the specified file and deletes the original, mv /tmp/opkg-lists/snapshots /mnt/sda1/opkg/packages
df disk free Shows you available space. Again, see flash.layout for understanding /rom, etc. And see df for help with the command and it's options. Try df -h.
free about free RAM
uptime time elapsed since last boot
dmesg print or control the kernel ring buffer
logread Shows the messages from syslogd (using circular buffer)
cat /proc/version
cat /proc/meminfo
more detailed data uppon RAM usage
cat /proc/cpuinfo
about your CPU
cat /proc/mtd
cat /proc/partitions
cat /proc/net/nf_conntrack
cat /proc/cmdline
cat /proc/modules

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 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 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.

  • vi has 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
  • vi starts out in command mode


Start with vi or 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:

  • :w to write the current file to disc, this will overwrite the old file
  • :q to quit without writing
  • :wq! to (forcefully) write to disk and then quit vi
  • :%s/string1/string2/g replace string1 with string2 in the whole file


Vi can be configured in command mode by setting certain variables:

  • :set ai use auto indentation (sometimes annoying default)
  • :set noai NO auto indentation


If you do not like vi, try joe, mg, nano, vim, vim-full, vim-help, vim-runtime, zile

  • 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


OpenWrt 默认使用 busybox 的 ash shell , ash shell 基本遵循 POSIX 规范. 访问 shell script 了解关于 shell 脚本的更多信息.


Shell scripts can be executed with:

sh /path/to/

After changing the executable bit its also possible to run it without the sh in front:

chmod +x /path/to/ /path/to/


You may also want to try mc or deco.


Konqueror GVim WinSCP


zh-cn/doc/howto/user.beginner.cli.txt · Last modified: 2013/11/15 10:29 (external edit)