A command-line interpreter is a computer program that reads singular lines of text entered by a user and interprets them in the context of a given operating system or programming/scripting language. The interaction takes place by means of a command-line interface. Other common, but technically not quite correct, denominations are console or shell.
The OpenWrt standard unix shell is the Busybox-fork of the Debian implementation of the Almquist shell (see → http://www.in-ulm.de/~mascheck/various/ash/#busybox). In case you want to read about it.
At the end of the boot up process, the init daemon is started, this can be init or systemd or upstart, etc. OpenWrt currently uses
procd. Following the boot up scripts located in
init will then start all sorts of programs, amongst them the chosen shell. This listens to keyboard strokes and outputs a more or less colorful command-line interface to the connected display.
But most devices you run OpenWrt on, have neither a keyboard nor a display adapter. So we need to access it over the serial port (=local) or over the Ethernet port (= over the network).
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).
(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:
PS1. see → http://controlc.de/2010/03/12/bash-shell-einrichten/ and many many many other pages in the web on help with that
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.
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
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