CENG393 Computer Networks Labwork 1

Similar documents
CENG 334 Computer Networks. Laboratory I Linux Tutorial

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Introduction to Linux

Introduction to Linux

Introduction: What is Unix?

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...

Linux Shell Script. J. K. Mandal

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

Introduction to Linux Workshop 1

EECS Software Tools. Lab 2 Tutorial: Introduction to UNIX/Linux. Tilemachos Pechlivanoglou

Linux Operating System Environment Computadors Grau en Ciència i Enginyeria de Dades Q2

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

Practical Session 0 Introduction to Linux

When talking about how to launch commands and other things that is to be typed into the terminal, the following syntax is used:

A Brief Introduction to the Linux Shell for Data Science

Introduction to the UNIX command line

Introduction to Linux (Part I) BUPT/QMUL 2018/03/14

Using UNIX. -rwxr--r-- 1 root sys Sep 5 14:15 good_program

Lab 1 Introduction to UNIX and C

CSC209. Software Tools and Systems Programming.

The Unix Shell & Shell Scripts

Introduction to Linux

Intro to Linux. this will open up a new terminal window for you is super convenient on the computers in the lab

Exercise 1: Basic Tools

Overview LEARN. History of Linux Linux Architecture Linux File System Linux Access Linux Commands File Permission Editors Conclusion and Questions

Introduction of Linux

Exploring UNIX: Session 3

This lab exercise is to be submitted at the end of the lab session! passwd [That is the command to change your current password to a new one]

Carnegie Mellon. Linux Boot Camp. Jack, Matthew, Nishad, Stanley 6 Sep 2016

Introduction to Linux

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

Essential Linux Shell Commands

History. Terminology. Opening a Terminal. Introduction to the Unix command line GNOME

Lecture 3. Unix. Question? b. The world s best restaurant. c. Being in the top three happiest countries in the world.

Computer Systems and Architecture

CS Fundamentals of Programming II Fall Very Basic UNIX

Open up a terminal, make sure you are in your home directory, and run the command.

Introduction to the Linux Command Line

Tutorial 1: Unix Basics

Lab 1 1 Due Wed., 2 Sept. 2015

CS246 Spring14 Programming Paradigm Notes on Linux

Laboratory 1 Semester 1 11/12

Linux Training. for New Users of Cluster. Georgia Advanced Computing Resource Center University of Georgia Suchitra Pakala

CISC 220 fall 2011, set 1: Linux basics

EE516: Embedded Software Project 1. Setting Up Environment for Projects

Introduction to Linux for BlueBEAR. January

Using LINUX a BCMB/CHEM 8190 Tutorial Updated (1/17/12)

Helsinki 19 Jan Practical course in genome bioinformatics DAY 0

1. What statistic did the wc -l command show? (do man wc to get the answer) A. The number of bytes B. The number of lines C. The number of words

Parallel Programming Pre-Assignment. Setting up the Software Environment

LAB #7 Linux Tutorial

Chapter-3. Introduction to Unix: Fundamental Commands

Hands-on Keyboard: Cyber Experiments for Strategists and Policy Makers

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

Files and Directories

Introduction to Linux

Introduction to the basics of UNIX

Introduction to Linux Basics

Lecture 1. A. Sahu and S. V. Rao. Indian Institute of Technology Guwahati

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

CS CS Tutorial 2 2 Winter 2018

Introduction to remote command line Linux. Research Computing Team University of Birmingham

Lab 3a Using the vi editor

Operating Systems. Copyleft 2005, Binnur Kurt

Linux Essentials. Programming and Data Structures Lab M Tech CS First Year, First Semester

Operating Systems 3. Operating Systems. Content. What is an Operating System? What is an Operating System? Resource Abstraction and Sharing

Getting Started With UNIX Lab Exercises

Working with Basic Linux. Daniel Balagué

Session 1: Accessing MUGrid and Command Line Basics

Open Source Computational Fluid Dynamics

Exercise Sheet 2. (Classifications of Operating Systems)

Introduction to Unix The Windows User perspective. Wes Frisby Kyle Horne Todd Johansen

Introduction to Linux Part 1. Anita Orendt and Wim Cardoen Center for High Performance Computing 24 May 2017

CSCI 2132 Software Development. Lecture 4: Files and Directories

Week 2. Exp 2 (a) (b): Introduction to LINUX OS, Installation of LINUX OS, Basic DOS commands

Introduction to Linux

Unix L555. Dept. of Linguistics, Indiana University Fall Unix. Unix. Directories. Files. Useful Commands. Permissions. tar.

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

Programming and Data Structure Laboratory (CS13002)

Basic Unix Commands. CGS 3460, Lecture 6 Jan 23, 2006 Zhen Yang

CSC111 Computer Science II

Using the Zoo Workstations

DEPARTMENT OF MATHEMATICS. RAMLab User Guide. An Introduction to the Ryerson Applied Mathematics Laboratory

Introduction to Unix: Fundamental Commands

Welcome to getting started with Ubuntu Server. This System Administrator Manual. guide to be simple to follow, with step by step instructions

Introduction to Supercomputing

CSE Linux VM. For Microsoft Windows. Based on opensuse Leap 42.2

Unix Introduction to UNIX

Unix basics exercise MBV-INFX410

Mills HPC Tutorial Series. Linux Basics I

CSE 391 Lecture 1. introduction to Linux/Unix environment

CSC209. Software Tools and Systems Programming.

GNU/Linux 101. Casey McLaughlin. Research Computing Center Spring Workshop Series 2018

CSE 390a Lecture 1. introduction to Linux/Unix environment

Basic UNIX Commands BASIC UNIX COMMANDS. 1. cat command. This command is used to create a file in unix. Syntax: $ cat filename

Commands are in black

CHAPTER 1 UNIX FOR NONPROGRAMMERS

Chap2: Operating-System Structures

CSE 391 Lecture 1. introduction to Linux/Unix environment

CSE 303 Lecture 2. Introduction to bash shell. read Linux Pocket Guide pp , 58-59, 60, 65-70, 71-72, 77-80

Transcription:

CENG393 Computer Networks Labwork 1 Linux is the common name given to a large family of operating systems. All Linux-based operating systems are essentially a large set of computer software that are bound together. The most essential piece of these operating systems is the Linux kernel. A large variety of software may be installed and run on this kernel, including web browsers, text editors, multimedia players, games; or more specialized software such as scientific tools, web and database servers, etc. As of 2017, there are over 100 different Linux-based operating systems. Ubuntu, Mint, Debian, Open- SUSE, Fedora are only a few of the most popular ones. The differences between all these operating systems are usually in terms of the user interface or how the operating system handles the background tasks. For example Kubuntu is different from Ubuntu only in terms of user interface and the default set of programs bundled with them; but all the other parts (Linux kernel, system services, etc) are exactly the same and common operations can be performed in a similar manner in both operating systems. Figure 1: Ubuntu and Kubuntu desktops We will be using Kubuntu operating system in our university laboratories but you are free to install any Linux-based operating system on your own computers. Ubuntu is recommended for beginners because of its popularity and it has a large resource of information on the web. 1 Introduction to Command Line Interface The aim of this manual is to get you acquainted with the Command Line Interface of Linux systems. The Command Line Interface (CLI) is a powerful tool for performing various tasks on the system. Basically you enter a command from keyboard (which tells the computer to do something) and the computer executes your command, maybe interacting with you by displaying output or asking for additional input. When the command finishes executing, the system waits for another command from the user. 1

In Kubuntu, the Command Line Interface can be accessed by Konsole application. You may open this application by opening the application menu on the bottom-left corner of the screen and searching for Konsole. When you see the application, click on its icon. Figure 2: Starting Konsole application in Kubuntu The black screen you now see is the Command Line Interface. In it, you should see a single line of text. This is the prompt line ; you may enter your commands when you see it. If command prompt does not appear after executing a command for any reason (program stuck in a loop, etc), you may hit Ctrl-C from keyboard to break the current program and forcefully return back to the prompt. 1.1 Basics For example, lets try date command: type date from keyboard and hit Enter key: Figure 3: Execution of date command You should see that the computer has responded to your command by displaying the current day and time. Try date command a few seconds later again and you should see that the computer responds with a different output. Try the following commands one by one: whoami - displays the username of the current user. cal - displays a calendar. uptime - displays how long the system has been running. echo - tells the computer to repeat a string: echo Hello World echo $USER - What do you see on screen? Why? echo Hello $USER - Combination of previous two examples. echo Two plus five is $((2+5)) - The CLI may help you with mathematics too. 2

1.2 Working With Files Echo command can also help you with creating text files. Enter the following commands: echo ntp 123 udp > ports.txt echo tftp 69 udp >> ports.txt echo dns 53 tcp udp >> ports.txt echo imap 143 tcp udp >> ports.txt echo ssh 22 tcp udp >> ports.txt echo https 443 tcp >> ports.txt echo ftp 21 tcp udp >> ports.txt echo http 80 tcp >> ports.txt Remember that when you used echo command previously, the output was written to the screen. But if you use > or >> signs, the output will instead be written to a specified file (ports.txt in this case). Do note that using > will clear everything in the file and start from beginning, while >> appends to the end of file without clearing previous contents. This is analogous to the difference between opening files with w or a modes with fopen() function in C programming language. Now that you have created a file, lets see if it is really there. Type ls command. This command lists available files and directories. Along with some directories, you should see your newly created file too. If you want to view contents of this file, you must execute cat ports.txt : Figure 4: Execution of ls and cat commands Execute the following commands one by one and understand how they work: wc ports.txt grep tcp ports.txt sort ports.txt sort ports.txt > sorted.txt cp ports.txt network.txt mv network.txt list.txt - Count words, lines and characters in ports.txt - Search for the word tcp in ports.txt and display the lines in which this word appears - alphanumerically sorts lines in ports.txt file and display results on screen - sorts ports.txt into sorted.txt file - make a new copy of ports.txt named as network.txt - rename network.txt into list.txt 3

1.3 Working With Directories In Linux based operating systems, files and directories are stored in an hierarchy as demonstrated below: Figure 5: File System Hierarchy When you first open Konsole, you usually start in your home directory, which resides in /home/ directory (e.g. /home/abc/, /home/student/, etc). All files and directories owned by your account are stored in your home directory by default. Execute the following commands one by one and understand how they work: ls cd Desktop mkdir lab1 ls cd lab1 ls cd.. cd.. - to view which files and directories are available in your current directory - change current directory to Desktop - make a new directory named lab1 - to view which files and directories are available in your current directory - change current directory to lab1 - to view which files and directories are available in your current directory - go back to parent directory - go back to parent directory You can move your files and directories into other directories. For example, execute the following: mv list.txt Desktop/lab1/ mv sorted.txt Desktop/lab1/ These two commands will move both your text files into lab1 directory you have created earlier. 4

1.4 Removing Files and Directories Go into your lab1 directory by properly using and cd commands. commands: Then execute the following rm list.txt - removes list.txt file. rm sorted.txt - removes sorted.txt file. cd.. - go to parent directory. rmdir lab1 - remove lab1 directory. Do note that rmdir requires the target directory to be completely empty before removing. Be careful! Using rm and rmdir commands will IMMEDIATELY delete files and directories, so you can not recover them back. 1.5 Getting Help You may get a detailed help document for any command with man utility. For example try man ls now. You can scroll up and down using arrow keys. After reading the document, you may go back to command prompt by hitting q key. You may get detailed documentation about C programming functions with man utility as well. man 3 printf, man 3 scanf, man 3 strcpy, man 3 islower, etc. Try 1.6 Permissions Executing ls -l will generate a detailed list of information about your files and directories: permission owner group size date filename drwxr-xr-x 5 student student 20480 May 21 13:47 Desktop -rw-r----- 1 student student 112 Sep 28 23:06 ports.txt The permissions are is divided into 4 parts: The first position specifies what type of file this is. - means regular file, d means directory, etc. The next three parts are divided into three sets of people: user, group, others. Each group gets three kinds of permission: read, write, execute. For example lets focus on ports.txt: user group others 421 421 421 rw- r-- --- 6 4 0 Access Mode of this file is 640. It is calculated as 4+2+0, 4+0+0, 0+0+0. The first three bits specify the permissions for the user who owns the file. In this example, the owning user can read and modify this file. The next trio of bits are related to other people in the same group as the owner. In this example, group members may read this file but not modify it. 5

The last trio of bits are for people outside the owner s group. In this example, they can neither read, nor modify this file. You can alter access modes of files at any time. Execute the following commands and use ls -l to observe what has changed after each chmod command: chmod 400 ports.txt chmod 644 ports.txt chmod 000 ports.txt chmod +r ports.txt chmod u+w ports.txt chmod o-r ports.txt - set read for owner and nothing else. - set read and write for owner, read for group and others. - remove all access to this file. - give read access for all users. - give write access only to owner. - remove read access from others. 1.7 Command Line Scripts Instead of entering commands one by one, you may store them in script files and execute them at once at any time later. Open Kate application from Kubuntu application menu and type the following: #!/bin/bash # this is a simple script for greeting the user # and displaying working directory and date echo "Hello $USER! You are now in:" echo "The date and time is:" date Save this file as hello.sh in your Desktop. Now open a new Konsole and execute the following: cd Desktop chmod +x hello.sh./hello.sh - go into Desktop directory - give execution permission to hello.sh file - execute your script 6

1.8 Compiling C / C++ Programs You may develop programs using C programming language (and MANY more!) in Linux too. As a demonstration, open Kate from application menu and write a simple hello world program in C. Save your file as hello.c and type the following in a new Konsole window: gcc hello.c -o helloworld - Compile hello.c source code into helloworld program file./helloworld - execute the program Figure 6: Compiling and Executing a C Program The gcc command translates your C source file into executable machine code. executing gcc commmand, you should see two different files: If you list files after -rw-rw-r-- 1 student student 65 Sep 29 12:56 hello.c -rwxrwxr-x 1 student student 8600 Sep 29 12:58 helloworld Notice that the new file, helloworld, has execution permissions. Sometimes you may make mistakes in your programs. In such cases, gcc may display either a warning or an error message: Figure 7: Compilation Warnings and Errors If you encounter a warning message, that means your code has compiled, but may not work properly (e.g. runtime errors). If you encounter an error message, that means your code has not compiled. Fixing warnings is recommended, but fixing errors is compulsory. 7