CS 460 Linux Tutorial

Similar documents
Introduction to the shell Part II

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

Lab 1 Introduction to UNIX and C

The Unix Shell & Shell Scripts

Introduction to Linux

Introduction To Linux. Rob Thomas - ACRC

COL100 Lab 2. I semester Week 2, Open the web-browser and visit the page and visit the COL100 course page.

First of all, these notes will cover only a small subset of the available commands and utilities, and will cover most of those in a shallow fashion.

CSE 390a Lecture 3. bash shell continued: processes; multi-user systems; remote login; editors

Introduction to UNIX command-line

Table Of Contents. 1. Zoo Information a. Logging in b. Transferring files 2. Unix Basics 3. Homework Commands

CSE 391 Lecture 3. bash shell continued: processes; multi-user systems; remote login; editors

First of all, these notes will cover only a small subset of the available commands and utilities, and will cover most of those in a shallow fashion.

commands exercises Linux System Administration and IP Services AfNOG 2015 Linux Commands # Notes

Computer Systems and Architecture

No Food or Drink in this room. Logon to Windows machine

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

Unix Tools / Command Line

Read the relevant material in Sobell! If you want to follow along with the examples that follow, and you do, open a Linux terminal.

First of all, these notes will cover only a small subset of the available commands and utilities, and will cover most of those in a shallow fashion.

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

Linux Command Line Primer. By: Scott Marshall

Scripting Languages Course 1. Diana Trandabăț

Exercise 1: Basic Tools

Unix/Linux Primer. Taras V. Pogorelov and Mike Hallock School of Chemical Sciences, University of Illinois

Computer Systems and Architecture

Chapter-3. Introduction to Unix: Fundamental Commands

Linux Tutorial #6. -rw-r csce_user csce_user 20 Jan 4 09:15 list1.txt -rw-r csce_user csce_user 26 Jan 4 09:16 list2.

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

Introduction to Linux

Useful Unix Commands Cheat Sheet

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

Exploring UNIX: Session 3

LOG ON TO LINUX AND LOG OFF

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

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

Introduction to Unix: Fundamental Commands

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

Introduction: What is Unix?

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

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

A Brief Introduction to the Linux Shell for Data Science

CSE 390a Lecture 3. Multi-user systems; remote login; editors; users/groups; permissions

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

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

Introduction to UNIX command-line II

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]

Lab 1 Introduction to UNIX and C

CS Fundamentals of Programming II Fall Very Basic UNIX

CSC209. Software Tools and Systems Programming.

Exercise Sheet 2. (Classifications of Operating Systems)

Laboratory 1 Semester 1 11/12

Introduction. File System. Note. Achtung!

CENG 334 Computer Networks. Laboratory I Linux Tutorial

The Linux Command Line & Shell Scripting

acmteam/unix.pdf How to manage your account (user ID, password, shell); How to compile C, C++, and Java programs;

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

Lecture # 2 Introduction to UNIX (Part 2)

CS197U: A Hands on Introduction to Unix

CS 261 Recitation 1 Compiling C on UNIX

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

Working with Basic Linux. Daniel Balagué

Hitchhiker s Guide to VLSI Design with Cadence & Synopsys

CS CS Tutorial 2 2 Winter 2018

CpSc 1111 Lab 1 Introduction to Unix Systems, Editors, and C

INSE Lab 1 Introduction to UNIX Fall 2017

Introduction to the Linux Command Line

Using WestGrid from the desktop Oct on Access Grid

Recitation #1 Boot Camp. August 30th, 2016

Lab Working with Linux Command Line

15-122: Principles of Imperative Computation

: the User (owner) for this file (your cruzid, when you do it) Position: directory flag. read Group.

Unix basics exercise MBV-INFX410

Introduction to Linux

Quick Start Guide. by Burak Himmetoglu. Supercomputing Consultant. Enterprise Technology Services & Center for Scientific Computing

CSC UNIX System, Spring 2015

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

Introduction to Linux Organizing Files

Introduction to Linux for BlueBEAR. January

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

Linux Tutorial #7. quota. df (disk free) du (disk usage)

Name: Peter Lemieszewski Venue: Education

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.

A Brief Introduction to Unix

Shell Programming Overview

Appendix B WORKSHOP. SYS-ED/ Computer Education Techniques, Inc.

Introduction to UNIX Command Line

CISC 220 fall 2011, set 1: Linux basics

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

commandname flags arguments

EECS 2031E. Software Tools Prof. Mokhtar Aboelaze

Command Line Interface The basics

COMS 6100 Class Notes 3

Lab 4: Bash Scripting

CS 307: UNIX PROGRAMMING ENVIRONMENT FIND COMMAND

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

Unix Essentials. BaRC Hot Topics Bioinformatics and Research Computing Whitehead Institute October 12 th

Arkansas High Performance Computing Center at the University of Arkansas

CSE 390a Lecture 2. Exploring Shell Commands, Streams, Redirection, and Processes

Mills HPC Tutorial Series. Linux Basics II

Transcription:

CS 460 Linux Tutorial http://ryanstutorials.net/linuxtutorial/cheatsheet.php # Change directory to your home directory. # Remember, ~ means your home directory cd ~ # Check to see your current working directory pwd # You should be in /home/punetid # Let s see what time it is date # Let s see the files and directories in your home directory. ls # Let s see some more information about those files and directories # The -l option (dash ell) displays the long entry for the file or # directory ls -l # Let s see who else has a home directory on this machine # the.. (period period) means to look in the directory above the # current directory # In this case, that is the directory /home. ls -l.. # In this view, you also see the permissions of the directories. # your home directory is marked as # drwx------ # which means d: directory # rwx: the owner can read, write, and execute, # ---: (middle three dashes) the group has no permissions # ---: (rightmost three dashes) the world has no permissions # These permissions allow you access to your home directory but # no one else has access. You can notice the group is listed in the # middle of the line, users. # Check to make sure you are still in your home directory. Using # ls does not move you even if you use the.. option. # Let s make a new directory inside of our home directory mkdir cs360_test # Check to make sure the new directory is listed # Let s move into that directory. # Change Directory cd cs360_test # Confirm your new current working directory

# If you ever need an explanation of a command, use the man command # this will explain the command and list all the options available. man ls (then press enter at the question, q to quit) # Let s copy some files from zeus to the local machine for the # rest of the exercise. # wget will retrieve a file from a web server. wget zeus.cs.pacificu.edu/chadd/linuxtest.tar.gz # The fetch command is similar to wget. The curl command is # also similar. Not all systems have all three commands. # Copy this LinuxTest.tar.gz file to your home directory on zeus. # we will use Secure Copy (scp) to do this. # Note the : at the end! scp LinuxTest.tar.gz punetid@zeus.cs.pacificu.edu: # Connect to zeus to make sure the file transferred up correctly ssh punetid@zeus.cs.pacificu.edu # Make sure your prompt says zeus, otherwise you are still on your # local machine. # Confirm the file exists on Zeus # The who command will show you who else is logged on to this # machine. who # Use the exit command to disconnect from zeus. exit # Make sure your prompt says the name of your local machine and # not zeus! # tar.gz files are compressed archives. # Uncompress and extract the files: # tar: the command # x: extract # v: verbose list to the screen the files extracted # z: compressed (the.gz file extension requires this) # f: file (the filename must follow directly after the f option) tar xvzf LinuxTest.tar.gz # Change directory to the newly created LinuxTest directory # List all the files in that directory # A number of text files (.txt) should be listed.

# Let s look at one of them # cat displays the contents of a text file to the screen cat CS150.txt # If you just want to see the first two lines in a file: head -n 2 CS150.txt # If you just want to see the last two lines in a file: tail -n 2 CS150.txt # A good way to edit the file is to use nano. # The menu is at the bottom of the screen. ^ means the control key. # Control-X exits nano nano CS150.txt # pico is similar to nano. # vi is more powerful than pico or nano, but takes a while to learn. # google vi cheat sheet if you are interested in vi. # There are many words in that file. Let s count how many # lines, words, and characters are in that file. The wc command # will do that. wc CS150.txt # How many lines are in the file? # How many characters are in the file? # You can also print just the number of lines, words, or characters wc -l wc -w wc -m # What does the following do wc * # Let s check how many files contain the word data. grep data * # Grep explained: # grep : the command # data : the pattern to look for # * : the files to check (* is a wildcard meaning every file) # Let s find all the text files (.txt) that exist in the # LinuxTest directory and its subdirectories find. -name '*.txt' # Find explained: # find : the command #. : Start looking in the current directory.

# -name '*txt' : look for file names that match the pattern *.txt # the single quotes are important! # Let s save that list of text files into a new file: # the > will take the output of the command to the left, and write # that output to the file on the right. find. -name '*.txt' > listoffiles.txt # Let s make sure that new file got created # Show the contents of the new file listoffiles.txt # Let s find all the text files again # Notice that listoffiles.txt is now listed. # Let s save the list of text files to a new file, named # newlistoffiles.txt # Let s see how the two list of text files differ. # The diff command compares two text files and displays the # difference diff listoffiles.txt newlistoffiles.txt # The output contains an > which means that line exists in the # file listed on the left, newlistoffiles.txt, and not in the file # listed on the right, listoffiles.txt. # Let s count how many files we found: # The pipe, or vertical bar, takes the output from the command on the # left and uses that output as input to the command on the right. find. -name '*.txt' wc -l # Let s list information about each of the text files: # the xargs command will take each of the lines from the # input (the command on the left) and pass that line # to the command on the right (in this case, ls l) find. -name '*.txt' xargs ls -l # Let's find all the text files that contain the string CS find. -name '*.txt' xargs grep CS # Let s move into the documents directory to work with those files # Display the contents of the file preamble.txt # Display the contents of the file declaration.txt

# This file declaration.txt is really long and scrolls by too fast. # Let s slowly scroll through the file. # the less command shows you a screen full of text at a time # press space for the next screen. press enter for the next line. # press q to quit cat declaration.txt less # The more command is similar cat declaration.txt more # You don t need to use cat more declaration.txt less declaration.txt # You can edit the output of a command using sed # The following command will replace all the of periods with # exclamation marks as the file CS150.txt is displayed. # The string in ' ' is of the format: # s/oldtext/newtext/g # s means search and replace # g means for each instance in the string # in our example \. is the escaped period. A period usually # means match any character. # sed operates on the file text one line at a time. cat CS150.txt sed 's/\./!/g' # Compiler Options # Don't forget the gcc compiler options: # -Wall : show all warnings # -g : include debug symbols # -c : compile only (produce object file) # -o file : name the output filename # -S : produce assembly # -fverbose-asm : produce verbose assembly gcc -o main_asm.s -S main.c gcc -o main_asm.s -fverbose-asm -S main.c gcc -o main.o -c -g -Wall main.c gcc -o main -g main.o

# You can perform more complicated regular expressions with sed: \ls CS*.txt \ls CS*.txt sed 's/cs\([0-9]*\)\.txt/\1/g' # Sort the results in reverse \ls CS*.txt sed 's/cs\([0-9]*\)\.txt/\1/g' sort -r # the capital R option to sort is quite different. Run the following # command twice. \ls CS*.txt sed 's/cs\([0-9]*\)\.txt/\1/g' sort -R What does -R do? # Open up another terminal on the other monitor # Run top to show all the processes currently running top # restrict top to show only your processes by typing u in the window # displaying top and typing your punetid # Press q in the window displaying top to quit top. Do not close the # terminal. # Type ps to see all the processes running in your current window ps # The sleep command will sleep for some number of seconds sleep 3 # Putting an & at the end of a command will run the command in the # background and allow you to type more commands. sleep 120 & # Check all the running processes again, you should see sleep running # (or sleeping) # Open top again in the other terminal # restrict top to show only your processes # Go back to the original terminal and launch sleep again with the & sleep 600 & # Look at top. The PID or process id is listed at the left. Sleep # should be listed. # Find the process id.

# Go back to the other terminal and kill the sleep process kill PID # Some processes don t die when you use kill alone. Sometimes you # need to do the following. 9 stands for SIGKILL: kill -9 PID # Check out the following man page. # You are looking at the definition of kill from section 1p. # SIGKILL is listed around line 70. man -s 1p kill # A few more commands. # Let s check how much space is left on the hard drive # You should be able to see how much space is available on /home df -h # Another useful command is screen. # Let s first check to make sure screen is available in the lab. # The which command will tell you where the command is on the # file system, if it exists. which screen # if screen is not installed in ArchLinux, user sudo pacman -S screen which bob # should fail and tell you in which directories which looked for bob # Screen exists, good. # screen is especially useful if you # need to run a long running command on a remote machine, such as # zeus. You would log into zeus and then start screen on zeus. screen -S test # This creates a shell session that won t die if you get # disconnected. Also, you can reconnect to this shell session from # another location to check # the progress of your work or make changes. # In a new terminal, connect to the screen you just created: screen -x test ls ls al # you should see the same output being shown in both terminals. # everything is happening exactly once, the output is just # copied to both places. # Let s disconnect from screen in one terminal. Control-A D # In the other terminal, let s write a little loop # The bash shell is powerful, you can program right in the shell! # The following is a while loop that will sleep for 3 seconds, # display information about the hard drive, and then display the # date. Remember, the semi-colon is just a command separator # The loop is equivalent to while(true) in C++ so it will

# never terminate. Later, we will use Control-C to kill the loop. while [ true ] ; do sleep 3; df -h ; date ; done # Let s disconnect from screen in this terminal. Control-A D # Take a deep breath. # Let s reconnect: screen -x test # Your previous output should show up and you should see that the # loop is still running. # Press control-c to kill the loop # Typing exit will terminate the screen.

QUESTIONS TO ANSWER Email the solutions to the instructor by 1pm Feb 6. Create a script of your session: script --timing=punetid_lp_timing PUNETID_LP.txt When you are done, exit to end the script. Tar and gzip the two files created above and email the tgz file to your instructor. What commands do you need to run to solve each question: 1. Move to your home directory 2. Attempt to move to Chadd s home directory (username: chadd). 3. Show all of the files and directories in your home directory, except those that start with a dot. 4. Count the number of the files and directories in your home directory, except those that start with a dot. (I ll accept an off by one error). (BONUS: don t be off by one). 5. Count the number of the files and directories in your home directory, including those that start with a dot. (I ll accept an off by one error) 6. How many characters are there in the first two lines of CS150.txt? 7. How many lines in the first 5 lines of CS150.txt contain the string CS? 8. BONUS: How many lines in the first 5 lines of CS150.txt contain the word is? The match must be case-insensitive. Note: Any line that only contains the word This does not match. 9. How many lines in the first 5 lines of each of the *.txt files contain the string CS? You must use on string of commands and must output exactly one number. 10. Run sleep 500 in the background, find sleep s process id, kill sleep. You can review your work with: scriptreplay PUNETID_LP_Timing PUNETID_LP.txt