Vous êtes sur la page 1sur 9

Praktikum Fisika Komputasi/ Dr. Artoto Arkundato / Dr.

Lutfi Rohman

7 September 2018

MODUL 2

Judul Praktikum:

Perintah-Perintah Dasar Linux, Instalasi C/C++, gfortran, Python dan Bahasan Pemrograman

Tujuan:

1. Menguasai perintah-perintah dasar CLI Linux di Terminal Linux

2. Menguasai Intalasi C/C++, gfortran dan python

3. Mempelajari pemrograman C/C++ di Linux

Tata Laksana Praktikum:

2.1 Perintah Dasar CLI Linux

-Ketikkan perintah-perintah berikut di Linux

-Catat/rekam hasil yang diperoleh dari eksekusi perintah tersebut di komputer Anda

List:

cat

Melihat isi file tanpa harus membuka file, dan menuliskan isi file dalam layar terminal $ cat nama_file (enter)

cd

Untuk mengubah/pindah ke suatu directory kerja

$ cd alamat_directory

pwd

Untuk melihat alamat directory kerja sekarang


$ pwd

clear

The clear command is used to clear the terminal screen.

$ clear

cp

The cp command is used for copying files and directories.

$ cp test.txt /home//himanshu/Desktop/

date

The date command can be used to print (or even set) the system date and time.

$ date

Tue Feb 28 17:14:57 IST 2017

echo

The echo command displays whatever input text is given to it.

$ echo hello hi

find

The find command lets you search for files in a directory as well as its sub-directories.

$ find test*

free

The free command displays the amount of free and used memory in the system.
$ free

total used free shared buffers cached

Mem: 1800032 1355288 444744 79440 9068 216236

-/+ buffers/cache: 1129984 670048

Swap: 1832956 995076 837880

gzip

The gzip command compresses the input file, replacing the file itself with one having a .gz extension.

$ gzip file1

gunzip

Files compressed with gzip command can be restored to their original form using the gunzip command.

$ gunzip file1.gz

history

The history command is used to display the history of commands that you typed in on the shell. It can be used to
record and replay commands too. To view the command history, run:

$ history

locate

The locate command helps user find a file by name.

$ locate [file-name]

ls

The ls command lists contents of a directory in output.

$ ls progress

lshw

The lshw command extracts and displays detailed information on the hardware configuration of the machine.
$ sudo lshw

lscpu

The lscpu command displays in output system's CPU architecture information (such as number of CPUs, threads,
cores, sockets, and more).

$ lscpu

mkdir

The mkdir command lets you create directories.

$ mkdir [dir-name]

mv

The mv command lets you either move a file from one directory to another, or rename it.

$ mv test.txt /home/himanshu/Desktop/

nano

The nano command in Linux launches the 'nano' editor. The editor is designed to emulate the features and
user-friendliness of the UW Pico text editor.

$ nano

nproc

The nproc command displays the number of processing units available to the current process.

$ nproc

passwd
The passwd command is used for changing passwords for user accounts.

$ passwd himanshu

Changing password for himanshu.

(current) UNIX password:

ping

The ping command is used to check whether or not a system is up and responding. It sends ICMP ECHO_REQUEST
to network hosts.

$ ping howtoforge.com

pwd

The pwd command displays the name of current/working directory.

$ pwd

$ rm [file-name]

rmdir

The rmdir command allows you delete empty directories.

$ rmdir [dir-name]

shutdown

The shutdown command lets user shut the system in a safe way.

$ shutdown

size

The size command lists the section sizes as well as the total size for an object or archive file.
$ size test

text data bss dec hex filename

1204 280 4 1488 5d0 test

watch

The watch command can be used to monitor a program's output. It runs the program repeatedly, displaying its
output and errors. For example:

$ watch date

wget

The wget command line tool in Linux lets you perform a non-interactive download of files from the Web.

Here's how you can use it:

wget [URL]

who

The who command shows who is logged on.

$ who

2.2 Install C/C++

1. Ketikan perintah di terminal:

$sudo apt-get install g++ (enter)

2. Atau jika ingin C++ yang ada GUI nya : install

$sudo apt-get install geany (enter)

2.3 Install gfortran

$sudo apt-get install gfortran

$sudo apt-get install f77


2.4 Install python

$sudo apt-get install python

2.5 Membuat program sederhana C/C++ dan MengCompile serta Run

2.5.1 Cara mengcompile:

Jika sourcecode program dalam C/C++ atau fortran disimpan dalam file dengan nama misal X.cpp atau X.f90 maka
kompilasinya dapat dengan dua cara:

A. Dari terminal

1. $g++ X.cpp -o X (opsional)

2. $gfortran X.f90 -o X (opsional)

Untuk menjalankan $./X (enter)

B. Dari GUI geany cukup di klik tombol compile>> build>> run

2.6 Untuk instalasi python dapat dipelajari materi di:

https://www.physics.rutgers.edu/grad/509/

Contoh program dalam bahasa C++:

Progam kalkulator:

1.Petunjuk: ketikan script program ini di editor geany atau di text editor Anda:

# include <iostream>using namespace std;

int main(){

char op;

float num1, num2;


cout << "Enter operator either + or - or * or /: ";

cin >> op;

cout << "Enter two operands: ";

cin >> num1 >> num2;

switch(op)

case '+':

cout << num1+num2;

break;

case '-':

cout << num1-num2;

break;

case '*':

cout << num1*num2;

break;

case '/':

cout << num1/num2;

break;

default:

// If the operator is other than +, -, * or /, error message is shown

cout << "Error! operator is not correct";

break;

}
return 0;}

2. Simpan dengan nama file X.cpp atau terserah menurut Anda.

3. Kompilasi dan jalankan

Tugas:

1. Buatlah program menghitung akar-akar persamaan kuadrat dalam bahasa C/C++ dari persamaan kuadrat:

ax2 +bx -c = 0

2. Buatlah laporan praktikum dari Modul 2 ini seperti format laporan sebelumnya

Vous aimerez peut-être aussi