Introduction To Unix- CS 21

Introduction To Unix- CS 21

Introduction to Unix CS 21 Lecture 4 Lecture Overview * cp, mv, and rm Looking into files

The file command head and tail cat and more What weve seen so far Homework and Quiz Homework #1 now available at

Due next Thursday (January 20th) at the beginning of class Quiz #1 next Thursday (January 20th) Everything covered up through today will be fair game Homework assignments, lab assignments, reading assignments, and

lecture material The First Wildcard * (asterisk) Wildcards are just like wild cards in poker They can be anything (within reason)

In Unix, this means that * can be replaced by anything in the current directory * actually gets replaced by everything in the current directory Example Of * Usage Why Is This Useful? At first glance, this doesnt seem to mean much

After all, ls without the * will list all the files anyway You can specify a little more than every file *.txt will match all files that end in .txt Example Of Advanced * Usage Moving Files Around

There are a couple of essential commands to move files around cp mv Remember, you can use touch to create an empty file to play around with

cp Usage The cp command makes a copy of a file Usage: cp OLDFILE NEWFILE Examples Of cp Problems With cp? Commonly Used Flags

With cp -i flag Asks if you want to write over a file that already exists -r flag Recursively will copy all files and

subdirectories What Does Recursion Mean? The same program gets called over and over again In this context, cp gets called on all files in all subdirectories Parent directories and other files

above the current directory are not affected A Graphical Representation Of Recursion cp r /usr ~/temp / /home /usr

~/temp /usr/bin ~/temp/usr /usr/misc /usr/zzz Keep In Mind All Of The Permissions You will only be able to copy a file

that you have read permission on You will only be able to create a file in a directory that you have write permission in mv Usage The mv command will move a file from one location to a new location Usage: mv OldFile NewFile You can also think of this as a

rename command Examples Of mv How Does This Compare To Windows? Windows will let you drag and drop files from one location to another

Right click if you would like to copy A little progress bar shows up animating the file being moved over to the new folder Other than that, it is exactly the same rm Usage The rm command will remove a file

This doesnt normally include directories Usage: rm filename Examples Of rm Commonly Used Flags -i

-f Verify the delete Force the removal of a file If you have permission, the file is gone, regardless of any warnings that might pop up Yeah, yeah, just do it Overrides the i flag

-r Recursively delete files Dangers Of rm Unix Is missing something you are probably used to rm is probably one of the most

dangerous commands in Unix Once Its Gone, Its Gone There is no way to get a file that has been removed back Only run rm if you are absolutely sure you want to remove a file The i flag provides a little protection

Prompts the user if they are really sure they want to delete the file Extreme Dangers Of rm rm rf ~ rm rf /

Say Bye, bye to your home directory You wont have permission to delete much, but If you are root, say goodbye to the entire system! rm rf . rm rf * Dont look as dangerous, but you have to be

absolutely certain you know where youre at So Why Use rm rf Then? The most destructive command in Unix, why would you ever want to use it? Just so happens that you WILL want to remove large portions of your files at some time (most likely many times)

Much easier to run rm rf than delete each file individually Avoiding The Dangers Of rm The best way is to make sure you are always using the i flag and only use f when you are certain Always check where your current

directory is so you dont delete the wrong file Make copies of important files just in case Unix, The Multichoice OS Whats the difference? rm rf subdirectory/ rmdir subdirectory/

Multichoice Again Whats the difference? mv fileA fileB cp fileA fileB rm fileA Examining Files Closer As previously stated, everything in

Unix is a file But different files have different uses How do you tell what type a file is? Example: In Windows, a *.doc file is a Word Document No such restriction is enforced in Unix A *.doc file might even be an executable!

The file Command A helpful command to get you started in your quest for knowledge: file Checks the first few bytes of the file in question and takes its best guess as to what type of file it is Sometimes file gets it wrong, but

most of the time it is pretty good Example Different Types Of Files What If I Want To Actually Look Inside The File Myself? If the file is a text file, several options exist

head tail cat more If the file is a binary (executable), you dont want to read it! (trust me) The head Command

Print out the first few lines of a text file 10 by default Provides a quick way to see if this is the file youre looking for Doesnt bombard you with a million

line file scrolling off the screen Usage: head FILE Common Flags For The head Command -6 Only print out the first 6 lines Actually, any number works here the

same way What counts as a line? Everything up until the new line terminator Examples Of head Usage The tail Command Pretty much the opposite of head Prints out the last few lines of a file

10 by default Usage: tail FILE Just like head, -NUM Prints out the last NUM lines Examples Of tail Usage

The cat Command The cat command will print out an entire file to the screen Usage: cat FILE Cat? Short for concatenate This command can be used to print out

multiple files one right after the other cat FILE1 FILE2 Problem With cat If the file is very large, it will scroll off the screen too fast to read No way to read a scrolling file without stopping the program

Cntrl-C will kill a running program The more Command Works exactly like cat, but doesnt automatically scroll the screen Usage: more FILE This is the first truly interactive program weve seen

You can control how the program runs while it is running More Example How do you scroll to the next screen? Hit the space bar Advanced more usage

Return will move you one line NUM followed by return will move you NUM lines Example: 5 [Return] displays the next 5 lines q will quit more without finishing less Is more

A better version of more exists: less Allows all of the same options as more Allows easier moving through the file Arrow keys and page up, page down will move you both forward and backward

Which you choose to use is, of course, up to you What About Binary Files? You Now Should Have Enough Info To Cause Some Damage You now have the ability to:

Wander about the system Create simple files and change all the properties of these files Copy and move files around Check out what type of files you are looking at and read the interesting ones Delete files you no longer want The Class So Far

History of Unix and the hacker connection Logging on and getting help man Environment variables The Unix Directory Structure

ls cd pushd and popd Relative and absolute pathnames . And .. Class Summary Continued Disk usage

du Compressing files Symbolic Links Ownership and permissions chmod umask

The Class So Far Continued Moving files cp mv Checking the contents and type of

files file head and tail cat and more In Lab Today You will practice setting permissions and the effect they have

chmod and umask Start creating simple files and moving them around the system Read files using head, tail, cat, and more Next Week

Things really start to get interesting as we start getting programs to work together and tie everything together Well look at more uses of wildcards and start making Unix sentences with pipes and filters Well look at the oddly named but strangely powerful command: grep

Recently Viewed Presentations

  • Man, manu - Jefferson School

    Man, manu - Jefferson School

    Root word: man, manu = hand Prefix: post = after. To set free; to lend a hand in freeing someone. Emancipate (v) handcuffs. Manacles (n) A person who has the upper hand; the person in charge . Manager (n) An...

    Current Events Update. OECD Countries Pulled Back the Gender Gap in Education. The Organization of Economic Co-operation and Development (OECD) is an IGO that has been working on reaching gender equality, education was included as one of the factor
  • Physics 311A Special Relativity - UW Courses Web Server

    Physics 311A Special Relativity - UW Courses Web Server

    y x t Light cone - partition of spacetime Why "partition"?.. y past future absolutely elsewhere NOW Partitions of spacetime Light cone preserves cause and effect. If Event 2 was caused by Event 1 in some reference frame, it will...
  • Bioinformatics  NSF Summer School 2003 Z. Luthey-Schulten, UIUC

    Bioinformatics NSF Summer School 2003 Z. Luthey-Schulten, UIUC

    Charging of t-RNA LeuRS Canonical Tree D,N Sequence Phylogenetic Trees Fold Motifs of AARSs Structural Alignment Methods PDB - Structural Neighbors - CE (Bourne) Stamp - Russell Multiple Structural Alignments Stamp Output/Secondary Structure Stamp Output/Clustal Format Phylogenetic Tree in Tutorial...
  • Hand Hygiene Journey - APIC In

    Hand Hygiene Journey - APIC In

    Survey Monkey. Evaluation. Webinar funded by CMS through the Partnership for Patients. CMS wants 80% of participants to evaluate educational sessions. As part of this initiative, our organization agrees to:
  • Customer relationship management.

    Customer relationship management.

    Operational CRM. Customer-facing applications, e.g. tools for sales force automation, call centre and customer service support, marketing automation. Analytical CRM . Applications that analyse (OLAP, data mining, etc.) customer data . Based on data warehouses consolidating data from operational CRM...
  • Magnet? - Cornell University

    Magnet? - Cornell University

    Of a previous test quadrupole magnet "5A" ... $1052.67 per QF magnet (16 wedges) $758.00 per BD magnet (16 wedges) Labour ~8h per magnet: 3h measurement, 2h shimming, 2h assembly, 1h 3D printer setup. Required infrastructure.
  • introducingPeak Inside Windows 8 - New Orleans Personal ...

    introducingPeak Inside Windows 8 - New Orleans Personal ...

    UAC. and other . security mechanisms. Windows Server 2008 R2. Based on Windows 7, server only O/S. ... Get used to the Windows Button on your keyboard. ... To pin any of these apps to the Start Page, just point...