A UNIX/Linux in a nutshell



Similar documents
Linux command line. An introduction to the Linux command line for genomics. Susan Fairley

Command Line - Part 1

An Introduction to the Linux Command Shell For Beginners

Unix Sampler. PEOPLE whoami id who

Tutorial 0A Programming on the command line

LECTURE-7. Introduction to DOS. Introduction to UNIX/LINUX OS. Introduction to Windows. Topics:

Basic C Shell. helpdesk@stat.rice.edu. 11th August 2003

ICS 351: Today's plan

Fred Hantelmann LINUX. Start-up Guide. A self-contained introduction. With 57 Figures. Springer

Command Line Crash Course For Unix

Command-Line Operations : The Shell. Don't fear the command line...

Introduction to Mac OS X

A Crash Course on UNIX

Thirty Useful Unix Commands

Cisco Networking Academy Program Curriculum Scope & Sequence. Fundamentals of UNIX version 2.0 (July, 2002)

CSIL MiniCourses. Introduction To Unix (I) John Lekberg Sean Hogan Cannon Matthews Graham Smith. Updated on:

1 Basic commands. 2 Terminology. CS61B, Fall 2009 Simple UNIX Commands P. N. Hilfinger

Unix Guide. Logo Reproduction. School of Computing & Information Systems. Colours red and black on white backgroun

Tutorial Guide to the IS Unix Service

An Introduction to Using the Command Line Interface (CLI) to Work with Files and Directories

HP-UX Essentials and Shell Programming Course Summary

CMSC 216 UNIX tutorial Fall 2010

Introduction to the UNIX Operating System on IT Systems

University of Toronto

UNIX Tutorial for Beginners

Unix the Bare Minimum

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, Introduction 1. 2 Invoking Shell Scripts 2

USEFUL UNIX COMMANDS

AN INTRODUCTION TO UNIX

Basic Linux & Package Management. Original slides from GTFO Security

Hands-On UNIX Exercise:

Introduction to. UNIX Bob Booth December 2004 AP-UNIX2. University of Sheffield

The Linux Operating System and Linux-Related Issues

Introduction to Unix Tutorial

Introduction to the UNIX Operating System and Open Windows Desktop Environment

Birmingham Environment for Academic Research. Introduction to Linux Quick Reference Guide. Research Computing Team V1.0

Lab 1: Introduction to C, ASCII ART and the Linux Command Line Environment

Training Day : Linux

1 Intro 1. 2 man - Accessing On-Line Manual Pages 1. 3 pwd - Print the Working Directory 2. 4 cd - Changing Directory 2

Introduction to Shell Programming

Unix Primer - Basic Commands In the Unix Shell

Syntax: cd <Path> Or cd $<Custom/Standard Top Name>_TOP (In CAPS)

How To Use The Librepo Software On A Linux Computer (For Free)

INASP: Effective Network Management Workshops

An A-Z Index of the Apple OS X command line (TERMINAL) The tcsh command shell of Darwin (the open source core of OSX)

DOS Command Reference

LPI certification 101 exam prep, Part 1

TEL2821/IS2150: INTRODUCTION TO SECURITY Lab: Operating Systems and Access Control

CS 103 Lab Linux and Virtual Machines

Linux Overview. Local facilities. Linux commands. The vi (gvim) editor

UNIX, Shell Scripting and Perl Introduction

New Lab Intro to KDE Terminal Konsole

L01 Introduction to the Unix OS

Lab 1: Introduction to the network lab

Introduction to Linux and Cluster Basics for the CCR General Computing Cluster

UNIX Intro and Basic C shell Scripting

GNU/Linux Command Line Tools Summary

List of FTP commands for the Microsoft command-line FTP client

Shell Scripts (1) For example: #!/bin/sh If they do not, the user's current shell will be used. Any Unix command can go in a shell script

Introduction to Running Hadoop on the High Performance Clusters at the Center for Computational Research

Open Source Computational Fluid Dynamics

Hadoop Basics with InfoSphere BigInsights

Introduction to Operating Systems

A Brief Introduction to the Use of Shell Variables

Linux System Administration on Red Hat

Extreme computing lab exercises Session one

UNIX Basics. Ian Darwin TCP Informatics January, Presented from a Mac using Apple s Keynote presentation software

Linux System Administration

Unix Scripts and Job Scheduling

UNIX / Linux commands Basic level. Magali COTTEVIEILLE - September 2009

UNIX (LINUX) PRACTICAL 1 INTRODUCTION

Lecture 22 The Shell and Shell Scripting

Although Mac OS X is primarily known for its GUI, the under pinnings are all Unix. This

Recommended File System Ownership and Privileges

Higher National Unit Specification. General information for centres. Multi User Operating Systems. Unit code: DH3A 34

CS 2112 Lab: Version Control

Running your first Linux Program

CPSC2800: Linux Hands-on Lab #3 Explore Linux file system and file security. Project 3-1

Using SVN to Manage Source RTL

Cygwin command line windows. Get that Linux feeling - on Windows

Unix/Linux Forensics 1

Lecture 18 Regular Expressions

system or read a good Unix book from the DESY library (e.g. Mark Sobell, APractical Guide to

Beginners Shell Scripting for Batch Jobs

Kernel. What is an Operating System? Systems Software and Application Software. The core of an OS is called kernel, which. Module 9: Operating Systems

grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print

An Introduction to Using the Command Line Interface (CLI) to Work with Files and Directories

12 Most Important Unix Commands You Should Know

Lecture 4: Writing shell scripts

Basic Linux and Unix commands, editing and transfering files

Introduction to Git. Markus Kötter Notes. Leinelab Workshop July 28, 2015

USERS MANUAL FOR OWL A DOCUMENT REPOSITORY SYSTEM

Agenda. Using HPC Wales 2

Shree M. & N. Virani Science College. DOS Commands. By Milan Kothari. Yogidham, Kalawad Road, Rajkot 5 Ph :

A Computer Glossary. For the New York Farm Viability Institute Computer Training Courses

Version Control with Subversion and Xcode

UNIX - FILE SYSTEM BASICS

2 Advanced Session... Properties 3 Session profile... wizard. 5 Application... preferences. 3 ASCII / Binary... Transfer

HDFS File System Shell Guide

Advanced UNIX Techniques Lee Ann Lee Revised by Wendy Kajiyama

Transcription:

bergman p.1/23 A UNIX/Linux in a nutshell Introduction Linux/UNIX Tommi Bergman tommi.bergman[at]csc.fi Computational Environment & Application CSC IT center for science Ltd. Espoo, Finland

bergman p.2/23 Contents Introduction Linux/UNIX Small utilities Shell Command line interface Linux/UNIX redirecting Directories and files Linux/UNIX pipes Directory structure Reading text files Contents of a directory More on text files Moving around in the directory tree Environment variables Creating directories Adding and Removing Moving and copying files Shell Scripting Directory and file permissions Config files.emacsrc.bashrc etc. Permissions: adding or removing Command Reference Online help on commands

bergman p.3/23 Introduction to UNIX/Linux UNIX/Linux are multitasking operating systems So systems running multiple programs and hosting multiple users at a time usually textual command line shell for command input you can also use GUI(graphical user interface) Same basic system utilities are typically found on both systems These system utilities include small programs for e.g. showing contents for a directory: ls, for copying files: cp, finding text in files: grep

bergman p.4/23 The Shell or command line interface Program that enables the user to interact with the computer Most common shells are called bash and tcsh, main differences between shells being syntax and builtin commands Usually commands follow a basic command structure command -options targets Command is sort of a verb and handles the target according to options Linux/UNIX command prompt is case sensitive, so cp command names are usually acronyms of actual words as cp for copy Cp

bergman p.5/23 Directory structure The filesystem is organized in a tree-like hierarchial directory structure The uppermost directory in a filesystem is called the root directory Files have a place in one of the directories (tree branches) Command pwd will show you current working directory bergman@c551 bergman> pwd /wrk/bergman/

bergman p.6/23 Contents of a directory Command ls(list directory) will show the contents of current directory with different switches you can change the output format yourid@c553 linuxkurssi> ls -la drwxr-xr-x 2 bergman csc 1024 Jan 30 15:47. drwxr-xr-x 4 bergman csc 512 Jan 28 15:02.. -rwx------ 1 bergman csc 41988 Feb 1 13:24 a.out type, permissions,links, owner, group, size, date, name of the file

bergman p.7/23 Moving in directory tree Whereas in Graphical user interface you use mouse to navigate through the directories, the cd command is used traverse the directory tree in a command line interface To enter subdirectory inside the current directory cd subdir, for entering parent directory cd.. also explicit path is possible e.g. cd /wrk/userid/new model/

bergman p.8/23 Directory and file handling commands To add a directory mkdir and to remove directory rmdir rmdir will only remove directories without content To remove a file command rm is used can also be used to remove directories with option -r which will erase the directory and all its subrirectories When creating files or directories the special characters are tricky, best to avoid using them e.g.?, -, one should especially avoid functions on most shells,/,? and # since they have special

bergman p.9/23 Moving and copying files For moving files around the filesystem there are few small commands For copying cp -options oldname new(name/dir) to copy entire folder one must use -r option to recurse the folder Also wildcards: all or part of the filename can be substituted with so called wildcards,?,[a-l] For moving or renaming mv -options oldname new(name/folder) Command history up/down arrows to flick through the previous commands If you have started an unwanted program which takes long to complete one can stop a program execution by pressing Ctrl-C

bergman p.10/23 Directory and file permissions All files and directories have a given set of permission attributes The permissions are read, write and/or execute: -rw-r--r-- 1 bergman csc 0 Jan 29 11:04 stuff.txt There are three groups of users The owner, user that has created the file The group, user belongs to at least one group. At CSC, usually group is named after the project leader And the others, that is all other users One can see the users own groups with command groups

bergman p.11/23 Permission adding or removing To change the permission there is command chmod ugo(+/-)rwx to add reading rights to user and group: chmod ug+r chmod +r User can also give permissions to users of these groups to use the files that he/she owns and to change the group of the file chgrp Be careful what permissions you give to other users: If you give write permissions to group others, anyone can destroy your important data Usually there is no need to give write permissions to the group other users

bergman p.12/23 Online help on commands There are many small commands there is also help features in the shell For shell basic utilities you can find help with info command which will give menu of basic utilities which can be browsed with cursor keys info coreutils The man command works for most programs It prints out manual pages for command in question (e.g. man ls)

bergman p.13/23 Linux/UNIX small utilities There are a small utilities that make life a little easier If you have misplaced important file for which you only know the name or part of it. This will find you all files named result yourid@c553:/wrk/yourid> find -name "result" -print For finding text in files yourid@c553:/wrk/yourid> grep pattern file usually you don t want to copy the same file to many different directories. For this purpose it is possible to create symbolic links: ln -s actualfile linkname

bergman p.14/23 Linux/UNIX small utilities continued for selecting columns from a file yourid@c553:/wrk/yourid> cut -f 2-3 file You have a list of names you want sort in alphabethical order? This will sort the lines in a file starting in column m and ending in column n sort -k m-n file For substituting parts of the text in (a) file(s) sed e.g. to change all the words dry to word wet yourid@c553:/wrk/yourid> sed s/dry/wet/g blah.txt One can also create aliases for often used commands alias lo logout

bergman p.15/23 Linux/UNIX redirecting Shells have a possibility to redirect files or output to commands for giving a file instead of reading from keyboard yourid@c553:/wrk/yourid> cat < names.txt for directing output to a file To print all lines that have string House from file names.txt to file house.txt: yourid@c553:/wrk/yourid> grep House names.txt > house.txt to append output to end of a file To add all lines that have string Road to file house.txt yourid@c553:/wrk/yourid> grep Road names.txt >> house.txt

bergman p.16/23 Linux/UNIX pipes It is also possible to redirect output of one program as input to another Almost all commands print result of their actions to standard output which can be redirected to file or as input to other programs using the pipe operator To print out first 10 lines with a string black of the file output.txt: yourid@c553: /testdir> grep black output.txt head [-10]

bergman p.17/23 Reading text files Several programs to printout textfiles: less (and more) printout text a screenful at a time, cat will put all on the screen in one go More and less quite similar programs, only More is a lot more primitive and moving about the document is more complex Less can be controlled with arrow and page up/down keys There is also search option with / -key To print a file to terminal screen use cat [option] file cat can also be used to join text files into one cat file1 file2 file3 > bigfile for splitting up a file there is split split -l 10 file.txt

bergman p.18/23 More on textfiles For printing only a part from the start or end of the file one can use tail/head [option ] file most common option is -n, where n is the number of lines to print by combining these two one can print some intermidiate part of the file head -100 output tail -5 will print lines 95-100 To evaluate the size of textfiles we have wc (wordcount) it will tell you how the number of lines, words and bytes the file or files have: 454 1937 15828 Nutshell.tex For editing there is vi and emacs more on these later

bergman p.19/23 Environment variables The shell stores information about the current system in environment variables similar to variables in programming languages: environment variable is some data that has a name assigned to it They can be essential to the system opreation or for users own needs purposes e.g. $PATH command search path, $HOME home directory, $LPDEST current printer or $IMPORTANT FILES

bergman p.20/23 Environment variables continued To see all current environment variables env They are userdefinable, but to add you must include the current variable to the list of values tcsh:setenv PATH ($PATH /some/new/directory/) bash:export PATH=$PATH:/some/new/directory/ NB! environment variables are used with a $-sign, but are set without

bergman p.21/23 Shell scripting Commands can be written to a text file to create scripts, so it is possible to automate even complex tasks They can be executed using shell-interpreter(sh scriptfile) or by changing file permission to execute Most of the normal programming language constructs are available as e.g If-then-else for conditional branches and for-loops Small example: for f in do.txt echo sorting file $f cat $f sort $f.sorted echo sorted file has been output to $f.sorted done

bergman p.22/23 Config files.emacsrc.bashrc etc. Config files are often called the dot-files for their naming conventions(.config) and stored at the users home directory These can include almost any information from work directory to redefining keyboard commands When logging on the shell will process.login and.bashrc files These are normal script files They include usually environment variables and aliases, advanced users may include many automated tasks to be run when logging on

bergman p.23/23 Small command reference card cd folder move to folder export PRINTER=spoolprint (bash) set environment ls show contents of folder set PRINTER spoolprint (tcsh) variable PRINTER rm remove file find -name foot -print find file with foot in the name cp for copying files env show environment variables rmdir remove directory ln -s file linkname create a link to file mkdir make directory sort file sort lines in file cat concatenate scp secure copy grep print lines with certain string head -n file show n first lines of file chmod change permissions tail -n file show n last lines of file less file show file screenful at a time cut -f n-m file cut columns n to m from file