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

    Einmal editiert, zuletzt von 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.

    Code
    cp -r /home/user1/folder /home/user2/

    works the same as

    Code
    cp /home/user1/folder /home/user2/ -r


    You can lookup the helpfile for most commands via

    Code
    command --help

    or

    Code
    command -h

    or you can open a full guide for each command, called manpage, via

    Code
    man command


    Debian Cheatsheets: Link #1 Link #2



    • Change directory
    Code
    cd

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

    Code
    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

    Code
    cd ..


    • List files / folders
    Code
    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
    Code
    cp

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

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


    • Move files
    Code
    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.

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


    • Delete files / folders
    Code
    rm

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


    Code
    rm filename

    or

    Code
    rm /home/user1/filename

    If you want to delete folders you need to either use the recursive option "-r" or use the rmdir command.


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

  • 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

    Code
    /

    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.

    Code
    .bash_rc

    in your home directory.


    • Access your home directory

    The home directory of your user can be accessed via

    Code
    cd ~


    • List all files of root filesystem




    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

  • 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

    Code
    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:



    Your output may differ from the ouput above because of different kernel versions.

  • 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

    Code
    /etc/init.d/program [start|stop|restart|...]

    You can also use the command service command

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



    Thanks Davidh2k for the Guide!

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!