• Home
  • Docker
  • Kubernetes
  • LLMs
  • Java
  • Ubuntu
  • Maven
  • Big Data
  • Archived
Linux-Ubuntu | Shell
  1. Shell
  2. Shell Environment
  3. Terminal Windows
  4. Shell Commands
  5. Shell Commands Syntax
  6. Edit Command Line
  7. Expand Commands
  8. Execute commands on remote system over SSH

  1. Shell
    Shell is the program that interpret and execute commands you type as command lines (CLI) or you write in a file (shell script).
    It automatically starts when you connect to a Linux console or you open a graphical terminal.

    The default shell on some systems is the Bash shell (bash).

    You can check the shell you are using:

    You can check the default shell associated with a specific user:

    There are other shells that can be available on your system:

    For some shells you can restrict some features that they provide by executing them in a restricted mode.
  2. Shell Environment
    The following configuration files contains settings that are applied when the user log in or open a shell session.
    • /etc/profile: This file is executed when the user log in. It executes the shell script /etc/bash.bashrc and any other shell scripts *.sh that can be found under the directory /etc/profile.d/.

    • ${HOME}/.bashrc: This file is specific to each user and set the shell environment when the user log in or open a bash shell. It defines the user environment variables and aliases. It might also execute the shell script ${HOME}/.bash_aliases where the user can define its own custom aliases.

    You can print the shell environment variables by using the command env:
  3. Terminal Windows
    You can access the shell interface by using a Terminal Window, Virtual Console, or Shell Prompt.

    • Terminal Window: A terminal window (emulator program) can be launched from your desktop GUI.

    • Virtual Console: From your desktop interface (GUI virtual console), you can switch to a virtual console by using key shortcuts: Ctrl+Alt+F1 (or F2, F3, ..., F6). F1 refer the GUI virtual console. When you access a virtual console you will see a login prompt. When you log in you will get a new shell session.

    • Shell Prompt: The shell prompt is available in systems that don't have a GUI. When you log in to your system you will see a shell prompt.

    When you access a shell interface you should see a prompt with dollar $ sign (regular user) or pound sign (root user):
  4. Shell Commands
    A command can be an alias, or a built-in shell command (echo, exit, ...), or a regular command in your filesystem.

    The commands in the filesystem can be found by looking at the paths defined in the environment variable $PATH.

    To locate a command you can use the type command.

    You can also use the which command to find the pathnames of a command.
    And you can use the locate command to search for files that the name match the provided command name.
  5. Shell Commands Syntax
    To execute a command, you only have to type its name.

    A command can have multiple options and arguments.

    An option is identified by a single character or a word.
    When specifying an option for a command, it should be preceded by a single hyphen (-) if it's referenced by a character
    Or double hyphen (--) if it's referenced by a word.

    You can group multiple options together using a single hyphen if they are referenced by a character or you can have each option specified separately using the single hyphen.
    In case where the option is referenced by a word, then each option should be specified separately using double hyphen.

    An option can have its own argument. The argument should follow the option.
    If the option is referenced by a character, then the argument should be separated form the option by a space.
    If the option is referenced by a word, then the argument should be separated form the option by the equal sign (=).

    You can specify multiple arguments for the command by placing them after the options.
  6. Edit Command Line
    While typing a command line, you can use some key shortcuts to edit the text of the command line and move the text cursor forward and backward.

    To edit the text of a command line, use the following key shortcuts:
    • Backspace: delete the previous character.

    • Ctrl+D: delete the current character.

    • Alt+C: change to uppercase the first character and to lowercase the remaining characters of the current word.

    • Alt+U: convert the current word to uppercase.

    • Alt+L: convert the current word to lowercase.

    To cut and paste the text of a command line, use the following key shortcuts:
    • Ctrl+K: cut the text on the right of the cursor (to the end of the line).

    • Ctrl+u: cut the text on the left of the cursor (to the beginning of the line).

    • Ctrl+w: cut the word on the left of the cursor.

    • Alt+d: cut the word on the right of the cursor.

    • Ctrl+y: paste the last cut text.

    To move the text cursor forward and backward, use the following key shortcuts:
    • Right Arrow, Ctrl+f: move the text cursor forward one character.

    • Left Arrow, Ctrl+b: move the text cursor backward one character.

    • Alt+f: move the text cursor forward one word.

    • Alt+b: move the text cursor backward one word.

    • Ctrl+a: move the text cursor to the beginning of the line.

    • Ctrl+e: move the text cursor to the end of the line.

    To find a previously executed command line, use the following key shortcuts:
    • Up/Down Arrow: move forward and backward in the command line history.

    • Ctrl+r: search a string in the command line history (keep pressing the key shortcut to go through command lines that match the string).

    • Alt+p: search a string in the command line history (press Enter when you finish typing the string to see the last command line that match the string).
  7. Expands Commands
    You can have commands, arithmetic expressions, and variables within the command line that need to be interpreted before executing the command line.

    For variables, you can precede them with the dollar sign ($), so they are substituted by their values before executing the command line.

    For commands, you can use either the form $(command) or `command`, so they are substituted by their values before executing the command line.

    For arithmetic expressions, you can use the form $[arithmetic-expression], so they are substituted by their values before executing the command line.

    It's recommended that you surround the command to be expanded with double quotes to avoid issues when the value of the substituted command contains spaces.
  8. Execute commands on remote system over SSH
    You can use the remote shell (ssh, rsh) to execute shell commands as a specific user on a remote server.
    Here's an example using the the secure shell (ssh):

    Execute a single command:

    Wrap a space separated command within double quotes characters:

    Wrap a command within single quotes characters to avoid variable expansion:

    Wrap multiples commands within double quotes characters separated with semicolon characters:

    Execute a command with sudo (use the option -t to force pseudo terminal allocation):

    Execute a shell script:
© 2025  mtitek