| Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision |
| docs:guide-user:base-system:user.beginner.cli [2018/03/03 20:35] – ↷ Links adapted because of a move operation | docs:guide-user:base-system:user.beginner.cli [2021/03/16 02:11] – [Profile customization] comment vgaetera |
|---|
| ====== Command-line interpreter ====== | ====== Command-line interpreter ====== |
| | See also: [[docs:guide-quick-start:sshadministration|SSH access for newcomers]] |
| | |
| 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 [[wp>command-line interface]]. Other common, but technically not quite correct, denominations are **console** or **shell**. | 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 [[wp>command-line interface]]. Other common, but technically not quite correct, denominations are **console** or **shell**. |
| |
| The OpenWrt standard [[wp>unix shell]] is the Busybox-fork of the Debian implementation of the [[wp>Almquist shell]] (see -> [[http://www.in-ulm.de/~mascheck/various/ash/#busybox]]). In case you want to read about it. | The OpenWrt standard [[wp>unix shell]] is the Busybox-fork of the Debian implementation of the [[wp>Almquist shell]] (see -> [[https://www.in-ulm.de/~mascheck/various/ash/#busybox]]). In case you want to read about it. |
| |
| ===== Start ===== | ===== Start ===== |
| At the end of the boot up process, the **init daemon** is started, this can be [[wp>init]] or [[wp>systemd]] or [[wp>upstart]], etc. OpenWrt currently uses **''[[docs:techref:procd]]''**. Following the boot up scripts located in ''/etc/rd.d'', ''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. | At the end of the boot up process, the **init daemon** is started, this can be [[wp>init]] or [[wp>systemd]] or [[wp>upstart]], etc. OpenWrt currently uses **''[[docs:techref:procd]]''**. Following the boot up scripts located in ''/etc/rc.d'', ''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 [[docs:hardware:port.serial|serial port]] (=local) or over the Ethernet port (= over the network). | |
| |
| | But most devices you run OpenWrt on, have neither a keyboard nor a display adapter. So we need to access it over the [[docs:techref:hardware:port.serial|serial port]] (=local) or over the Ethernet port (= over the network). |
| |
| ===== Network ===== | ===== Network ===== |
| (OpenWrt does also include a SSH-client ''ssh'' and a telnet-client ''telnet'', in case you want to login from it to somewhere else.) | (OpenWrt does also include a SSH-client ''ssh'' and a telnet-client ''telnet'', in case you want to login from it to somewhere else.) |
| |
| | {{:meta:icons:tango:dialog-information.png?nolink}} | **Note:** Before [[doc:howto:firstlogin]] only ''telnetd'' will run, and after only ''dropbear''. | | | {{:meta:icons:tango:dialog-information.png?nolink}} | **Note:** Before [[docs:guide-quick-start:walkthrough_login]] 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 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. |
| |
| * [[http://www.electrictoolbox.com/article/applications/ssh-putty/|Howto login to an SSH Server using PuTTY]] | * [[docs:guide-quick-start:sshadministration|SSH Access for Newcomers]] |
| |
| ===== Configuration ===== | ===== Configuration ===== |
| In OpenWrt this is done in the file: ''[[docs:guide-user:base-system:notuci.config#etcprofile|/etc/profile]]'' by setting [[wp>Environment variable|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: | In OpenWrt this is done in the file: ''[[docs:guide-user:base-system:notuci.config#etcprofile|/etc/profile]]'' by setting [[wp>Environment variable|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 [[wp>command-line_interface#Command_prompt|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 can configure the [[wp>command-line_interface#Command_prompt|command prompt]] via the variable ''PS1''. see -> [[https://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 | * you change the content of existent variables and can define new ones |
| * etc. | * etc. |
| |
| ===== Copy & Paste ===== | ===== Copy & paste ===== |
| 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]! | 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 ==== | ==== Numpad in PuTTY while using Vi ==== |
| In PuTTY goto //"Terminal"// => //"Features"// and check //"Disable application keypad mode"//. | In PuTTY goto //"Terminal"// => //"Features"// and check //"Disable application keypad mode"//. |
| |
| |
| ===== Issue commands ===== | ===== Issue commands ===== |
| * For some orientation with the file system and the whole directories, check [[docs:techref:flash.layout]]. | * For some orientation with the file system and the whole directories, check [[docs:techref:flash.layout]]. |
| |
| At login you will be in your $HOME directory, which is ''/root'' for user root and would be ''/home/user1'' for user1, etc. Commands: | At login you will be in your $HOME directory, which is ''/root'' for user root and would be ''/home/user1'' for user1, etc. Commands: |
| |
| ^ Command ^ Memorize ^ Description ^^ | ^ Command ^ Memorize ^ Description ^^ |
| | ''pwd'' | //print working directory// | prints out the current directory you are in | | | ''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'' | | | ''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'' | | | ''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'' | | | ''cat'' | //concatenate// | print 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'' | | | ''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'' | | | ''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 [[docs:techref:flash.layout]] for understanding ''/rom'', etc. And see [[man>df]] for help with the command and it's options. Try ''df -h''. | | | ''df'' | //disk free// | Shows you available space. Again, see [[docs:techref:flash.layout]] for understanding ''/rom'', etc. And see [[man>df]] for help with the command and it's options. Try ''df -h''. | |
| | ''free'' | | about free RAM | | | ''free'' | | info about free RAM | |
| | ''uptime'' | | time elapsed since last boot | | | ''uptime'' | | time elapsed since last boot | |
| | ''dmesg'' | | print or control the kernel ring buffer | | | ''dmesg'' | | print or control the kernel ring buffer | |
| | ''logread'' | | Shows the messages from syslogd (using circular buffer) | | | ''logread'' | | Shows the messages from syslogd (using circular buffer) | |
| |<code sh>cat /proc/version</code> | | | | | ''cat /proc/version'' | | | |
| |<code sh>cat /proc/meminfo</code> | | more detailed data uppon RAM usage | | | ''cat /proc/meminfo'' | | more detailed info about RAM usage | |
| |<code sh>cat /proc/cpuinfo</code> | | about your CPU | | | ''cat /proc/cpuinfo'' | | info about your CPU | |
| |<code sh>cat /proc/mtd</code> | | | | | ''cat /proc/mtd'' | | | |
| |<code sh>cat /proc/partitions</code>| | | | | ''cat /proc/partitions'' | | | |
| |<code sh>cat /proc/net/nf_conntrack</code>| | | | | ''cat /proc/net/nf_conntrack'' | | | |
| |<code sh>cat /proc/cmdline</code> | | | | | ''cat /proc/cmdline'' | | | |
| |<code sh>cat /proc/modules</code> | | | | | ''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 [[https://man.cx/]]. Man pages are in the process of being translated. |
| |
| 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 [[https://kb.mozillazine.org/Using_keyword_searches|keywords]] to simplify the usage. Create a new bookmark, use ''https://man.cx/?page=%s'' as address and ''man'' as keyword. |
| |
| **''Tip''** In firefox, you can use [[http://kb.mozillazine.org/Using_keyword_searches|keywords]] to simplify the usage. Create a new bookmark, use ''%%http://man.cx/?page=%s%%'' as address and ''man'' as keyword. | ===== Editing files ===== |
| | |
| | |
| ===== editing files ===== | |
| To edit a file you need an editor, to edit a text file, you would use a text editor. | To edit a file you need an editor, to edit a text file, you would use a text editor. |
| |
| * ''vi'' starts out in command mode | * ''vi'' starts out in command mode |
| |
| === starting vi === | === Starting vi === |
| Start with ''vi'' or ''vi /etc/config/network'' or ''vi firewall.user'' if you are already in the same directory. | Start with ''vi'' or ''vi /etc/config/network'' or ''vi firewall.user'' if you are already in the same directory. |
| |
| === editing === | === Editing === |
| In order to edit the file, you have to be in //insert mode//. Press [i] or [a]. | In order to edit the file, you have to be in //insert mode//. Press [i] or [a]. |
| |
| === exiting vi === | === Exiting vi === |
| 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: | 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 | * '':w'' to write the current file to disc, this will overwrite the old file |
| * '':%s/string1/string2/g'' replace string1 with string2 in the whole file | * '':%s/string1/string2/g'' replace string1 with string2 in the whole file |
| |
| === configuring vi === | === Configuring vi === |
| Vi can be configured in //command mode// by setting certain variables: | Vi can be configured in //command mode// by setting certain variables: |
| * '':set ai'' use auto indentation (sometimes annoying default) | * '':set ai'' use auto indentation (sometimes annoying default) |
| * '':set noai'' NO auto indentation | * '':set noai'' NO auto indentation |
| |
| === alternative text editors === | === Alternative text editors === |
| If you do not like ''vi'', try ''joe'', ''mg'', ''nano'', ''vim'', ''vim-full'', ''vim-help'', ''vim-runtime'', ''zile'' | If you do not like ''vi'', try ''joe'', ''mg'', ''nano'', ''vim'', ''vim-full'', ''vim-help'', ''vim-runtime'', ''zile'' |
| * ''[[wp>Vim (text editor)|vim]]'' | * ''[[wp>Vim (text editor)|vim]]'' |
| |
| ===== Scripting language ===== | ===== Scripting language ===== |
| OpenWrt uses [[http://www.busybox.net/BusyBox.html | busybox's]] ash shell by default, which is in most parts //[[wp>POSIX]]// conform. Visit //[[wp>shell script]]// for general Information about shell scripts. | OpenWrt uses [[https://www.busybox.net/BusyBox.html | busybox's]] ash shell by default, which is in most parts //[[wp>POSIX]]// compliant. Visit //[[wp>shell script]]// for general information about shell scripts. |
| |
| ===== Executing shell scripts ===== | ===== Executing shell scripts ===== |
| After changing the executable bit its also possible to run it without the sh in front: | After changing the executable bit its also possible to run it without the sh in front: |
| |
| ''chmod +x /path/to/script.sh | <code> |
| /path/to/script.sh'' | chmod +x /path/to/script.sh |
| | /path/to/script.sh |
| | </code> |
| |
| | ===== Profile customization ===== |
| | User profile customization example. |
| |
| ===== File Managers ===== | <code bash> |
| | # Configure profile |
| | mkdir -p /etc/profile.d |
| | cat << "EOF" > /etc/profile.d/custom.sh |
| | export EDITOR="nano" |
| | export PAGER="less" |
| | alias diff="diff --color=auto" |
| | alias grep="grep --color=auto" |
| | alias ip="ip -color=auto" |
| | EOF |
| | . /etc/profile |
| | </code> |
| | |
| | ===== File managers ===== |
| You may also want to try ''[[wp>Midnight Commander|mc]]'' or ''[[wp>Demos Commander|deco]]''. | You may also want to try ''[[wp>Midnight Commander|mc]]'' or ''[[wp>Demos Commander|deco]]''. |
| |
| |
| |
| ===== Use GUIs ===== | ===== Use GUIs ===== |
| |
| ===== Further Help ===== | ===== Further Help ===== |
| * [[http://wiki.debian.org/CommandLineInterface]] | * [[https://wiki.debian.org/CommandLineInterface]] |
| | * [[http://linuxcommand.org/tlcl.php]] ---- William Shotts free pdf books starting from terminal basics |
| |