Treebeard's Unix Cheat Sheet

Similar documents
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]

commandname flags arguments

Mills HPC Tutorial Series. Linux Basics I

Introduction to the Linux Command Line

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

Chapter-3. Introduction to Unix: Fundamental Commands

Introduction: What is Unix?

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

CHAPTER 1 UNIX FOR NONPROGRAMMERS

Week 2 Lecture 3. Unix

Practical Session 0 Introduction to Linux

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

Outline. Structure of a UNIX command

Unix Introduction to UNIX

Basic Survival UNIX.

Introduction to Linux Workshop 1

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

AN INTRODUCTION TO UNIX

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

Essential Linux Shell Commands

FREEENGINEER.ORG. 1 of 6 11/5/15 8:31 PM. Learn UNIX in 10 minutes. Version 1.3. Preface

Files

Oxford University Computing Services. Getting Started with Unix

Introduction to Unix: Fundamental Commands

CS Unix Tools. Lecture 2 Fall Hussam Abu-Libdeh based on slides by David Slater. September 10, 2010

Quick Start Guide. by Burak Himmetoglu. Supercomputing Consultant. Enterprise Technology Services & Center for Scientific Computing

Getting your department account

Introduction to Linux

CSCI 2132 Software Development. Lecture 5: File Permissions

Unix basics exercise MBV-INFX410

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

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

CSCI 2132 Software Development. Lecture 4: Files and Directories

Permission and Ownership

CS4350 Unix Programming. Outline

CENG 334 Computer Networks. Laboratory I Linux Tutorial

A Brief Introduction to Unix

Unix Tools / Command Line

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

UNIX Quick Reference

Lecture # 2 Introduction to UNIX (Part 2)

Unix Workshop Aug 2014

Files and Directories

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

INSE Lab 1 Introduction to UNIX Fall 2017

CSCE 212H, Spring 2008, Matthews Lab Assignment 1: Representation of Integers Assigned: January 17 Due: January 22

Introduction to UNIX Command Line

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

Introduction to UNIX command-line II

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

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

Chapter 1 - Introduction. September 8, 2016

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

The Directory Structure

CISC 220 fall 2011, set 1: Linux basics

Introduction to Linux

Find out where you currently are in the path Change directories to be at the root of your home directory (/home/username) cd ~

A Big Step. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers

Linux Operating System Environment Computadors Grau en Ciència i Enginyeria de Dades Q2

Set 1 MCQ Which command is used to sort the lines of data in a file in reverse order A) sort B) sh C) st D) sort -r

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

CENG393 Computer Networks Labwork 1

A Brief Introduction to the Linux Shell for Data Science

GNU/Linux 101. Casey McLaughlin. Research Computing Center Spring Workshop Series 2018

Open up a terminal, make sure you are in your home directory, and run the command.

Scripting Languages Course 1. Diana Trandabăț

CS CS Tutorial 2 2 Winter 2018

Getting Started. Running Utilities. Shells. Special Characters. Special Characters. Chapter 2 Unix Utilities for non-programmers

Lab Working with Linux Command Line

Unix Filesystem. January 26 th, 2004 Class Meeting 2

Operating Systems. Copyleft 2005, Binnur Kurt

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

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

Physics REU Unix Tutorial

UNIX Quick Reference

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

CSE 390a Lecture 3. Multi-user systems; remote login; editors; users/groups; permissions

BIOINFORMATICS POST-DIPLOMA PROGRAM SUBJECT OUTLINE Subject Title: OPERATING SYSTEMS AND PROJECT MANAGEMENT Subject Code: BIF713 Subject Description:

Lab 1 Introduction to UNIX and C

Linux Refresher (1) 310/ Fourth Workshop on Distributed Laboratory Instrumentation Systems (30 October - 24 November 2006)

Quick Start Guide. by Burak Himmetoglu. Supercomputing Consultant. Enterprise Technology Services & Center for Scientific Computing

Scripting. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers

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

Introduction to the UNIX command line

The Unix Shell & Shell Scripts

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

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

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

Introduction to Linux

Introduction to Linux Part I: The Filesystem Luca Heltai

Linux Shell Script. J. K. Mandal

12/7/10 ATSC 212 UNIX ATSC 212 ATSC 212 UNIX

Introduction to Linux

Introduction to Linux Part 1. Anita Orendt and Wim Cardoen Center for High Performance Computing 24 May 2017

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

CST8207: GNU/Linux Operating Systems I Lab Six Linux File System Permissions. Linux File System Permissions (modes) - Part 1

Week 5 Lesson 5 02/28/18

Introduction to UNIX I: Command Line 1 / 21

Transcription:

Treebeard's Homepage : Computer Topics Rants and Writes Treebeard's Unix Cheat Sheet People who use Windows without DOS, or a Macintosh, or PPP without a terminal, or an ISP's menu without the Unix prompt are at a disadvantage. Something is happening, and they don't know what it is. I like to know what's really going on, so I've been learning some Unix. The Net is a Unix place. I'm no wizard, but I'm comfortable with basic commands and occasionally type "rm" at my DOS prompt instead of "del". This is my Unix cheat sheet, so I can remember. Uppercase and lowercase matter. These commands (mostly) work with my C-shell account on RAIN. Your account might be different, especially if your prompt ends with a "$" (Korn shell) rather than a "%", so be cautious. When I need help, I reach for the books UNIX in a Nutshell (O'Reilly) and Unix Unbound by Harley Hahn (Osborne/McGraw Hill, 1994). This page won't look right without table support. Most of this is available in a text version. Help on any Unix command. RTFM! man {command} man {command} > {filename} whatis {command} apropos {keyword} Type man ls to read the manual for the ls command. Redirect help to a file to download. Give short description of command. (Not on RAIN?) Search for all Unix commands that match keyword, eg apropos file. (Not on RAIN?) List a directory ls {path} ls {path_1} {path_2} ls -l {path} ls -a {path} ls -F {path} ls -R {path} ls {path} > {filename} ls {path} more dir {path} It's ok to combine attributes, eg ls -laf gets a long listing of all files with types. List both {path_1} and {path_2}. Long listing, with date, size and permisions. Show all files, including important.dot files that don't otherwise show. Show type of each file. "/" directory, "*" executable. Recursive listing, with all subdirs. Redirect directory to a file. Show listing one screen at a time. Useful alias for DOS people, or use with ncftp. 1 of 9 05/12/2016 09:54 AM

Change to directory cd {dirname} cd ~ cd.. cdup There must be a space between. Go back to home directory, useful if you're lost. Go back one directory. Useful alias, like "cd..", or use with ncftp. Make a new directory mkdir {dirname} Remove a directory rmdir {dirname} rm -r {dirname} Only works if {dirname} is empty. Remove all files and subdirs. Careful! Print working directory pwd Show where you are as full path. Useful if you're lost or exploring. Copy a file or directory cp {file1} {file2} cp -r {dir1} {dir2} cat {newfile} >> {oldfile} Recursive, copy directory and all subdirs. Append newfile to end of oldfile. Move (or rename) a file mv {oldfile} {newfile} mv {oldname} {newname} Moving a file and renaming it are the same thing. Delete a file rm {filespec} ls {filespec} rm {filespec}? and * wildcards work like DOS should. "?" is any character; "*" is any string of characters. Good strategy: first list a group to make sure it's what's you think......then delete it all at once. Download with zmodem sz [-a b] {filename} (Use sx with xmodem.) -a ascii, -b binary. Use binary for everything. (It's the default?) 2 of 9 05/12/2016 09:54 AM

sz *.zip Handy after downloading with FTP. Go talk to your spouse while it does it's stuff. Upload with zmodem rz [-a b] (filename} (Use rx with xmodem.) Give rz command in Unix, THEN start upload at home. Works fine with multiple files. View a text file more {filename} less {filename} cat {filename} cat {filename} more page {filename} pico {filename} View file one screen at a time. Like more, with extra features. View file, but it scrolls. View file one screen at a time. Very handy with ncftp. Use text editor and don't save. Edit a text file. pico {filename} The same editor PINE uses, so you already know it. vi and emacs are also available. Create a text file. cat > {filename} pico {filename} Enter your text (multiple lines with enter are ok) and press control-d to save. Create some text and save it. Compare two files diff {file1} {file2} sdiff {file1} {file2} Show the differences. Show files side by side. Other text commands grep '{pattern}' {file} sort {file1} > {file2} sort -o {file} {file} spell {file} wc {file} Find regular expression in file. Sort file1 and save as file2. Replace file with sorted version. Display misspelled words. Count words in file. Find files on system 3 of 9 05/12/2016 09:54 AM

find {filespec} find {filespec} > {filename} Works with wildcards. Handy for snooping. Redirect find list to file. Can be big! Make an Alias alias {name} '{command}' Put the command in 'single quotes'. More useful in your.cshrc file. Wildcards and Shortcuts * Match any string of characters, eg page* gets page1, page10, and page.txt.? Match any single character, eg page? gets page1 and page2, but not page10. [...] Match any characters in a range, eg page[1-3] gets page1, page2, and page3. ~ Short for your home directory, eg cd ~ will take you home, and rm -r ~ will destroy it.. The current directory... One directory up the tree, eg ls... Pipes and Redirection {command} > {file} {command} >> {file} {command} < {file} {command} < {file1} > {file2} {command} {command} (You pipe a command to another command, and redirect it to a file.) Redirect output to a file, eg ls > list.txt writes directory to file. Append output to an existing file, eg cat update >> archive adds update to end of archive. Get input from a file, eg sort < file.txt Get input from file1, and write to file2, eg sort < old.txt > new.txt sorts old.txt and saves as new.txt. Pipe one command to another, eg ls more gets directory and sends it to more to show it one page at a time. Permissions, important and tricky! Unix permissions concern who can read a file or directory, write to it, and execute it. Permissions are granted or withheld with a magic 3-digit number. The three digits correspond to the owner (you); the group (?); and the world (everyone else). Think of each digit as a sum: execute permission write permission write and execute (1+2) 1 2 3 4 of 9 05/12/2016 09:54 AM

read permission read and execute (4+1) read and write (4+2) read, write and execute (4+2+1) 4 5 6 7 Add the number value of the permissions you want to grant each group to make a three digit number, one digit each for the owner, the group, and the world. Here are some useful combinations. Try to figure them out! chmod 600 {filespec} chmod 700 {filespec} chmod 644 {filespec} chmod 755 {filespec} You can read and write; the world can't. Good for files. You can read, write, and execute; the world can't. Good for scripts. You can read and write; the world can only read. Good for web pages. You can read, write, and execute; the world can read and execute. Good for programs you want to share, and your public_html directory. Permissions, another way You can also change file permissions with letters: u user (yourself) g group a everyone r read w write x execute chmod u+rw {filespec} chmod u+x {filespec} chmod a+rw {filespec} Give yourself read and write permission Give yourself execute permission. Give read and write permission to everyone. Applications I use finger {userid} gopher irc lynx ncftp pico {filename} pine Find out what someone's up to. Gopher. IRC, but not available on RAIN. Text-based Web browser, fast and lean. Better FTP. Easy text editor, but limited. vi and emacs are available. Email. 5 of 9 05/12/2016 09:54 AM

telnet {host} tin Start Telnet session to another host. Usenet. uudecode {filename} uuencode {filename} Do it on the server to reduce download size about 1/3. ytalk {userid} Chat with someone else online, eg ytalk mkummel. Please use w first so you don't interrupt a big download! System info date df du more /etc/motd printenv quota -v uptime w Show date and time. Check system disk capacity. Check your disk usage and show bytes in each directory. Read message of the day, "motd" is a useful alias.. Show all environmental variables (in C-shell% - use set in Korn shell$). Check your total disk use. Find out system load. Who's online and what are they doing? Unix Directory Format Long listings (ls -l) have this format: - file d directory, * executable ^ symbolic links (?) file size (bytes) file name / directory ^ ^ ^ ^ ^ drwxr-xr-x 11 mkummel 2560 Mar 7 23:25 public_html/ -rw-r--r-- 1 mkummel 10297 Mar 8 23:42 index.html ^ ^^^ user permission (rwx) date and time last modified ^^^ group permission (rwx) ^^^ world permission (rwx) How to Make an Alias An alias lets you type something simple and do something complex. It's a shorthand for a command. If you want to type "dir" instead of "ls -l" then type alias dir 'ls -l'. The single quotes tell Unix that the enclosed text is one command. Aliases are more useful if they're permanent so you don't have to think about them. You can do this by adding the alias to your 6 of 9 05/12/2016 09:54 AM

.cshrc file so they're automatically loaded when you start. Type pico.cshrc and look for the alias section and add what you want. It will be effective when you start. Just remember that if you make an alias with the name of a Unix command, that command will become unavailable. Here are a few aliases from my.cshrc file: # enter your aliases here in the form: # alias this means this alias h history alias m more alias q quota -v alias bye exit alias ls ls -F alias dir ls alias cdup cd.. alias motd more /etc/motd How to Make a Script A Unix script is a text file of commands that can be executed, like a.bat file in DOS. Unix contains a powerful programming language with loops and variables that I don't really understand. Here's a useful example. Unix can't rename a bunch of files at once the way DOS can. This is a problem if you develop Web pages on a DOS machine and then upload them to your Unix Server. You might have a bunch of.htm files that you want to rename as.html files, but Unix makes you do it one by one. This is actually not a defect. (It's a feature!) Unix is just being more consistent than DOS. So make a script! Make a text file (eg with pico) with the following lines. The first line is special. It tells Unix what program or shell should execute the script. Other # lines are comments. #! /bin/csh # htm2html converts *.htm files to *.html foreach f ( *.htm ) set base`basename $f.htm` mv $f $base.html end Save this in your home directory as htm2html (or whatever). Then make it user-executable by typing chmod 700 htm2html. After this a * will appear by the file name when you ls -F, to show that it's executable. Change to a directory with.htm files and type ~/htm2html, and it will do its stuff. Think about scripts whenever you find yourself doing the same tedious thing over and over. 7 of 9 05/12/2016 09:54 AM

Dotfiles (aka Hidden Files) Dotfile names begin with a "." These files and directories don't show up when you list a directory unless you use the -a option, so they are also called hidden files. Type ls -la in your home directory to see what you have. Some of these dotfiles are crucial. They initialize your shell and the programs you use, like autoexec.bat in DOS and.ini files in Windows. rc means "run commands". These are all text files that can be edited, but change them at your peril. Make backups first! Here's some of what I get when I type ls -laf:.addressbook my email addressbook..cshrc.gopherrc.history.login.lynxrc.ncftp/.newsrc.pinerc.plan.profile.project.signature.tin/.ytalkrc my C-shell startup info, important! my gopher setup. list of past commands. login init, important! my lynx setup for WWW. hidden dir of ncftp stuff. my list of subscribed newsgroups. my pine setup for email. text appears when I'm fingered, ok to edit. Korn shell startup info, important! text appears when I'm fingered, ok to edit. my signature file for mail and news, ok to edit. hidden dir of my tin stuff for usenet. my ytalk setup. DOS and UNIX commands Action DOS UNIX change directory cd cd change file protection attrib chmod compare files comp diff copy file copy cp delete file del rm 8 of 9 05/12/2016 09:54 AM

delete directory rd rmdir directory list dir ls edit a file edit pico environment set printenv find string in file find grep help help man make directory md mkdir move file move mv rename file ren mv show date and time date, time date show disk space chkdsk df show file type cat show file by screens type filename more more sort data sort sort Other Unix Links Basic UNIX Guide Linux Info Quick Reference Card - for pico, pine, elm, and more. Stevem's Place On The Web - good Unix info and links from RAIN's sysadmin The UNIX FAQ The UNIX Guru Universe UNIXhelp for users #UNIX IRC homepage The UNIX Reference Desk last modified. Marc Kummel / mkummel@rain.org 9 of 9 05/12/2016 09:54 AM