Working with the CLI (CommandLineInterface)

    • core
    • Working with the CLI (CommandLineInterface)

      Description
      (commonly referred to as CLI, short for CommandLineInterface).

      With todays release the Guide is rather minimal. The goal on the outset is to aid the new Linux user in their use of Debian, and OMV. We will continually make updates and improvements to this Guide over time. In time the Guide will become more comprehensive and extend coverage towards more intermediate level subject matters.
      • Part 1: Basic commands
      • Part 2: Filesystem structure
      • Part 3: PuTTY, FireSSH, ChromeExtension "SecureShell" or ShellinaBox
      • Part 4: Daemons and Services

      If you have any questions / problems / suggestions, feel free to contribute in this thread:
      How to work with the Linux CLI

      OMV stoneburner | HP Microserver | 256GB Samsung 830 SSD for system | 4x 2TB in a RAID5
      OMV erasmus| Odroid XU4 | 5TB Data drive | 500GB Backup drive

      The post was edited 1 time, last by WastlJ ().

    • Part 1: Basic commands

      First thing you should know before starting with the CLI is that under Linux the user/administrator seperation is much bigger than on Windows Systems. On Linux you have one administrating account called root which is way more powerfull than an administrator account under Linux. The root account is more like the "system" account under windows. You need to use the root account for actions that may threaten your system. Because of that it is recommend to not use this account for running services and working with most parts of the system where root privileges are not needed.

      For everything you do under linux you have a command. Commands are short names for actions. Each command can have options e.g. "-r" for cp to copy files recursively.
      These options can be typed in directly after the command you use, or you can type it at the end of the full command. E.g.

      Source Code

      1. cp -r /home/user1/folder /home/user2/
      works the same as

      Source Code

      1. cp /home/user1/folder /home/user2/ -r

      You can lookup the helpfile for most commands via

      Source Code

      1. command --help
      or

      Source Code

      1. command -h
      or you can open a full guide for each command, called manpage, via

      Source Code

      1. man command

      Debian Cheatsheets: Link #1 Link #2


      • Change directory

      Source Code

      1. cd
      - If you want to change to a specific directory you need to use that command. e.g. change to the home directory via

      Source Code

      1. cd /home/user/
      See Part 2: Filesystem Structure for more information on how to navigate through the filesystem.
      If you want to go one folder upwards you would type

      Source Code

      1. cd ..

      • List files / folders

      Source Code

      1. ls
      - Lists the files in a specific directory. If you do not specify from which folder you want to list the file, it will show the files in the directory you're right now.
      Use it with "-l" to show it as a List which also shows the owner and the attributes of the files. "-a" also shows hidden files.
      e.g. "ls -la" shows the following when executed in "/root/" (which is the home folder of the root user!)

      • Copy files

      Source Code

      1. cp
      If you want to copy files from one location to another. E.g.

      Source Code

      1. cp /home/user1/textfile.txt /home/user2/


      • Move files

      Source Code

      1. mv
      If you not just want to copy a file but rather move it you use mv. If you want to move folders you need to use the recursive option "-r".
      You can also use mv to rename files. E.g.

      Source Code

      1. mv /home/user1/textfile.txt /home/user1/newtextfile.txt


      • Delete files / folders

      Source Code

      1. rm
      If you want to delete files you will use that command. E.g.

      Source Code

      1. rm filename
      or

      Source Code

      1. rm /home/user1/filename
      If you want to delete folders you need to either use the recursive option "-r" or use the rmdir command.

      Source Code

      1. rmdir
      Is used to delete directories. HOWEVER, be really carefull with this command, or the "-r" option for rm because when you execute it with root priviliges or the root account, you *could* remove your whole system.

      • Basic editor

      Source Code

      1. nano
      Basic editor. Trust me, it's the editor you want to use if you're unexperienced with the commandline. Vi, Vim, Joe or any other editor out there is not as simple to use as nano.
      You can edit without any trouble in this editor.
      You open files with "nano filename" or "nano /home/user1/filename" depending on where you're on the commandline in the moment. (See Part 2)
      You save files with CTRL+O and close files with CTRL+X.
      OMV stoneburner | HP Microserver | 256GB Samsung 830 SSD for system | 4x 2TB in a RAID5
      OMV erasmus| Odroid XU4 | 5TB Data drive | 500GB Backup drive
    • Part 2: Filesystem structure

      Under Linux the Filesystem structure is a little different from Windows. In Windows you have your drives called C:\ or D:\.
      In Linux the filesystem is collected under

      Source Code

      1. /
      All full paths start with this. Under "/" you'll find the home directory, the device directory, the var directory where logfiles are saved and many more directories.
      Hidden files begin with a dot. e.g.

      Source Code

      1. .bash_rc
      in your home directory.

      • Access your home directory
      The home directory of your user can be accessed via

      Source Code

      1. cd ~


      • List all files of root filesystem

      Source Code

      1. root@chap:~# ls -l /
      2. insgesamt 112
      3. drwxr-xr-x 2 root root 4096 17. Aug 16:19 bin
      4. drwxr-xr-x 3 root root 4096 3. Okt 17:22 boot
      5. drwxr-xr-x 17 root root 8340 27. Okt 19:58 dev
      6. drwxr-xr-x 130 root root 12288 27. Okt 19:58 etc
      7. drwxr-xr-x 5 root root 4096 23. Sep 15:34 export
      8. drwxr-xr-x 6 root root 4096 9. Okt 19:22 home
      9. lrwxrwxrwx 1 root root 36 17. Aug 16:14 initrd.img -> /boot/initrd.img-3.2.0-0.bpo.4-amd64
      10. lrwxrwxrwx 1 root root 30 28. Mär 2013 initrd.img.old -> boot/initrd.img-2.6.32-5-amd64
      11. drwxr-xr-x 14 root root 12288 17. Aug 16:36 lib
      12. drwxr-xr-x 4 root root 4096 14. Apr 2013 lib32
      13. lrwxrwxrwx 1 root root 4 28. Mär 2013 lib64 -> /lib
      14. drwx------ 2 root root 16384 28. Mär 2013 lost+found
      15. drwxr-xr-x 8 root root 4096 13. Okt 02:58 media
      16. drwxr-xr-x 3 root root 4096 17. Aug 16:36 mnt
      17. drwxr-xr-x 3 root root 4096 17. Aug 15:38 opt
      18. dr-xr-xr-x 174 root root 0 27. Okt 19:57 proc
      19. drwx------ 22 root root 4096 27. Okt 20:00 root
      20. drwxr-xr-x 2 root root 4096 17. Aug 16:18 sbin
      21. drwxr-xr-x 2 root root 4096 21. Jul 2010 selinux
      22. drwxr-xr-x 3 root root 4096 29. Mär 2013 srv
      23. drwxr-xr-x 13 root root 0 27. Okt 19:57 sys
      24. drwxrwxrwt 7 root root 4096 27. Okt 22:57 tmp
      25. drwxr-xr-x 11 root root 4096 28. Mär 2013 usr
      26. drwxr-xr-x 15 root root 4096 28. Aug 23:57 var
      27. lrwxrwxrwx 1 root root 32 17. Aug 16:14 vmlinuz -> boot/vmlinuz-3.2.0-0.bpo.4-amd64
      28. lrwxrwxrwx 1 root root 27 28. Mär 2013 vmlinuz.old -> boot/vmlinuz-2.6.32-5-amd64
      29. root@chap:~#
      Display All




      A root shell is identified by the hash key in root@NAS:~# - A user shell has a dollar sign instead david@NAS:~$

      In nearly any shell on Linux you can autocomplete paths. e.g. if you type the first two or three letters of a folder/file you can hit the tabulator key and the shell will complete the path for you. Get used to that feature as it eases the use of the command line.

      More detailed description of bash-completion on Wikipedia
      OMV stoneburner | HP Microserver | 256GB Samsung 830 SSD for system | 4x 2TB in a RAID5
      OMV erasmus| Odroid XU4 | 5TB Data drive | 500GB Backup drive
    • Part 3: PuTTY, FireSSH, ChromeExtension "SecureShell" or ShellinaBox

      If you're on Windows, you can use different tools to connect to your linux server via SSH.

      • FireSSH - free, cross-platform SSH terminal client for Mozilla Firefox
      • ChromeExtension: Secure Shell - terminal emulator and ssh client for Chrome
      • PuTTY - a free SSH and telnet client (standalone program) for Windows
      • ShellinaBox - OMV 3rd-party-Plugin , works only, if you are connected to the OMV-WebGUI

      ATTN: You need to enable SSH in the Service tab of the OMV Webinterface before you can use it.

      If you want to login with a user except than root you need to change the users shell (In the user management tab in the OMV Webinterface) to bash. You also need to add the user to the "ssh" group.

      FireSSH, SecureShell (Chrome) and ShellinaBox:
      Just type

      Source Code

      1. ssh IP_of_your_OMV
      to login to OMV on the CLI.

      PuTTY:
      When you've don the steps above you can start PuTTY and type in either the IP or the Hostname of your OMV System in the Host Name field. Leave Protocol to anything untouched (protocol should be SSH and Port shoud be 22). Then you may hit Open.


      General:

      When you connect the first time to a system you receive a warning. This warning tells you about the identy of the server, which is there to verify the identy of the server you're connecting to. You can accept it permanently by clicking/typing yes.

      Now you're asked for the username you want to login with. Either chose the root account or if you setup another user you may use this one. After that you're asked for the password. Caution: You won't get any echo from typing in your password, however, you are typing! This is a security feature of both PuTTY and Linux itself to prevent your password length to be spyed from other people.

      The Output then should look like this:

      Source Code

      1. login as: root
      2. root@chap's password:
      3. Linux chap 3.2.0-0.bpo.4-amd64 #1 SMP Debian 3.2.46-1+deb7u1~bpo60+1 x86_64
      4. The programs included with the Debian GNU/Linux system are free software;
      5. the exact distribution terms for each program are described in the
      6. individual files in /usr/share/doc/*/copyright.
      7. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
      8. permitted by applicable law.
      9. Last login: Sun Oct 27 20:00:49 2013 from gaming.local
      10. root@chap:~#
      Display All


      Your output may differ from the ouput above because of different kernel versions.
      OMV stoneburner | HP Microserver | 256GB Samsung 830 SSD for system | 4x 2TB in a RAID5
      OMV erasmus| Odroid XU4 | 5TB Data drive | 500GB Backup drive
    • Part 4: Daemons and Services

      Daemons and services are located in /etc/
      The startscripts are for the individual services are located in /etc/init.d/

      Under Debian you can manage programs in two ways. Either you use theire startscripts with

      Source Code

      1. /etc/init.d/program [start|stop|restart|...]
      You can also use the command service command

      Source Code

      1. service program [start|stop|restart|...]



      Thanks Davidh2k for the Guide!
      OMV stoneburner | HP Microserver | 256GB Samsung 830 SSD for system | 4x 2TB in a RAID5
      OMV erasmus| Odroid XU4 | 5TB Data drive | 500GB Backup drive