Main Menu

search

You are here

Linux: Executing Commands:

[last updated: 2021-07-05]
go to: Linux Home page
-----

Excute Linux Commands:

  • You can execute commands using a script

  • Or you can use a command line interpreter (CLI) like LX Terminal.
    • LXT is bundled with Raspbian and can be opened by clicking its icon on the GUI home screen, or by clicking: start menu (bottom left corner of main screen - depending on version...) > Accessories > LXTerminal.
    • LXTerminal acts like a rudimentary file manager, allowing you to see what files are located in whatever directory. But instead of more advanced file managers that allow clicking and dragging etc, you must tell (by typing in text) the LXT program every action you want it to take.
    • When LXT opens, it opens to your home directory. You will see a prompt, which on my system looks like this:
      pi['at' symbol]raspberry pi ~ $
      the '~' signifies your home directory.
      if from here you type in: pwd (print working/current directory), it will tell you that your home is (at least on my system) "/home/pi".
      The left-most "/" signifies your root directory, the top-most directory in your SD card memory.
    • From LXT command line you can also execute Linux commands to run programs
      • It can happen that some programs (commands) require the user to have root privilege. There are ways to log on as a root user, but for me, I invoke root privilege by prefacing those commands that require it with 'sudo'.
        • So for example if I want to execute a python program (which requires root privilege), I would type (not including the '$' which is just short-hand for whatever the prompt is):
          $ sudo python myPythonProgram.py
          (note python programs have a .py extension.)
        • If you want to execute a python (or any other) program that is located in a different directory than your current directory, the syntax would be:
          $ sudo python [path]/[programName].py
          where '[path]', if it is in reference to your root directory, would start with a '/'
          if OTOH '[path]' is a sub-sub directory to your current directory, you would not include the first '/'.
    • Dot-Slash:
      To run a compiled program in your current directory, execute:
      $ ./[progName]


.

.

.

eof