Main Menu

search

You are here

Linux Commands: General notes

[last updated: 2021-02-10]
Linux Commands
-----

  • Linux commands are case-sensitive.
  • Every character matters - spaces included.
  • Commands shown here may start with a '$'. This is short-hand for your command line prompt, and should not be typed in as a character.
  • Filenames and directory names may NOT Contain spaces.
  • Some commands require root account permissions:
      If you are not logged in as a root user, you must preface your command with "sudo "
      If you want to log in as a root user, type: $ sudo su [though it is not recommended]
      The '$' which is the last character in your prompt, will change to a '#'.
      To return to standard (non-root) user status, type: # exit
  • The words 'folder' and 'directory' are used as equivalent/synonymous.
  • ----------------------------------------------------------------------------------------------

  • Executing Linux commands:
    • This page assumes you will be executing Linux commands from a Command Line Interpreter (CLI) (a terminal program) like LXTerminal (LXT - bundled with Raspbian).
      There are other ways to execute commands, but a terminal CLI is easy for beginners.
    • When LXT opens, it opens to your home directory.
      • You will see a prompt, which on my rPi system looks like this:
        pi@raspberry pi ~ $
        The first 'pi' signifies you, the user that is logged in.
        The '~' signifies that you are in your home directory.
        Note the last character in the prompt is '$'. This indicates the end of the prompt line.
        Commands that I have described on this page will be listed as eg. $ pwd: [description]. Neither the '$' nor the ':' at the end should be re-typed.
      • On my Dell Linux laptop, opening the terminal program gives this prompt:
        jay@jay-Precision-M4400 ~ $

      ----------------------------------------------------------------------------------------------

    • Executing Script files: (go to:) Script Files
      • You must preface the execution with "./", eg.
        $ ./[scriptFileName].sh
    • Some commands allow or require additional parameters. For example, the cd command to change directories requires that you specify the directory that you want to change to. Generally this will be indicated on this page as: $ cd [path/directory]: [description]
      OTOH, the "ls" (lower-case 'LS') command, if used without parameters, gives the contents of the current directory.
      However you could add a parameter of a directory pathname to list contents of any directory desired, eg:
      ls / will give contents of root directory; ls [directory name] will list contents of the named sub-directory of the current directory.

    ----------------------------------------------------------------------------------------------

  • General Programming Notes:
    • If you use a variable in a command, intending to reference its value,
      you must precede the variable name with a ' $ '
      $ str01="tmp" ... no $ needed, defining str01, not referencing its value
      $ echo $str01 ... $ needed, intending to echo the value of str01 to output
    • Re-direct the output of a command:
      $ ls > tmp.txt ... sends the output of "$ ls" to create a file named tmp.txt.
      If the file already exists, it will overwrite whatever's there with this new output.
    • If tmp.txt already exists, and you want to preserve its content and just add to it,
      then append this new output to the end of it with:
      $ ls >> tmp.txt
    • Re-direct the input to a command:
      $ sort < tmp.txt
      content of tmp.txt will be sent to sort, then the sorted output will be sent to screen.
    • Re-direct both input and output
      $ sort < tmp.txt > tmp1.txt
      sorted output sent to new file

    • Pipes:
      $ ls | less ... shows lts output a page at a time allowing scrolling
      $ ls | more ... shows its output a page at a time, but no scrolling allowed, must press enter to get next page
      $ ls | grep "file" ... sends ls output through grep filter, and only displays items containing "file"
      [Clearly this only describes a tiny fraction of a very complex and rich feature...]

    ----------------------------------------------------------------------------------------------

.

.

.

eof