The Directory Structure

Similar documents
INSE Lab 1 Introduction to UNIX Fall 2017

UNIX Tutorial Two

Scripting Languages Course 1. Diana Trandabăț

UNIX Tutorial One

Parts of this tutorial has been adapted from M. Stonebank s UNIX Tutorial for Beginners (

A Short Introduction to UNIX Operating System

Mills HPC Tutorial Series. Linux Basics I

Unix Tutorial Haverford Astronomy 2014/2015

Chapter Two. Lesson A. Objectives. Exploring the UNIX File System and File Security. Understanding Files and Directories

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

Unix tutorial. Thanks to Michael Wood-Vasey (UPitt) and Beth Willman (Haverford) for providing Unix tutorials on which this is based.

Operating Systems and Using Linux. Topics What is an Operating System? Linux Overview Frequently Used Linux Commands

1 Getting Started with Linux.

Lab Working with Linux Command Line

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

5/8/2012. Creating and Changing Directories Chapter 7

Unix File System. Class Meeting 2. * Notes adapted by Joy Mukherjee from previous work by other members of the CS faculty at Virginia Tech

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

Getting Started with Command Prompts

PDS Lab Section 16 Autumn Tutorial 1. Unix Commands pwd The pwd command displays the full pathname of the current directory.

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

Introduction to Unix: Fundamental Commands

Unix Filesystem. January 26 th, 2004 Class Meeting 2

Introduction. File System. Note. Achtung!

Linux/Cygwin Practice Computer Architecture

CSE115 Lab exercises for week 1 of recitations Spring 2011

Introduction to Unix - Lab Exercise 0

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:

Overview of the UNIX File System. Navigating and Viewing Directories

Introduction to the Linux Command Line

CSCI 2132 Software Development. Lecture 4: Files and Directories

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

Overview of the UNIX File System

CENG 334 Computer Networks. Laboratory I Linux Tutorial

Getting Started With UNIX Lab Exercises

Chapter-3. Introduction to Unix: Fundamental Commands

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

Unix Basics. Systems Programming Concepts

Introduction to the UNIX command line

Tutorial 1: Unix Basics

Command Line Interface The basics

CMSC 104 Lecture 2 by S Lupoli adapted by C Grasso

Unix background. COMP9021, Session 2, Using the Terminal application, open an x-term window. You type your commands in an x-term window.

Refresher workshop in programming for polytechnic graduates General Java Program Compilation Guide

Files

Basic Survival UNIX.

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]

CHAPTER 1 UNIX FOR NONPROGRAMMERS

Common UNIX Commands. Unix. User Interfaces. Unix Commands Winter COMP 1270 Computer Usage II 9-1. Using UNIX. Unix has a command line interface

Essential Linux Shell Commands

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

Operating Systems. Copyleft 2005, Binnur Kurt

Operating Systems. Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000) alphapeeler.sf.net/pubkeys/pkey.htm

CS Fundamentals of Programming II Fall Very Basic UNIX

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

Lab 1 Introduction to UNIX and C

Introduction to Linux. Fundamentals of Computer Science

Oxford University Computing Services. Getting Started with Unix

Linux & Shell Programming 2014

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

You should see something like this, called the prompt :

Using the Unix system. UNIX Introduction

Multiple Choice - 58 Questions - 10 of 15%

Using the Zoo Workstations

Unit 10. Linux Operating System

Introduction to Linux

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

This is Lab Worksheet 3 - not an Assignment

Physics REU Unix Tutorial

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

A Brief Introduction to the Linux Shell for Data Science

UNIX files searching, and other interrogation techniques

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

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 Linux Environment. Yun-Wen Chen

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

The Shell. EOAS Software Carpentry Workshop. September 20th, 2016

Getting Started with UNIX

Week Overview. Unix file system File types and file naming Basic file system commands: pwd,cd,ls,mkdir,rmdir,mv,cp,rm man pages

Tiny Instruction Manual for the Undergraduate Mathematics Unix Laboratory

DATA 301 Introduction to Data Analytics Command Line. Dr. Ramon Lawrence University of British Columbia Okanagan

Why learn the Command Line? The command line is the text interface to the computer. DATA 301 Introduction to Data Analytics Command Line

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

Introduction to Linux Workshop 1

COSC UNIX. Textbook. Grading Scheme

UNIX Quick Reference

Commands are in black

Unix Introduction. Part 2

UNLV Computer Science Department CS 135 Lab Manual

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.

Advanced Linux Commands & Shell Scripting

Linux Command Line Primer. By: Scott Marshall

1) Introduc,on to unix command line and perl. Ma5 Webster IMBIM, BMC

Part I. Introduction to Linux

Std: XI CHAPTER-3 LINUX

Lecture 2: Tools & Concepts

CS 3410 Intro to Unix, shell commands, etc... (slides from Hussam Abu-Libdeh and David Slater)

Chapter 2 Text Processing with the Command Line Interface

Unix File System. Learning command-line navigation of the file system is essential for efficient system usage

Transcription:

The Directory Structure All the files are grouped together in the directory structure. The file-system is arranged in a hierarchical structure, like an inverted tree. The top of the hierarchy is traditionally called root (written as a slash /) In the diagram above, we see that the home directory of the undergraduate student "ee51vn" contains two sub-directories (docs and pics) and a file called report.doc. The full path to the file report.doc is "/home/its/ug1/ee51vn/report.doc"

Starting a UNIX Terminal To open an UNIX terminal window, click on the "Terminal" icon from Applications/Accessories menus. An UNIX Terminal window will then appear with a % prompt, waiting for you to start entering commands.

Listing files and directories ls (list) When you first login, your current working directory is your home directory. /home/user To find out what is in your home directory, type % ls The ls command ( lowercase L and lowercase S ) lists the contents of your current working directory. There may be no files visible in your home directory, in which case, the UNIX prompt will be returned. Alternatively, there may already be some files inserted by the System Administrator when your account was created. ls does not, in fact, cause all the files in your home directory to be listed, but only those ones whose name does not begin with a dot (.) Files beginning with a dot (.) are known as hidden files and usually contain important program configuration information. They are hidden because you should not change them unless you are very familiar with UNIX!!! To list all files in your home directory including those whose names begin with a dot, type % ls -a As you can see, ls -a lists files that are normally hidden.

ls is an example of a command which can take options: -a is an example of an option. The options change the behaviour of the command. There are online manual pages that tell you which options a particular command can take, and how each option modifies the behaviour of the command. Making Directories mkdir (make directory) We will now make a subdirectory in your home directory to hold the files you will be creating and using in the course of this tutorial. To make a subdirectory called unixstuff in your current working directory type % mkdir directoryname Example a. To create a folder temp in the /home/user folder $ /home/user/mkdir temp $ ls

Changing to a different directory cd (change directory) The command cd directory means change the current working directory to 'directory'. The current working directory may be thought of as the directory you are in, i.e. your current position in the file-system tree. To change to the directory you have just made, type % cd temp $ /home/user/cd temp $ pwd $ ls The parent directory (..) (..) means the parent of the current directory, so typing % cd.. will take you one directory up the hierarchy (back to your home directory). Pathnames pwd (print working directory) Pathnames enable you to work out where you are in relation to the whole file-system. For example, to find out the absolute pathname of your home-directory, type cd.. to get back to your home-directory and then type % pwd The full pathname will look something like this - /home/its/ug1/ee51vn which means that ee51vn (your home directory) is in the sub-directory ug1 (the group directory),which in turn is located in the its sub-directory, which is in the home sub-directory, which is in the top-level root directory called " / ".

More about home directories and pathnames Understanding pathnames $ /home/user is the current directory $ mkdir beta $ ls beta Now to list the contents of a folder temp in the /home/user/temp from the /home/user/beta Note: current folder is /home/user/beta $ ls /home/user/temp ~ (your home directory) Home directories can also be referred to by the tilde ~ character. It can be used to specify paths starting at your home directory. So typing % ls ~/ will list the contents of your user directory, no matter where you currently are in the file system.

Copying Files a. Create a folder or directory( named temp) in /home/user b. Create a file science.txt in /home/user cp (copy) cp file1 file2 is the command which makes a copy of file1 in the current working directory and calls it file2 What we are going to do now, is to take a file stored in /home/user/temp, and use the cp command to copy it to your /home/user directory. Navigate to the temp directory inside the /home/user % cd ~/temp Then at the UNIX prompt, type, % cp /home/user/science.txt. Note: Don't forget the dot. at the end. Remember, in UNIX, the dot means the current directory. The above command means copy the file science.txt to the current directory, keeping the name the same. Moving Files mv (move) mv file1 file2 moves (or renames) file1 to file2 To move a file from one place to another, use the mv command. This has the effect of moving rather than copying the file, so you end up with only one file rather than two. It can also be used to rename a file, by moving the file to the same directory, but giving it a different name.

Example: a. Create a folder store in /home/user b. Create another folder temp in /home/user ( If folder temp already exists, then use it) c. Create a file science.txt in /home/user/temp folder d. Use ls l command to check the folder contents e. Now use the following command to move the science.txt from /home/user/temp to /home/user/store (Execute this command in the /home/user folder) $ mv ~/temp/science.txt ~/store (Execute this command from the target folder) $ mv ~/temp/science.txt. (here. refers to the current folder) Removing Files and Directories rm (remove) rmdir (remove directory) To delete (remove) a file, use the rm command. Example ( rm filename) a. Create a file science.txt in the /home/user/temp folder b. Copy the science.txt to temp.txt in the same folder $ cp science.txt temp.txt $ ls ( to list and verify ) c. Now delete the file temp.txt $ rm temp.txt $ ls( to list and verify) Example (rmdir directory) a. Create a folder alpha in the /home/user b. List and verify the folder has been created ( ls l) c. Now remove the alpha folder using the following command $ rmdir alpha Now use the ls command and verify the folder has been deleted or not.

Clear Screen At the prompt, type % clear This will clear all text and leave you with the % prompt at the top of the window cat The command cat can be used to display the contents of a file on the screen. Type: % cat science.txt As you can see, the file is longer than the size of the window, so it scrolls past making it unreadable. less The command less writes the contents of a file onto the screen a page at a time. Type % less science.txt Press the [space-bar] if you want to see another page, and type [q] if you want to quit reading. As you can see, less is used in preference to cat for long files. head The head command writes the first ten lines of a file to the screen. First clear the screen then type % head science.txt Then type % head -5 science.txt tail The tail command writes the last ten lines of a file to the screen.

Clear the screen and type % tail science.txt Searching the contents of a file Simple searching using less Using less, you can search though a text file for a keyword (pattern). For example, to search through science.txt for the word 'science', type % less science.txt then, still in less, type a forward slash [/] followed by the word to search /science As you can see, less finds and highlights the keyword. Type [n] to search for the next occurrence of the word. grep It searches files for specified words or patterns. First clear the screen, then type % grep science science.txt As you can see, grep has printed out each line containg the word science. % grep Science science.txt The grep command is case sensitive; it distinguishes between Science and science. To ignore upper/lower case distinctions, use the -i option, i.e. type % grep -i science science.txt To search for a phrase or pattern, you must enclose it in single quotes (the apostrophe symbol). For example to search for spinning top, type % grep -i 'spinning top' science.txt Some of the other options of grep are:

-v display those lines that do NOT match -n precede each matching line with the line number -c print only the total count of matched lines Try some of them and see the different results. Don't forget, you can use more than one option at a time. For example, the number of lines without the words science or Science is % grep -ivc science science.txt wc (word count) A handy little utility is the wc command, short for word count. To do a word count on science.txt, type % wc -w science.txt To find out how many lines the file has, type % wc -l science.txt Wildcards The * wildcard The character * is called a wildcard, and will match against none or more character(s) in a file (or directory) name. For example, in your unixstuff directory, type % ls list* This will list all files in the current directory starting with list... Try typing % ls *list This will list all files in the current directory ending with...list

The? wildcard The character? will match exactly one character. So?ouse will match files like house and mouse, but not grouse. Try typing % ls?list On-line Manuals There are on-line manuals which gives information about most commands. The manual pages tell you which options a particular command can take, and how each option modifies the behaviour of the command. Type man command to read the manual page for a particular command. For example, to find out more about the wc (word count) command, type % man wc Alternatively % whatis wc gives a one-line description of the command, but omits any information about options etc. Apropos When you are not sure of the exact name of a command, % apropos keyword will give you the commands with keyword in their manual page header. For example, try typing % apropos copy