Essential Linux Shell Commands

Similar documents
CENG 334 Computer Networks. Laboratory I Linux Tutorial

Mills HPC Tutorial Series. Linux Basics I

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

Introduction: What is Unix?

A Brief Introduction to the Linux Shell for Data Science

Introduction to Linux. Fundamentals of Computer Science

Unix Filesystem. January 26 th, 2004 Class Meeting 2

Lecture 3. Unix. Question? b. The world s best restaurant. c. Being in the top three happiest countries in the world.

Examples: Directory pathname: File pathname: /home/username/ics124/assignments/ /home/username/ops224/assignments/assn1.txt

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

Command Line Interface The basics

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

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

Physics REU Unix Tutorial

Linux File System and Basic Commands

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

commandname flags arguments

Python for Astronomers. Week 1- Basic Python

Introduction to UNIX I: Command Line 1 / 21

Files

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

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

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

Introduction to the Linux Command Line

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

I/O and Shell Scripting

CISC 220 fall 2011, set 1: Linux basics

Practical 4. Linux Commands: Working with Directories

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

LOG ON TO LINUX AND LOG OFF

Exploring UNIX: Session 3

The Unix Shell. Pipes and Filters

Working with Basic Linux. Daniel Balagué

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

Windshield. Language Reference Manual. Columbia University COMS W4115 Programming Languages and Translators Spring Prof. Stephen A.

CHAPTER 1 UNIX FOR NONPROGRAMMERS

Lab Assignment #1. University of Pittsburgh Department of Electrical and Computer Engineering

Basic UNIX Commands BASIC UNIX COMMANDS. 1. cat command. This command is used to create a file in unix. Syntax: $ cat filename

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

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

CS246 Spring14 Programming Paradigm Notes on Linux

Introduction to Linux Workshop 1

Outline. Structure of a UNIX command

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

Introduction of Linux

Multiple Choice - 58 Questions - 10 of 15%

COMS 6100 Class Notes 3

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

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

Linux Training. for New Users of Cluster. Georgia Advanced Computing Resource Center University of Georgia Suchitra Pakala

Introduction to Unix - Lab Exercise 0

Week 2 Lecture 3. Unix

genome[phd14]:/home/people/phd14/alignment >

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

Introduction to Unix: Fundamental Commands

Introduction to Linux

CS CS Tutorial 2 2 Winter 2018

SECTION -C. Getting Started with UNIX

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

CENG393 Computer Networks Labwork 1

Week 2. Exp 2 (a) (b): Introduction to LINUX OS, Installation of LINUX OS, Basic DOS commands

Basic Survival UNIX.

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

CS395T: Introduction to Scientific and Technical Computing

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

Unix basics exercise MBV-INFX410

Shell Programming Overview

UNIX File Hierarchy: Structure and Commands

Chapter-3. Introduction to Unix: Fundamental Commands

You will automatically be in your user (home) directory when you login.

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

Crash Course in Unix. For more info check out the Unix man pages -orhttp:// -or- Unix in a Nutshell (an O Reilly book).

A Brief Introduction to Unix

Basic UNIX Commands BASIC UNIX COMMANDS. 1. cat command. This command is used to create a file in unix. Syntax: $ cat filename

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

UNIX Essentials Featuring Solaris 10 Op System

FILE MAINTENANCE COMMANDS

Introduction to the UNIX command line

Introduction to Linux

CSCI 2132 Software Development. Lecture 4: Files and Directories

You should see something like this, called the prompt :

Getting Started With UNIX Lab Exercises

Filesystem and common commands

This is Lab Worksheet 3 - not an Assignment

Connecting to ICS Server, Shell, Vim CS238P Operating Systems fall 18

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

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

Basic UNIX commands. HORT Lab 2 Instructor: Kranthi Varala

Unix Tutorial Haverford Astronomy 2014/2015

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

Subversion FOUR. 4.1 What is Version Control? 4.2 What is Subversion? Types of Version Control SESSION

AOS Linux Tutorial. Introduction to Linux. Michael Havas Dept. of Atmospheric and Oceanic Sciences McGill University. September 15, 2011

The Unix Shell. Permissions

Unix Handouts. Shantanu N Kulkarni

Introduction to Linux for BlueBEAR. January

Practical Session 0 Introduction to Linux

Course 144 Supplementary Materials. UNIX Fundamentals

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

Processes. Shell Commands. a Command Line Interface accepts typed (textual) inputs and provides textual outputs. Synonyms:

Transcription:

Essential Linux Shell Commands Special Characters Quoting and Escaping Change Directory Show Current Directory List Directory Contents Working with Files Working with Directories

Special Characters There are some characters that have special meaning in Unix They should never be used in file or directory names They are & : *? ' " [ ] ( ) $ < > { } # / \! ~ Three other characters, called whitespace, are also special The whitespace characters are o Space o Tab o Newline

Special Characters The Space and Tab characters are used to separate words on the command line They separate the command from its options and its arguments The newline character is what you get when you press Enter on a PC or Return on a Mac The newline character tells the shell you are done typing a command and the shell should run the command you just entered When the shell sees a newline it executes whatever is on the command line

Quoting and Escaping If you need to use a special character on the command line you must do two one of two things o Use quotes o Escape the special character Escaping means putting a backslash, \ in front of a special character to turn off its special meaning You can put backslash character, \ just before the character The backslash must come immediately in front of the special character

Quoting and Escaping The backslash turns off the special meaning of the newline, which is normally to run the command you have typed $ cat foo.txt foo bar bletch $ cat > \ > foo.txt foo bar bletch The backslash turned off the special meaning of the Enter key The shell did not try to execute the command line Instead, it waited for you to finish the command on the next line The second greater than symbol, > is the shell saying it is waiting for more of the command

Quoting and Escaping What if you have many characters to escape? You could put a backslash before each one But, it is probably better to use quotes $ echo >> -bash: syntax error near unexpected token `newline' $ echo \>\> >> $ echo '>>' >> There are two types of quotes o Single quotes - ' ' o Double quotes - " " They have slightly different meanings, but you don't need to worry about the difference for now

cd - Change Directory cd (change directory) changes your current directory You use cd to move from one directory to another cd DIRECTORY_NAME If you use cd with the name of a directory, it moves you to that directory If you use cd without an argument, it takes you to your home directory The home directory is the directory you are in when you first log in to Unix To go up one directory, use.. as the argument for cd cd..

pwd - Show Your Current Directory pwd (print working directory) displays your current directory pwd In the beginning, use pwd every time you use cd This will keep you from getting lost

ls - List the Contents of a Directory ls (list) is one of the most basic Unix commands It shows you the files and directories inside a directory The command line is not a GUI It is easy to lose track of where you are When this happens, certain things will not work as you would expect

ls - List the Contents of a Directory When ls is used without an argument, it lists the contents of your current directory When you use ls followed by the name of a directory, it lists the contents of that directory ls DIRECTORY When you use ls followed by the name of a file, it simply displays the file name

ls - List the Contents of a Directory When used with the -a (for all) option, ls will list all files -- including those whose names begin with a. Any file whose name begins with a. will not show up when you use ls, unless you use the -a option These "invisible" files are configuration files Under normal circumstances, you pay no attention to them We'll discuss these files later in the course

ls - List the Contents of a Directory Another useful option to ls is l which displays a "long" listing $ ls -l total 20 -rw-rw-r-- 1 ghoffmn 103 Sep 11 14:34 basic.css -rw-r--r-- 1 ghoffmn 3560 Aug 29 13:30 emacs_cheat_sheet.html -rw-r--r-- 1 ghoffmn 701 Aug 29 13:30 index.html drwxr-xr-x 6 ghoffmn 512 Sep 15 14:11 it_244 -rw-r--r-- 1 ghoffmn 6831 Aug 29 13:30 tips.html -rw-r--r-- 1 ghoffmn 6052 Aug 29 13:30 unix_cheat_sheet.html (NOTE: This is the lowercase letter l, not the number 1. Do not get them confused!) We'll talk about this more when we discuss permissions

cat - Print the Contents of a File cat (concatenate) displays the contents of a file $ cat foo.txt foo bar blecth

cat - Print the Contents of a File When used with the -n option cat displays line numbers $ cat -n lines.txt 1 line 1 2 line 2 3 line 3 4 line 4 5 line 5 6 line 6 7 line 7 8 line 8 9 line 9 10 line 10

cat - Print the Contents of a File If you run cat on a long file, the contents of the file will pass by too quickly to read To view long files, you should use a paging program Paging programs, like more and less, show the content of a file one screenful at a time You can navigate using arrows, the space bar, and other keys on your keyboard I'll discuss them more in a future class

rm (remove) deletes a file rm FILENAME rm - Delete a File rm does not ask you if you are sure before deleting the file There is no undelete feature in Unix Deleted files cannot be recovered, if not backed up Don't delete a file, unless you are sure you won't need it

rm - Delete a File To remove all the files in a directory use rm * Be careful when using * with rm It will delete everything, and there is no way to get back what was deleted

rm - Delete a File If you run rm with the -i option, it will ask you before deleting each file rm -i foo.txt rm: remove regular file `foo.txt'? y [Enter] It's good idea to use this option when running rm * rm cannot be used on a directory -- unless you use the -f or "force" option

mkdir - Create a Directory Directories o mkdir (make directory) creates a directory mkdir DIRECTORY_NAME o The directory will be created in the current directory, unless you specify another location rmdir - Delete a Directory o rmdir (remove directory) deletes a directory rmdir DIRECTORY_NAME o rmdir will not work on a directory, unless the directory is empty

cp - Copy Files cp (copy) makes a copy of a file or a directory cp takes two arguments o The first argument is the source - the file or directory to be copied o The second argument is either the new filename, if you are making a copy in the same directory or the directory into which the copy will go cp FILENAME NEW_FILENAME_OR_DIRECTORY cp can copy an entire directory -- when used with the -r (for recursive) option

mv - Move a File or Directory mv (move) is a command that does two different things It can change the location of a file or directory mv FILENAME_OR_DIRECTORY_NAME NEW_DIRECTORY It can also change the name of a file or directory mv FILE_OR_DIR_NAME NEW_FILE_OR_DIR_NAME In either case, mv takes two arguments

mv - Move a File or Directory When used to move something, the first argument is thing to be moved, and the second argument is the new location $ ls foo.txt it244 work $ ls work $ mv foo.txt work $ ls it244 work $ ls work foo.txt

mv - Move a File or Directory When changing the name of a file or directory, the first argument is the old name, and the second is the new name $ ls foo.txt hold it244 work $ mv foo.txt bar.txt $ ls bar.txt hold it244 work