0% found this document useful (0 votes)
16 views21 pages

h1 ENG B Terminal

The document provides instructions on using the terminal to issue commands, list files, and access command information. It explains how to write, compile, and run a simple C program using gedit and the GNU C Compiler, as well as how to manage compilation warnings and change the compiled program's name. Additionally, it covers modifying the system PATH variable to run programs without specifying their directory and making these changes permanent.

Uploaded by

fgonen076
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views21 pages

h1 ENG B Terminal

The document provides instructions on using the terminal to issue commands, list files, and access command information. It explains how to write, compile, and run a simple C program using gedit and the GNU C Compiler, as well as how to manage compilation warnings and change the compiled program's name. Additionally, it covers modifying the system PATH variable to run programs without specifying their directory and making these changes permanent.

Uploaded by

fgonen076
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Terminal

• We can issue commands to the operating system


using the terminal screen, also called the shell.
• We can use Ctrl + Alt + T or program search menu to
open the terminal screen.
Terminal
• If we run the ls command from the terminal
screen, we can list the files in the active folder.
Terminal
• If we want to have information about a
command we use on the terminal screen, we
can use the man command.
Terminal
• For example, if we use the -a option with ls.
We can also view the records starting with.
Terminal

ls -la
gedit
• gedit is an editor that comes built on ubuntu. We will
use it when writing the C code.
Example program in C
• Using the editor, a simple program can be written as
follows.
• The program will only print a message on the screen.
Compiling the program
• After saving the app1.c file, let's compile it using
GNU C Compiler.
• First of all, let's change the directory we are in to be
the folder where the apps1.c file is located.
• After typing gcc as below, if we run by specifying the filename,
our file will be compiled.
• The warnings that arise as a result of the compilation are
about the construction of the libraries that we did not add.
Compiling the program
• If we type ls again from the command window
and look at the files in the folder, a file named
a.out is created as a result of the compilation.
Running the program
• If we write ./a.out on the command line, the
program works as expected and prints a
message on the screen.
Removing compilation warnings
• To remove the compilation warnings, let's add
the stdio.h library, which provides the printf
function to the program, and make the return
type of the main function int.
Changing the compiled program name
• To change the name of the program we
compiled, the –o option is used as follows:
• gcc test.c -o programname
PATH variable
• When running the program, the compiled program
that we write in front of the compiled file prevents it
from being confused with the programs in the
system path.

• If we want to run the program without using ./, we


need to add the directory /folder containing the
compiled code to the system path.
PATH

We can print the PATH variable with the echo command


to see the directories in the system path.
PATH variable
• We can use pwd (print working directory) command
to see the path of the directory we are in.

• Bu yolu kopyalayıp sistem yoluna ekleyebiliriz.


PATH variable
• Instead of writing the path, we can add the
active directory to the system path directly
with the pwd command.
PATH
• When we add the program to the system
path, we can write and run it directly without
using ./.
PATH
• Our changes are lost when we close and open
the terminal window.
• We can use the ~ / .bashrc file to be
permanent.
• From the command line: gedit ~ / .bashrc
PATH
• It should be noted that the programs in the
folders we add to the system path and the
programs in the other folder should not have
the same name.
• For example, let's compile the program we are
evaluating by giving the test name instead of
uyg1.
whereis
• In this case, the program in another folder
runs instead of our program.

You might also like