ULSTER COUNTY COMMUNITY COLLEGE CIS 116Linux (Part 2) First CommandsKarl Wick.

Slides:



Advertisements
Similar presentations
RH030 Linux Computing Essentials
Advertisements

RH030 Linux Computing Essentials
Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
การใช้ระบบปฏิบัติการ UNIX พื้นฐาน บทที่ 4 File Manipulation วิบูลย์ วราสิทธิชัย นักวิชาการคอมพิวเตอร์ ศูนย์คอมพิวเตอร์ ม. สงขลานครินทร์ เวอร์ชั่น 1 วันที่
Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision.
CIS 118 – Intro to UNIX Shells 1. 2 What is a shell? Bourne shell – Developed by Steve Bourne at AT&T Korn shell – Developed by David Korn at AT&T C-shell.
Chapter One The Essence of UNIX.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
Lab6 CPCS361 I.Mona Alshehri. Working with Files and Directories Creating files Create a file with the cat command type the command cat > name_of_file.
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
Chapter 5 Accessing Files and Directories. How Directories Get Created OS installation: usr, dev, etc, export, kernel and others places to store installation.
UNIX Chapter 00 A “ Quick Start ” into UNIX Operating System Mr. Mohammad Smirat.
Guide To UNIX Using Linux Third Edition
Chapter 6 Basic Directory and File Management. Command Line Control Characters Control-s - Stops screen output - rarely used Control-q - Resumes screen.
Introduction to Linux and Shell Scripting Jacob Chan.
7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE1 Unix Comp-145 C HAPTER 2.
L INUX C OMMAND L INE I NTERFACE G UNAANBAN.G
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
Linux Installation and Administration Lesson 2 Tutor: George Papamarkos.
Using the “CLI” Unix / Linux Preparation Course May 25 Djibouti.
COMP1070/2002/lec4/H.Melikian COMP1070 Lecture #5  Files and directories in UNIX  Various types of files  File attributes  Notion of pathname  Commands.
Ch 51 Internal Commands COPY and TYPE. Ch 52 Overview Will review file-naming rules.
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
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.
Ch 21 Command Syntax Using the DIR Command with Parameters and Wildcards.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
File Processing. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash facilities.
Unix Basics Chapter 4.
The UNIX Shell. The Shell Program that constantly runs at terminal after a user has logged in. Prompts the user and waits for user input. Interprets command.
Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems.
Linux+ Guide to Linux Certification, Third Edition
The Shell Chapter 7. Overview The Command Line Standard IO Redirection Pipes Running a Program in the Background Killing (a process!)
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.
1 Day 5 Additional Unix Commands. 2 Important vs. Not Often in Unix there are multiple ways to do something. –In this class, we will learn the important.
Guide to Linux Installation and Administration, 2e1 Chapter 7 The Role of the System Administrator.
Week 3 Exploring Linux Filesystems. Objectives  Understand and navigate the Linux directory structure using relative and absolute pathnames  Describe.
Linux Operations and Administration
1 Operating Systems and Using Linux Topics What is an Operating System? Linux Overview Frequently Used Linux Commands Some content in this lecture added.
Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will.
Lesson 2-Touring Essential Programs. Overview Development of UNIX and Linux. Commands to execute utilities. Communicating instructions to the shell. Navigating.
Using Commands Unix / Linux Preparation Course May 6, 2012 Serrekunda, The Gambia.
BIF713 Basic Unix/Linux Commands Getting Help with Commands.
Chapter Five Advanced File Processing. 2 Lesson A Selecting, Manipulating, and Formatting Information.
Unix Commands PowerPoint Presentation developed for LS 560 Information Technology online class - University of Alabama by Debey Sklenar TENacious Cohort.
Ch 91 Pipes, Filters and Redirection. Ch 92 Overview Will use redirection to redirect standard input and standard output.
Introduction to Programming Using C An Introduction to Operating Systems.
Manage Directories and Files in Linux Part 2. 2 Identify File Types in the Linux System The file types in Linux referred to as normal files and directories.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: which, passwd, date, ps / kill Working with Files: file, touch, cat, more, less, grep,
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 2a – A Unix Command Sampler (Courtesy of David Notkin, CSE 303)
Using the “CLI” Unix / Linux Preparation Course June 9, 2013 Lusaka, Zambia.
Linux Commands C151 Multi-User Operating Systems.
File and Folder CLI Commands 12/24/ Agenda Overview of OS functions and the SHELL Internal v External Commands Command History Making & Modifying.
Chapter 5: The Shell The Man in the Middle. In this chapter … The command line Input, output, and redirection Process management Wildcards and expansion.
1 Lecture 2 Working with Files and Directories COP 3353 Introduction to UNIX.
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
Lecture 02 File and File system. Topics Describe the layout of a Linux file system Display and set paths Describe the most important files, including.
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
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.
Lesson 5-Exploring Utilities
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
Some Linux Commands.
C151 Multi-User Operating Systems
Linux Shell Script Programming
Presentation transcript:

ULSTER COUNTY COMMUNITY COLLEGE CIS 116Linux (Part 2) First CommandsKarl Wick

The Command Interpreter - Bash  From man: Bash is (a) … command language interpreter that executes commands read from the standard input (the keyboard) or from a file.  A blank character is used to separate words and redirections. The first word specifies the command to be executed. (The remaining words are treated as parameters.)

Reserved Words Reserved words have special meaning to the Bash shell;  casedoelif  elseesacfi  forfunctionif  inselectthen  untilwhile{}  time[[ ]]  ! |<>

bash – Command Line Syntax

bash – Rules of Syntax

Naming Comventions  A file name may contain up to 256 characters.  _, -,. are allowed. Other characters are also allowed but not recommended because they may be OS command characters.  File name extensions are preceded by a dot (.) and may contain from 1 to 3 characters  Directory names may use extensions buy generally do not.

Man(ual) q exits man  The most important Linux command is man pagename  man opens the manual for the page (or command specified).  Navigation: – moves forward – moves backward – exits the manual  Type man man

Print man pages  with man command | col -b | lpr  Type !lpr filename (text pg 85)  Note: This only works if a printer is attached and configured.

Swapping user account  Remember that the # prompt means that you are logged in as root. The $ prompt means that we are logged in as user.  Usually it is dangerous to be logged on as root, and sometimes it is essential.  We can switch user levels with the su command.  sulog into root with your own shell  su -log into root with its shell (better)  su – name log into name account  su – student  su - root

Where am I? pwd  With Linux’s extended tree hierarchy it is very easy to get lost.  The pwd command stands for “print working directory” and will tell you the complete directory path that you are in. –cd /etccd sounds cd events  The command prompt shows only the lowest level directory. events]#  pwd shows: /etc/sound/events

Changing the Active Directory  cd is the magic command –cd (alone) returns you to your home directory –cd with a path name will (may) take you there –There are two ways of specifying the path Absolute Relative

Absolute vs Relative Pathnames  A path is absolute if it specifies the entire path name. An absolute path begins with / which is the name for the top directory.  A path is relative if it specifies where to go from the present directory  cd /etc/sounds/events is absolute  if we are already in /etc we can type cd sounds/events

Some special paths .Stay in current directory ..Move up one level  …Move up two levels  / is the top directory  /home is the normal user directory  /rootis the root directory

Options for the cd command CommandFunction cdreturn to login directory cd ~return to login directory cd /go to system top directory cd /rootgo to root directory cd /homego to users home directory cd..move up one level cd ~otherusergo to his login dir if permitted cd /dir1/subdirabsolute path cd../../dir3/X11up two levels, then down to X11

An experiment  Make sure that you are logged in as student  (if not then type su – student) and you will be.  Type cd /root –You will get a message “Permission denied”  Change to root (su – root, then type pw)  Now you are in the /root directory.  The root directory is protected.

List the directory with ls  Type ls from the root directory  You will see a few entries –Blue means a folder –Grey means a file –Green means special items  Type cd /  Type ls again  You now see many folders here including root and home  Just like with DOS, ls may not show everything in the directory.

ls options  Type man lsWhen done type q –There are many options listed –We will use a few  These many options allow us to sort the information displayed to best meet our needs.  With options we can –Specify HOW files are displayed –See file permissions –See other file attributes

ls options practice  Go back to the root directory cd  Type ls again and note the output  Now type ls –a and note the output again –Are they the same?  You should see more files or folders. These inculde. and..  All of the new files may begin with dots (.)  These are hidden files (“dot” files).  Try ls –A (all but implied {. and..})

Even more information  ls and ls –a give names only.  We can also look at details. Use the l(ong) option;  ls –l Now we see a lot more information  Many files are still missing.  Try typing ls –al (this combines options) –the output may scroll off of the screen –ls –al | more

Useful ls Options Chart -aall – list all files, including hidden -llong – detailed: permissions, owner, etc. -Ffile type - *=executable -rreverse – Back to front -RRecursive – all dirs current and lower -SSize – sorts files by size

Finding files and directories  Sometimes you know that a file or directory exists but you cannot recall the exact location on the disk  The commands locate filename and slocate filename will find a file or directory.  slocate only lets you find files and folders that you have permission to access.  Format is locate [-options]  Example locate finger

The cron daemon  The locate command finds names from a database created by a daemon called cron.  (Daemons handle background tasks)  The database is called slocate  cron updates the database nightly if the system is running. If you shutdown after using the system cron rarely has a chance to update slocate.

Updating slocate  As we’ve already mentioned, cron updates the slocate datebase nightly, but only if Linux is up.  We can force an update by entering the command updatedb at the root prompt (only root can run this utility).  The update takes a minute or two depending on the number of files and speed of the system.

Clearing the Window  By now you must be getting tired of clutter filling your screen and the cursor appearing only at the very bottom.  Just like DOS, Linux has a clear screen command.  In DOS the command was CLS,  In Linux the command is clear

Listing the Contents of a File  Remember all files are text files unless otherwise specified  In Linux, there are several ways displaying the contents of a text file.  The commands are;  cat is the most versatile and also has other useful functions. Sometimes this can get us into trouble. cat moreless headtail

cat  cat is short for ‘concatenate’ – meaning ‘to connect files together in order’  cat will display an existing file  cat will create a new file if the name is not already taken  cat uses the standard input and output devices unless you specify otherwise.

Standard Input & Output  The standard input device is the keyboard  The standard output device is the monitor  Type cat –The cursor moves to a blank line –Type “Stop at the music store.”  cat echoed the string to the screen  To quit cat, move the cursor to a blank line and press. The command prompt will reappear.  cat works a lot like the DOS ECHO command.

Redirection  Redirection means directing the shell to get input or send output to/from somewhere other than the standard devices.  The > symbol redirects output  The < symbol redirects input  Placing > after any command that generated output will send the output to that location (often a file)

cat and Redirection  Type cat > roadtrip.txt and then  now type these lines (all followed by ) –Buy some CDs –Then visit the coffee shop –Buy some coffee –Go home, drink coffee and listen to CDs  At a blank line type  The command prompt should reappear.  The four lines that we typed did NOT appear on the screen. Instead, they were sent to a file called roadtrip.txt

cat with Redirection – continued  Type ls. you will see the new file listed.  Read the file by typing cat roadtrip.txt  NOTE: Be careful using cat to create a new file because it will replace existing files with the same name without prompting.

cat with Redirection – continued  Create another file called part2.txt  cat > part2.txt –Make supper –Watch the news –Do homework   ls  cat part2.txt

Concatenation with cat  Let us now join our two files into a third file by using the cat command  cat roadtrip.txt part2.txt > saturday.txt  ls  cat saturday.txt  What do you see on the screen?  cat has appended the second file’s contents to the first file.  Format is cat file1 file2 … filen > destination  cat can use any number of input files.

Appending information  The special character > redirects information to a file  The special character >> appends information to the end of a file.  Type cat part2.txt >> roadtrip.txt  cat roadtrip.txt  roadtrip now contains its original text plus the text of part2 at its end.

Appending information  CAUTION! –Be careful to use the doubled >> when appending information. If you accidentally use the single > you will replace your output file instead of adding information to it!

Make a larger file  cat > longfile.txt  Type the numbers 1 through 50 one to a line.   cat longfile.txt - The output scrolls off of the screen.  How can we display this file and see all of it?

more  The more command lets us display long files one page at a time with a pause for a keypress between pages.  Type more longfile.txt –At the bottom of the screen you see --More--(35%)  Press the enter key – the text moves up one line  Press the space bar – the text moves up one page  More is similar to the DOS command MORE  You CANNOT scroll back up!

less  less does what more does only more.  less will display a file and will let you scroll up and down with the arrow, page up, page down, b, enter and spacebar keys.  See man for more options.  less longfile.txt  While more exits automatically at the end of a file, you must exit less by pressing the q key.

head and tail  head filename will display the first ten lines of a file on the output device.  tail filename will display the last ten lines of a file on the output device.  head longfile.txt  tail longfile.txt  These commands let us take a quick at the beginning or ending of a file to see what kind of information it contains.  head –20 displays 20 lines, etc.

Redirection with pipes  Pipes connect the standard output of one command to the standard input of another command.  Type ls –al /etc  The information scrolls off of the screen  Type ls –al /etc | less  Remember all of those messages during the boot process?  Type dmesg | less to see them.

Finding character strings  The grep command will find specific strings of characters within files  grep searches are case sensitive  the –i option makes the search case insensitive. (grep –i string filename)  grep coffee saturday.txt will show every line containing the word coffee.  grep can redirect its output into a file for later review grep buy part2.txt | review

Wildcards  * matches any string including null string  ? matches any single character  \* matches the * character  \? matches the ? character  […] matches any one of the enclosed characters. A pair of characters separated by a dash indicates a range of characters.  [A-z] means match all letters  If the first character is ! or ^ then any character NOT enclosed is matched.

wc-Word Count  wc [options] filename  The generic version shows –number of lines –number of words –number of bytes  wc longfile.txt

diff- Comparing two files  The diff command compares two text files and finds the differences between them.  diff [option] file1 file2 –The –l option treats all letters as lower case –The –c option gives a very detailed comparison

Command History  Linux stores a list of recently issued commands in a file called.bash_history. By default bash stores up to 500 (1000) commands.  You can review these commands in reverse order by typing the up arrow.  You can view the file with more, less, et.al.  Typing env will show the size of the file.

Tab Completion  You can type part of a simple command and then and bash will complete the command or beep.  If it beeps just hit tab again for a list of all commands beginning with what you typed.  m  mo

Multiple commands on a single line  ; separates commands  cat roadtrip.txt; cat saturday.txt will display BOTH files on the screen.

DOS/UNIX Cross Reference DOSUNIXFunction DIRlslist directory contents CDpwdshow working directory CDcdchange working directory MDmkdirmake new directory RDrmdirremove directory DELrmRemove file(s) COPYcpcopy file RENmvmove/rename file TYPEcatdisplay file (cat does more) SORTsort sort file MOREmoredisplay file with pause CLSclearclear screen DATEdateDisp date (and time) EDITvi/emacsBuilt in editors HELPmanhelp files VERuname –aOS info (and more)

Special Key Combinations Stop screen output Resume screen output Stop current activity or process Exit or End of File Erase last word Erase entire line

Back to the regular book Now that we have a good grasp of the basic operation of Linux let us explore our text book.