Executing program in linux

How to Run a Program in Linux?

Linux is an effective distribution to perform certain tasks through the command line, i.e., installing, updating, removing, etc. A Linux program can be run through the terminal and GUI(if available). Numerous program types require different ways to run them. This guide will teach you how to run the program using the GUI and Command Line Interface (CLI).

This post will cover the below informative topics:

  • Method 1: How to Run a Linux Program Using GUI?
  • Method 2: How to Run a Linux Program Using Terminal?
  • Method 3: How to Run a Program Using a Text-Based Command Dialogue Box?
  • Method 4: How to Run a Linux Program Using Customized Keyboard Shortcuts?
  • Additional Tip: Make File Executable Before Running a Program

Method 1: How to Run a Linux Program Using GUI?

Most beginners are used to running a program via GUI, as in Windows or macOS. The easiest way to run a program in Linux is using the GUI approach, which is the same as in Windows or macOS. To run a program in Linux using GUI, you can follow the below-given few steps (as an example, Google Chrome is being opened):

Navigate to the dock panel on the Left side of the screen and click on “Shown Applications” or press the Super key (Windows key) + A to launch the applications menu. A search bar will appear in the applications menu, enter the desired program and click its icon to run it.

Note: Ensure that the Linux program is installed on your system.

Method 2: How to Run a Linux Program Using Terminal?

The Linux default shell terminal is the most popular and used tool to run a program. The terminal is a command-line interpreter that takes the arguments as commands and performs that function. To run google chrome using the terminal, press “CTRL + ALT + T” to open the terminal and enter the desired program name to run it.

For instance, to run google chrome using the terminal, enter the name in the terminal, as shown below:

Читайте также:  Посмотреть сколько памяти занято linux

After pressing the “enter” key, the program will be launched:

Note: The program name is defined by the package provider, so make sure you are using the correct keywords to run it.

Method 3: How to Run a Program Using a Text-Based Command Dialogue Box?

Another way to run a Linux program is by using the default run command by simply clicking the “Alt + F2” or “FN + Alt + F2” keys. The run command is built-in Linux distribution to run the programs directly; for instance, to run “Google Chrome” using the run command, you need to perform below easy steps:

Press the “Alt + F2” shortcut keys to open the run command search box and enter the desired program (in this case, google-chrome) and press “Enter” to run:

Pressing the “Enter” key which will run the process and open the “ Google Chrome” browser:

Method 4: How to Run a Linux Program Using Customized Keyboard Shortcuts?

There are several built-in shortcuts that you can utilize to run the programs, but if you want to run a program with your desired shortcut keys, you can set it up.

To set up the desired shortcut keys to perform a specific task, follow the below steps:

Press Windows Key + A to open the applications menu or Click on “Show Application” from the Dock panel to launch the applications menu. Enter the “shortcut” in the search and click on the keyboard shortcuts icon:

Clicking on the Keyboard shortcut will open up the below interface; click on the “View and Customize Shortcuts”:

The system shortcut keys list will open up, now click on “Custom Shortcuts”:

It will open up a window to set desired shortcut keys for running a specific program. Press the “Add Shortcut” button to create the desired shortcut:

Set the name & command related to that program and press the “Set Shortcut…”:

Note: For instance, the command in the case of Google Chrome is “google-chrome”.

The below dialog window will open up to set the shortcut; press the desired keys who want to set the shortcut:

After pressing the keys (in this case, Ctrl + G), the keys will appear in front of the shortcut. Click the “Add” button to set the shortcut keys:

The shortcut key (Ctrl + G) is added to run Google Chrome. Now, navigate to the home screen and press the “Ctrl + G” to launch Google Chrome:

Additional Tip: Make File Executable Before Running a Program

Before running any program, make sure the program is executable. To make a program executable using GUI, the following basic changes are made:

Читайте также:  Как пользоваться clamav linux

Select the specified program file, right-click to open options, and press the shortcut keys “Ctrl + l” or click the “Properties” option to open file settings:

Move to the “Permissions” tab and check the “Allow executing file as program” option to make the file executable:

Now, you can run the program as done in previous sections.

Similarly, to make the file executable using the terminal, run the following command:

The program is executable and can be run using the terminal.

Conclusion

In Linux, a program can be run using different methods, including GUI, terminal, run command, and custom shortcut keys. Before running a program, ensure that the program is available on the system and is executable. This post has demonstrated multiple methods to run a Program in Linux.

Источник

How to Write, Compile and Run a C Program in Ubuntu and Other Linux Distributions [Beginner’s Tip]

Running C program in Linux command line is not that difficult. Running it in a code editor like Visual Studio Code is even easier. Learn both methods.

How do you program in C on Linux? It is indeed very easy and consists of three simple steps. Step 1: Write your program and save the file with a .c extension. For example, my_program.c. Step 2: You compile the program and generate the object file using gcc compiler in a terminal like this:

gcc -o my_program my_program.c

Running a C Program in Linux using gcc

This was just a quick summary of how to compile and run a C program in Linux. If you are new to either C or Linux, I’ll show these steps in detail to make you comfortable coding C programs in a Linux environment. I’ll discuss how to run C programs in a Linux terminal and a code editor.

Method 1: How to run C programs in a Linux terminal

In order to run a C program in Linux, you need to have a C compiler present on your systems. The most popular compiler is gcc (GNU Compiler Collection). You can install gcc using your distribution package manager. In Debian and Ubuntu-based Linux distributions, use the apt command:

Switch to the directory where you have kept your C program (or provide the path) and then generate the object file by compiling the program:

gcc -o my_program my_program.c

Keep in mind that it is optional to provide the output object file (-o my_program). If you won’t do that, an object file named a.out will be automatically generated. But this is not good because it will be overwritten for each C program and you won’t be able to know which program the a.out object file belongs to. Once your object file is generated, run it to run the C program. It is already executable. Simply use it like this:

Читайте также:  Посмотреть скорость интернета linux

And it will display the desired output if your program is correct. As you can see, this is not very different from running C++ programs in Linux.

Every time you make a change in your program, you have to compile it first and then run the generated object file to run the C program.

Method 2: How to run C programs in Linux using a code editor like Visual Studio Code

C program editing in Visual Studio Code

Not everyone is comfortable with the command line and terminal and I totally understand that. You can use a proper C/C++ IDE like Eclipse or Code Blocks but they are often too heavy programs and more suitable for large projects. I recommend using an open-source code editor like Visual Studio Code or Atom. These are basically text editors and you can install add-ons to compile and run programs directly from the graphical code editor. I am using Visual Studio Code editor in this example. It’s a hugely popular open-source code editor from Microsoft. First thing first, install Visual Studio Code in Ubuntu from the software centre. For other distributions, please check your Linux distribution’s package manager or software centre. You may also check the official website for more information. Start Visual Studio Code and open/create a project and create your C program here. I am using a sample Hello World program. You must ensure the gcc compiler is installed on your Linux system.

Next, you would want to use an extension that allows you to run the C code. Microsoft may prompt you for installing its own extension for the C/C++ programs but it is complicated to set up and hence I won’t recommend it. Instead, I suggest using the Code Runner extension. It’s a no-nonsense extension and you can run C and C++ code easily without additional configuration. Go to the Extensions tab, search for ‘Code Runner,’ and install it. Installing Code Runner extension in Visual Studio CodeRestart Visual Studio Code. Now, you should be able to run the C code by using one of the following ways:

  • Using the shortcut Ctrl+Alt+N.
  • Press F1 and then select or type Run Code.
  • Right-click the text editor and click Run code from the context menu.

Right -click the program file that you want to run and then press

When you run the program, it is compiled automatically and then run. You can see the output in the terminal that is opened at the bottom of the editor. What could be better than this?

Program output is displayed in the bottom section of the Visual Studio Code editor

Which method do you prefer?

If you prefer a video to learn about installing and running C programs in Linx, check out the below Video tutorial.

Источник

Оцените статью
Adblock
detector