Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
docs:guide-user:base-system:user.beginner.cli [2019/03/14 15:46] – [Network] use internal link vgaeteradocs:guide-user:base-system:user.beginner.cli [2021/03/16 02:11] – [Profile customization] comment vgaetera
Line 1: Line 1:
 ====== 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**.
  
Line 5: Line 7:
  
 ===== 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:techref: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 =====
Line 21: Line 22:
 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.
  
-  * [[docs:guide-quick-start:sshadministration]]+  * [[docs:guide-quick-start:sshadministration|SSH Access for Newcomers]]
  
 ===== Configuration ===== ===== Configuration =====
Line 30: Line 31:
   * 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 [[https://man.cx/]]. Man pages are in the process of being translated.
Line 68: Line 67:
 **''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 [[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.
  
- +===== 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.
  
Line 78: Line 76:
   * ''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
Line 91: Line 89:
   * '':%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]]''
Line 108: Line 106:
  
 ===== Scripting language ===== ===== Scripting language =====
-OpenWrt uses [[https://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 =====
Line 122: Line 120:
 </code> </code>
  
 +===== Profile customization =====
 +User profile customization example.
  
-===== File Managers ===== +<code bash> 
-You may also want to try ''[[wp>Midnight Commander|mc]]'' or ''[[wp>Demos Commander|deco]]''+# 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]]''.
  
 ===== Use GUIs ===== ===== Use GUIs =====
  • Last modified: 2021/09/09 02:29
  • by vgaetera