CSCM98 Lab Class #5 Getting familiar with the command line

Similar documents
List of Linux Commands in an IPm

hash Remember the full pathname of a name argument head Output the first part of file(s) history Command History hostname Print or set system name

Bash command line for Linux. adduser Add a user to the system. addgroup Add a group to the system. Create an alias

Operating Systems Lab 1 (Users, Groups, and Security)

SANJAY GHODAWAT POLYTECHNIC

Kali Linux Commands Cheat Sheet

Linux Essentials Objectives Topics:

PDF Downloaded from StuffPrime All Tech Stuff That Matters

Lecture 02: Linux Command Line

TestOut Linux Pro - English 4.0.x OBJECTIVE MAPPING: CompTIA Linux+ LX0-103

Linux Reference Card - Command Summary

LPIC-1 System Administrator

Computer Systems and Architecture

Introduction to Supercomputing

Linux Command Line Primer. By: Scott Marshall

UNIX. Basic UNIX Command

Linux crash lecture by Andrey Lukyanenko

[ Terminal ] [ Users management ] Alt +F6 = Terminal switcher. useradd [option] JohnG

Computer Systems and Architecture

Presented by Bill Genske Gary Jackson

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

Embedded Linux Systems. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Unix/Linux Operating System. Introduction to Computational Statistics STAT 598G, Fall 2011

1. $ who 2. $ date 3. $ echo $? 4. $ echo $$ 5. $ ps 6. $ echo $PATH 7. $ echo $HOME 8. $ echo \thola 9. $ echo "\thola" 10. $ echo e "\thola" 11.

On successful completion of the course, the students will be able to attain CO: Experiment linked. 2 to 4. 5 to 8. 9 to 12.

Unix Tools / Command Line

System Administration

2. UDP Client, UDP Server

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

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

BIOINFORMATICS POST-DIPLOMA PROGRAM SUBJECT OUTLINE Subject Title: OPERATING SYSTEMS AND PROJECT MANAGEMENT Subject Code: BIF713 Subject Description:

Introduction to Linux

for more :-

Some useful UNIX Commands written down by Razor for newbies to get a start in UNIX

Shell Programming Systems Skills in C and Unix

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

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

Introduction To Linux. Rob Thomas - ACRC

Shell. SSE2034: System Software Experiment 3, Fall 2018, Jinkyu Jeong

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

Essential Unix (and Linux) for the Oracle DBA. Revision no.: PPT/2K403/02

Basic Linux (Bash) Commands

Introduction to UNIX. Introduction EECS l UNIX is an operating system (OS). l Our goals:

LING 408/508: Computational Techniques for Linguists. Lecture 5

Linux Kung-Fu. James Droste UBNetDef Fall 2016

Introduction to Linux

Perl and R Scripting for Biologists

Exercise 1: Basic Tools

LAB #7 Linux Tutorial

Lab 2A> ADDING USERS in Linux

Course 144 Supplementary Materials. UNIX Fundamentals

Common UNIX Utilities Alphabetical List

Basic Linux Command Line Interface Guide

Exam Linux-Praxis - 1 ( From )

CENG 334 Computer Networks. Laboratory I Linux Tutorial

Basic Linux Command Line Interface Guide

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

INTRODUCTION TO LINUX

2 Lab 4. Unix Shell 2

Introduction to UNIX/Linux

Lab Working with Linux Command Line

Linux Shell Script. J. K. Mandal

More Raspian. An editor Configuration files Shell scripts Shell variables System admin

Unix as a Platform Exercises. Course Code: OS-01-UNXPLAT

INd_rasN SOME SHELL SCRIPTING PROGRAMS. 1. Write a shell script to check whether the name passed as first argument is the name of a file or directory.

ECE 471 Embedded Systems Lecture 10

National University of Computer and Emerging Sciences Operating System Lab - 02 Lab Manual

Defensie Exercises preparing for the exam.

2) clear :- It clears the terminal screen. Syntax :- clear

CS/CIS 249 SP18 - Intro to Information Security

Linux Kung Fu. Stephen James UBNetDef, Spring 2017

Unix Guide. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : December, More documents are freely available at PythonDSP

UNIX System Programming Lecture 3: BASH Programming

Processes and authentication

Mills HPC Tutorial Series. Linux Basics II

Assume that username is cse. The user s home directory will be /home/cse. You may remember what the relative pathname for users home directory is: ~

Introduction to UNIX. Introduction. Processes. ps command. The File System. Directory Structure. UNIX is an operating system (OS).

Introduction to UNIX. CSE 2031 Fall November 5, 2012

DAVE LIDDAMENT INTRODUCTION TO BASH

NETW 110 Lab 5 Creating and Assigning Users and Groups Page 1

Introduction to UNIX Command Line

Introduction. What is Linux? What is the difference between a client and a server?

EECS2301. Lab 1 Winter 2016

Topics. Installation Basics of Using GNU/ Linux Administration Tools

The Unix Shell & Shell Scripts

3/8/2017. Unix/Linux Introduction. In this part, we introduce. What does an OS do? Examples

Lecture 03. Shell programming Part 1. CSC 320: Systems Programming

SA2 v6 Linux System Administration II Net Configuration, Software, Troubleshooting

Command-line interpreters

Linux at the Command Line Don Johnson of BU IS&T

Useful Unix Commands Cheat Sheet

Unix as a Platform Exercises + Solutions. Course Code: OS 01 UNXPLAT

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]

Introduction to Linux. Roman Cheplyaka

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

Shell Scripting. With Applications to HPC. Edmund Sumbar Copyright 2007 University of Alberta. All rights reserved

Unix Introduction to UNIX

EECS 2031E. Software Tools Prof. Mokhtar Aboelaze

IMPORTANT: Logging Off LOGGING IN

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

Transcription:

CSCM98 Lab Class #5 Getting familiar with the command line Lab Class Description. Unix has some powerful commands that can be combined inside shell scripts. Today we will have a look at various commands before seeing at how shell programming works. Firstly, log on the Unix computers and start a command line. Note that a few of those commands may not work on your account/system. Task 1 First, create a directory for the lab class using the following commands: cd cd ~ mkdir CSCM98_lab cd CSCM98_lab You will then need to download the lab file from the course website and add it to this directory (lab5.tar.gz). Then, uncompress the files with the following command from the command line. Make sure you download the file in the right directory! tar xvf lab5.tar.gz then try unzip lab.zip Task 2: Simple commands Try the following commands from the command line and describe their action ls ls -la pwd whoami groups

who w finger myusername mail myusername@swansea.ac.uk Finish with a. on the last line wc lab1.cpp more lab1.cpp cat lab1.cpp diff lab1.cpp lab2.cpp man kill followed by Q man kill more use spacebar du lab1.cpp df date grep main lab1.cpp

find. name "lab.zip" ps ps -edf pstree kate followed by ctrl-c in the command line kate& top find the kate pid from top and follow with ctrl-c kill 9 kate_pid whereis ls cmp lab1.cpp lab2.cpp man chown env

Task 3: Pipes and text files Try the following commands in the following order and ask if necessary: echo helloworld echo ls>myls ls -la ls la grep myls./myls man chmod man umask man chown man chgrp chmod u+x myls./myls echo "echo Hello world" >>myls./myls man cut man tr ps -edf grep mysusername tr s " " cut d' ' f1,2 ls *.cpp more man cron

Task 4: small introduction to shell scripts cat>script.sh then enter the following: for x in lab1.cpp 1 5 do echo hi $x! done mkdir tmp cd tmp pwd ctrl-c chmod the script file with the right properties, then execute it. Test the command pwd again. Finally, lookup eval Online as this command will be useful in our next exercise. Task 5 Read, create (by copy-pasting text possibly) and run the following bash script: #This is a comment #!/bin/bash echo Calculator polish notation echo enter. for exiting sum=0 lastnb=0 echo $lastnb while read entry do case "$entry" in.) break +) let sum=$(($sum+$lastnb)) -) let sum=$(($sum-$lastnb)) /) let sum=$(($sum/$lastnb)) "*") let sum=$(($sum*$lastnb)) *) let lastnb=$entry esac done Try to understand every line of code and ask if needed. To run a command, the script must be executable (an x should show up for your file after an ls -la command.) Use the command

chmod u+x on your script first before execution. Task 6: The script below is trying to count how much space is taken by files including $1 and greater than $2 (E.g. spacescript ".cpp" 50 ). The script does not however work. This is due to the fact that the while loop is included in a pipe (that creates a new context for the process) and the global sum is therefore not updated at the end. Try to run the code first. In a second time, modify the script by 1) Redirecting the ls line to a temporary file using > ; 2) Using both the created file and < after the while loop to provide the input lines to the while loop; 3) Finally deleting the temporary file. #!/bin/bash echo sum of large files sum=0 ls -la grep $1 tr -s " " cut -d' ' -f5 while read entry do if [ $entry -gt $2 ] then echo File size: $entry sum=$(($sum+$entry)) ; fi done echo Total usage for $1 $sum Task 7: Create a script that computes a Fibonacci value recursively. i.e. the script should call itself. Do not try with large values. Note that arithmetic can be written the following way: let val1=$myvariable+1 or val1=$(($myvariable+1)) while getting the ouput of a command in a variable can be written as follow for instance: result=$(./myscript myargument)

Others: System, admin commands and more (optional) man dump man restore man badblocks man lsmod man insmod man rmmod man modprob man quota man ldd man watch man useradd man userdel man usermod man groupmod man newgrp man id man lid logname su l alogin man sudo man passwd man ac last tset r uname a arch lastlog lsof more strace man nc ping Swansea.ac.uk free man stat vmstat man dmesg hostname hosted sar man realdelf man size man logger man logrotate man pidof man nice man halt math shutdown man reboot man service man nmap ifconfig netstat man mount man umount

man mkswap man mke2fs man mkbootdisk man ulimit man strip man nm man xrandr man linx man wget