California State University Fresno

Slides:



Advertisements
Similar presentations
Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
Advertisements

Chapter One The Essence of UNIX.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
Cosc 4750 Getting Started in UNIX Don’t be afraid of the prompt, in linux it can be your best friend. In some cases, the only way to do certain things.
Introducing the Command Line CMSC 121 Introduction to UNIX Much of the material in these slides was taken from Dan Hood’s CMSC 121 Lecture Notes.
Linux+ Guide to Linux Certification, Second Edition
Linux+ Guide to Linux Certification, Second Edition
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Very Quick & Basic Unix Steven Newhouse Unix is user-friendly. It's just very selective about who its friends are.
Linux Shell. 2 Linux Command-Line Interface ■ Linux shells: A shell is a command interpreter that allows you to type commands from the keyboard to interact.
Linux Commands LINUX COMMANDS.
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
Chapter 9 Part II Linux Command Line Access to Linux Authenticated login using a Linux account is required to access a Linux system. The Linux prompt will.
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
Introduction to Shell Script Programming
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Introduction to the Shell – Session 2 · Permissions · Users.
CENT 305 Information Systems Security Linux Introduction.
Carnegie Mellon Linux Boot Camp Jenna MacCarley, Peter Pearson, Shashank Goyal 9/19/2015.
1 UNIX essentials (hands-on) the directory tree running programs the shell → command line processing → special characters → command types → shell variables.
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
Session 2 Wharton Summer Tech Camp Basic Unix. Agenda Cover basic UNIX commands and useful functions.
Linux+ Guide to Linux Certification, Third Edition
UNIX shell environments CS 2204 Class meeting 4 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
Introduction to Programming Using C An Introduction to Operating Systems.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.
1 CS3695/M6-109 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
Jozef Goetz, expanded by Jozef Goetz, 2006 Credits: Parts of the slides are based on slides created by textbook authors, Syed M. Sarwar, Robert.
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
Linux+ Guide to Linux Certification, Second Edition
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
 Simple UNIX commands  I/O techniques in C++  Solutions to Lab#0 problems  Solutions to Lab#1 problems 1.
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
Learning Unix/Linux Based on slides from: Eric Bishop.
Linux Administration Working with the BASH Shell.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
GRID COMPUTING.
Tutorial of Unix Command & shell scriptS 5027
Lesson 5-Exploring Utilities
CS1010: Intro Workshop.
Quality Thought Technologies
SUSE Linux Enterprise Desktop Administration
Bash Introduction (adapted from chapters 1 and 2 of bash Cookbook by Albing, Vossing, & Newham) CPTE 440 John Beckett.
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
UNIX The Basics Source:
Andy Wang Object Oriented Programming in C++ COP 3330
Some Linux Commands.
Introduction to Linux Dr Karina Kubiak - Ossowska
Part 3 – Remote Connection, File Transfer, Remote Environments
Guide To UNIX Using Linux Third Edition
The Linux Operating System
Introduction to Programming the WWW I
Shell Script Assignment 1.
Vim.
Assignment Preliminaries
Tutorial of Unix Command & shell scriptS 5027
Basic UNIX OLC Training.
Introduction to UNIX.
Tutorial of Unix Command & shell scriptS 5027
John Carelli, Instructor Kutztown University
Guide To UNIX Using Linux Third Edition
Web Programming Essentials:
Tutorial of Unix Command & shell scriptS 5027
Andy Wang Object Oriented Programming in C++ COP 3330
Linux Shell Script Programming
Linux Commands LINUX COMMANDS.
A shell is a user interface.
Presentation transcript:

California State University Fresno Essential Linux Harinder Bawa California State University Fresno

Editors In order to do many tasks you will have to use an editor Edit Code Control analysis/programs In the linux world these all edit text files Word is not an editor Can run at the command line, or in window 5/19/2018 Dr. Harinder Bawa

Choice of an editor Nearly always available Don’t require xwindows Command line editors vi vim pico/nano Xwindow editors Xemacs/emacs nedit Nearly always available Don’t require xwindows fast Not very powerful and no access to mouse 5/19/2018 Dr. Harinder Bawa

vi Editor The most readily available Generally installed as standard on all systems Quite powerful But difficult to use or at least get used to Some people swear by vi Its important to know some basics in case vi is the only option for a particular task. 5/19/2018 Dr. Harinder Bawa

Basic commands of vi vi filename (open file to edit) Two modes of operation Insert mode: Used for typing ( after typing i) Command mode:- used to issue commands(Esc + command) :q to quit without saving (!q= quit & discard changes) u = undo the last change x = Delete a character; dd= delete full line :wq to quit after saving 5/19/2018 Dr. Harinder Bawa

vi: Cheat sheet 5/19/2018 Dr. Harinder Bawa

Editing a file using pico or nano Type “pico” or “nano” at the prompt 5/19/2018 Dr. Harinder Bawa

Editing a file using pico To save use “ctrl-x” 5/19/2018 Dr. Harinder Bawa

Compiling a C++ Program To compile a c++ program, use the g++ command. “g++ helloworld.cpp” Provided there are no errors, this will create an executable file called a.out. If you want to name your executable file, use the -o flag to specify a name. “g++ helloworld.cpp -o helloworld.out”

Running a C++ Program Running a c++ program is easy, just type in the name of the executable file! “a.out” There could be a minor issue however. If for some reason, that doesn’t work, try preceding the name with a ./ “./a.out”

OTHERS WAY TO DISPLAY A FILE CONTENTS AND SEARCH INSIDE IT 5/19/2018 Dr. Harinder Bawa

Displaying a file Various ways to display a file in Unix cat less/more head tail 5/19/2018 Dr. Harinder Bawa

Command: cat Dumps an entire file to standard output Good for displaying short, simple files 5/19/2018 Dr. Harinder Bawa

Command: less/more “less” displays a file, allowing forward/backward movement within it return scrolls forward one line, space one page y scrolls back one line, b one page use “/” to search for a string Press q to quit The file contents are displayed by ‘cat’ command. The contents will scroll off the screeen, when the file contents are more than one screen page. The file contents are displayed page by page with the use of ‘more’ command. 5/19/2018 Dr. Harinder Bawa

Command: head “head” displays the top part of a file By default it shows the first 10 lines -n option allows you to change that “head -n50 file.txt” displays the first 50 lines of file.txt 5/19/2018 Dr. Harinder Bawa

Command: head Here’s an example of using “head”: 5/19/2018 Dr. Harinder Bawa

Command: tail Same as head, but shows the last lines 5/19/2018 Dr. Harinder Bawa

Pipes and Redirection Programs can output to other programs called “piping Command > file- Redirect output to a file Command>>file- Append output to an existing file Command<file- Get input from a file, eg sort<file.txt Command<file1>file2- Get input from file1, and write to file2 Command | command- Pipe one command to another 5/19/2018 Dr. Harinder Bawa

Searching grep pattern files- search for pattern in files grep -r pattern dir- search recursively for pattern in dir Command | grep pattern- search for pattern in the output of command locate file- find all instances of file 5/19/2018 Dr. Harinder Bawa

A few examples of piping 5/19/2018 Dr. Harinder Bawa

Command: wc To count the characters, words, and lines in a file use “wc” The first column in the output is lines, the second is words, and the last is characters 5/19/2018 Dr. Harinder Bawa

A few examples of piping 5/19/2018 Dr. Harinder Bawa

Command: grep To search files in a directory for a specific string use “grep” 5/19/2018 Dr. Harinder Bawa

Command: diff To compare to files for differences use “diff” Try: diff /dev/null hello.txt /dev/null is a special address -- it is always empty, and anything moved there is deleted 5/19/2018 Dr. Harinder Bawa

LINUX SHELLS & ITS SCRIPTING 5/19/2018 Dr. Harinder Bawa

Shells The shells is a part of the interface for control of linux There are a number of options, the two most common are: tc (or c) shell (tcsh) bourne shell (bash) Change your shell with chsh Pick a shell and stick to it, but can be useful for a new account somewhere. 5/19/2018 Dr. Harinder Bawa

Linux Command Line Interface Linux shells: A shell is a command interpreter that allows you to type commands from the keyboard to interact with the operating system kernel. ■ sh (Bourne Shell) The sh shell was the earliest shell, being developed for UNIX back in the late 1970s. ■ bash (Bourne-Again Shell) The bash shell is an improved version of the sh shell and is one of the most popular shells today. It’s the default shell used by most Linux distributions. ■ csh (C Shell) The csh shell was originally developed for BSD UNIX. It uses a syntax that is very similar to C programming. ■ tsch The tsch shell is an improved version of the C Shell. It is the default shell used on FreeBSD(Berkeley Software Distribution) systems. ■ zsh (Z Shell) The Z Shell is an improved version of the bash shell. 5/19/2018 Dr. Harinder Bawa

Environment variables Much of your linux environment is set by environment variables These are access via the $sign eg $HOST To view your environment use env Prints out all your environment variables Use echo to view an individual one echo $HOST or echo $HOME 5/19/2018 Dr. Harinder Bawa

Setting environment variables You can set your environment variables using export (bash shell) export ROOTSYS=/user/local/root setenv(tc shell) setenv ROOTSYS /user/local/root This creates the variable if it doesn’t already exist or updates if it does Typically the environment variables you set yourself will be to tell programs where to find things. 5/19/2018 Dr. Harinder Bawa

Your PATH Your path is an environment variable $PATH (check by echo $PATH) It contains all the directories that your OS will look in to find the programs you want to run The path should contain “.” to ensure that you don’t need to specify it while running local program Entries are separated by “:” Update your path with setenv PATH /newdir:$PATH 5/19/2018 Dr. Harinder Bawa

Adding/Modifying the “PATH” 5/19/2018 Dr. Harinder Bawa

Bash Shell Startup When a bash shell is started, it automatically executes commands stored in certain files. There are three kinds of shells: 5/19/2018 Dr. Harinder Bawa

Note: Hidden files If you try the ls command in your home directory, you will (probably) notice that the file .bash_profile is not listed. Filenames that begin with a period are hidden by default. You can use the ls –a command will show hidden files as well as non-hidden files. 5/19/2018 Dr. Harinder Bawa

Ubuntu Variance When you open an interactive terminal session in Ubuntu, the sequence described on the preceding slide is NOT followed by default. In particular, ~/.bash_profile is not executed automatically, and therefore changes you make to it will not be effective. There is a simple fix for the issue: - open a terminal session and go to Edit/Profile Preferences - select the Title and Command tab - check the box for “Run command as a login shell” In fact, in my Ubuntu installation, ~/.bash_profile did not exist initially; I had to create it with editor. 5/19/2018 Dr. Harinder Bawa

~/.bash_profile You should use ~/.bash_profile to set changes to the PATH variable because ~/.bash_profile is only executed once. Here is a sample ~/.bash_profile And you know how to add PATH. Right? 5/19/2018 Dr. Harinder Bawa

A sample ~/.bashrc alias commands are a convenient way to create mnemonics(memory) for specialized execution of system commands. 5/19/2018 Dr. Harinder Bawa

Setup atlas environment in lxplus 5/19/2018 Dr. Harinder Bawa

Remote communication Most of your analysis is unlikely to be on your local machine. You need to login to bigger computing clusters e.g CERN’s “lxplus.cern.ch” or FresnoState “t3head.atlas.fresnostate.edu” provided you have account in that! Advantage Large Processing nodes for jobs Remote data storage for experiments Remote code repositories & databases . 5/19/2018 Dr. Harinder Bawa

ssh/scp ssh is used to securely log in to remote systems, successor to telnet ssh options [username]@[hostname]/ip ssh bawa@lxplus.cern.ch Type “exit” to log out of session 5/19/2018 Dr. Harinder Bawa

ssh/scp scp is used to copy files to/from remote systems, syntax is similar to cp: scp [local path] [username]@[hostname]:[remote file path] scp options file bawa@lxplus.cern.ch:path/. or scp options bawa@lxplus.cern.ch:path/file 5/19/2018 Dr. Harinder Bawa

Exercise-1 Download http://zimmer.csufresno.edu/~hbawa/ubuntu.txt Print number of words in the file Print number of lines in a file Command to scp transfer the file to your lxplus area login to lxplus and move the file to /tmp/username dir. Scp transfer file from lxplus /tmp/username to your current working dir. 5/19/2018 Dr. Harinder Bawa

Exercise-2 Download simple c++ code from http://zimmer.csufresno.edu/~hbawa/cplus.C Open using any editor (vi /pico) Remove second line and correct indentations. Save the file Compile using both c++ and g++ compiler Make executable name “myoutput” Run and print the output 5/19/2018 Dr. Harinder Bawa

Brain Teaser How to save the output text on the screen in a file named “screen.txt”. 5/19/2018 Dr. Harinder Bawa