Department of Computer Engineering

Slides:



Advertisements
Similar presentations
การใช้ระบบปฏิบัติการ UNIX พื้นฐาน บทที่ 4 File Manipulation วิบูลย์ วราสิทธิชัย นักวิชาการคอมพิวเตอร์ ศูนย์คอมพิวเตอร์ ม. สงขลานครินทร์ เวอร์ชั่น 1 วันที่
Advertisements

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.
5 Basic utilities When a user logs in to the Linux operating system the directory that they will start in is their home directory. Most users will have.
ATS Programming Short Course I INTRODUCTORY CONCEPTS Tuesday, Jan. 27 th, 2009 Essential Unix Commands.
Linux+ Guide to Linux Certification, Second Edition
Linux+ Guide to Linux Certification, Second Edition
Guide To UNIX Using Linux Third Edition
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
Linux Commands LINUX COMMANDS.
1 Day 3 Directories Files Moving & Copying. 2 Case Sensitive First thing to learn about UNIX is that everything is case sensitive. Thus the files: –enda.
Brief introduction to UNIX A. Emerson CINECA, High Performance Systems.
Help session: Unix basics Keith 9/9/2011. Login in Unix lab  User name: ug0xx Password: ece321 (initial)  The password will not be displayed on the.
The file structure and related utilities CS240 Computer Science II.
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.
Offline File Storage. Module 12 Offline File Storage ♦ Introduction Backup is usually done by first collecting all the data in a single archive file,
Lesson 11-Locating, Printing, and Archiving User Files.
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
Guide To UNIX Using Linux Fourth Edition
Unix Basics Chapter 4.
Linux Operations and Administration
Linux+ Guide to Linux Certification, Second Edition
1 Lecture 5 Additional useful commands COP 3353 Introduction to UNIX.
Workbook 5 - Part 2 The Linux Filesystem RH030 Linux Computing Essentials.
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.
Agenda Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Review next lab assignments Break Out Problems.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX Commands cal – will print a calendar.
Chapter Two Exploring the UNIX File System and File Security.
Welcome to CS323 Operating System lab 1 TA: Nouf Al-Harbi NoufNaief.net.
Unix Commands PowerPoint Presentation developed for LS 560 Information Technology online class - University of Alabama by Debey Sklenar TENacious Cohort.
E X C E E D I N G E X P E C T A T I O N S Basic LINUX Linux System Administration Dr. Hoganson Kennesaw State University Operating Systems Directory structure:
Linux+ Guide to Linux Certification, Third Edition
Linux+ Guide to Linux Certification, Third Edition
Introduction to Programming Using C An Introduction to Operating Systems.
Linux Commands C151 Multi-User Operating Systems.
CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.
1 Lecture 2 Working with Files and Directories COP 3353 Introduction to UNIX.
UNIX filesystem CS 2204 Class meeting 2 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
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 Introduction to Unix. 2 What is UNIX?  UNIX is an Operating System (OS).  An operating system is a control program that helps the user communicate.
The Kernel At a high level, the kernel in an operating system serves as the bridge between applications and the actual data processing of the hardware.
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
Learning basic Unix command It 325 operating system.
BIF703 File Permissions. As you recall from our previous notes, that Unix/Linux recognizes everything as a file: Regular files to store data, programs,
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.
Agenda The Linux File System (chapter 4 in text) Linking Files Hard Links / Symbolic Links Disk Storage Checking for Disk Space (df / du) Archiving (Backing.
Linux Filesystem Management
Introduction to Unix – CS 21
By Jonathan Rinfret UNIX/LINUX By Jonathan Rinfret
Department of Computer Engineering
File permissions Operating systems I800
Lecture 2 Working with Files and Directories
Some Linux Commands.
C151 Multi-User Operating Systems
BIF703 File Permissions.
UNIX Basics Internet Technology.
Introduction to UNIX.
Using Linux Commands Lab 3.
Exploring the UNIX File System and File Security
Web Programming Essentials:
Lecture 5 Additional useful commands COP 3353 Introduction to UNIX 1.
Chapter Four UNIX File Processing.
Introduction Paul Flynn
UNIX/LINUX Commands Using BASH Copyright © 2017 – Curt Hill.
Linux Commands LINUX COMMANDS.
Chapter 4: The Linux Filesystem
Lecture 5 Additional useful commands COP 3353 Introduction to UNIX 1.
January 26th, 2004 Class Meeting 2
Presentation transcript:

Department of Computer Engineering Week 2 Introduction to UNIX OS Department of Computer Engineering 2001-2002 Fall Prepared by Aykut Guven

Beginning... You have been learning basic concepts of Unix since 3 weeks. This week we are going on to learn Unix commands. This week ,we will complete of learning basic and common used commands of Unix. Please do these steps which are given below....

Steps Login to the system. Make sure you are in your HOME directory. (typing "cd" by itself and pressing return will put you in your home directory) Type the following command: "cp -f /home/files/myfirstscript ." Now type "cp -fR /home/public_html ." Type in "cat myfirstscript". What happens? Now, type in "more myfirstcript" What do you see this time? Now, type in "less myfirstcript" What do you see this time? Try this command "ls -al /etc/" Did you get to read everything? Now, try this command: " ls -al /etc/ | more" The " | " is above the enter key on your keyboard. It is called a "pipe". Can you figure out what it does? Try the previous command using the command "less" instead of the "more". Does it work?

Steps Try the previous command without using the pipe character. What happens now? Type "cd" to make sure you are in your home directory. Do an "ls -al" What is the information you see on the new file? Now, let's try to execute the script we copied over. Type "./myfirstscript" Take note: that is a period followed by the forward slash, followed by the name of the program. What happens? Now, type in "chmod 755 myfirstscript" and try to execute the script again. What happens this time? Type in "mv myfirstscript mynewnamescript" . Do an "ls -al" , what do you see? Let's rename the script back to it's original name. "mv mynewnamescript myfirstscript" Does it still run? (It should, but make sure.) Type "cat lesson1.html | grep UNIX" . What do you see? Type "grep UNIX lesson1.html". Now what do you see? Type in "man grep". Do you get an indication of what grep is used for? Finally, type "grep UNIX lesson1.html > UNIXTestFile" . Do an "ls" and look for a file called "UNIXTestFile". Type in "more UNIXTestFile" . What do you see? Delete the UNIXTestFile. ("rm UNIXTestFile") Make sure you are in your home directory and type "cp lesson1.html ./public_html" .

UNIX Commands Cat Concatenate files and print on standard output. Works like the DOS "TYPE" command. Simply put, "cat" can be use to read the contents of a file. Chmod Change the permissions on a file or directory Grep Find line matching a certain pattern. Very powerful search tool. Less Filter for viewing files and directories. Works the same as the "more" command, but lets you scroll backwards. It is a little bulkier than more. More Filter for viewing files and directories a screen at a time. Mv Move or rename file > A cool feature of Linux is that you can easily send the info that normally gets printed on the screen into a text file instead. This is called redirecting output. . For example, ls > newFile, will list all files in a directory and write them to a file called "newFile". If "newFile" already exists, the contents will be over-written, otherwise a new file will be created. >> Append the output of a program to a file. If the file does not already exist, it will be created. If it does already exist, the output will be written to the end of the file. | Called the "pipe". It is used to redirect the output of a command to another command.

You will use the "cat" command quite often You will use the "cat" command quite often. You might be told to "cat the file", which means to read it using the cat command. For example, "cat lesson1.html" will let you read the file, lesson1.html. In a future lesson we will describe "chmod" and file permissions in greater detail. For now, just know that if you want to execute a file as a program, you should enter "chmod 755 filename". The "|" (pipe) character allows you to pipe data from one program to another program or command. For example, if you change directories to /dev and do an "ls", the listing goes by too quickly to see what is there. Try this yourself. Now, use the pipe function and pipe the results of ls to a paging program like more. Here's how: ls /dev/ | more Now you can scroll through the results of the "ls" command. "grep" performs searches in files and directories. It is often used with wild cards to find information. For example, cd into your public_html directory. If you type, "grep linux *", a search will be performed on ALL (*) files in the directory for the word "linux." Then each line containing the word "linux" will be printed to the screen. If you want to save your results to a file, you can use the greater than character to redirect the output to a file. For example, "grep linux * > linuxLines" will perform a search on all files in the directory for the word "linux" and save the output to a file called "linuxLines". If the file already exists, it will be overwritten. To avoid this, you can use a 2 greater than signs to append the output to the end of the file.

The Lab Assignment You have a file named "index.html" in your home directory. In a new file that you write with vi, please list 3 commands to quickly view the file. Make a copy of the file and call it "myPractice.html". Search the file for all lines with the word "zip" in it and save them to a file call "mypracticeresults.txt". Print the contents of mypracticeresults.txt to the screen. Attach a screen shot of this to the email you send me with the answers from question number 1.

File Permissions Every file and directory in UNIX/Linux has read, write, and execute permissions. Read permission means that the file can be read but not modified or deleted. Write permission means that the file can be created, modified, or deleted. Execute permission means that the file can be executed. The execute permission is similar to a .exe file in Windows or DOS. For directories, execute permission means you can open the directory.

Permissions There are 3 sets of permissions for every file or directory -- owner, group, and world. For each set, there are separate read, write, and execute permissions. The owner permissions are for the owner of the file or directory. The group permissions are for everyone in the group. The global permissions are for anyone. To see the current permissions, owner, and group for a file or directory, type the following commands: 1-"cd" 2-"ls -l" This will display the contents of your home directory in long format. The following is an example of what you might have seen with the above 2

commands drwxr--r-- 5 you public 4096 Feb 7 14:33 Desktop drwxr--r-- 2 you public 4096 Apr 4 10:55 linuxpractice -rwxr-xr-x 1 you public 223 Apr 6 11:37 myfirstscript drwxr-xr-x 4 you public 4096 Apr 9 12:03 public_html The third column (you) tells the owner of the file or directory, and the fourth column (public) is the name of the group for the file or directory.The permissions are listed in the first column. The first letter is whether the item is a directory or a file. If the first letter is a "d", then the item is a directory as in the first item listed above, Desktop. Notice, for the file myfirstscript, the first letter is "-". The next three letters are the permissions for the owner of the file, the next three letters apply to everyone in the group, and the last three letters are for everyone else. The read, write, and execute permissions are referred to as r,w, and x respectively. Thus, for the directory Desktop above, the owner you has read, write, and execute permissions to the directory Desktop, everyone in the group public has read permissions, and everyone else has read permissions. The only one who can modify or delete any file in this directory is the owner you (or the superuser- "root").

Changing Permissions "chmod" is a standard UNIX/Linux command that allows you to change the permissions of a file or directory. There are two arguments for chmod: the permissions and the file/directory name. The permission argument for chmod is based on numbers. 1 stands for execute. 2 stands for write. 4 stands for read. To set more than one permission on a file or directory, you just add up the permissions. For example, 7 means read, write, and execute permissions. chmod takes the permissions as the first argument in the order user, group, global. Thus, the command chmod 777 hello will change the permissions of the file hello to read, write and execute by user, group, and everyone else. Note: To change the permissions of a file/directory, you must be the owner of that file/directory. However, root can change permissions on any file or directory.

Changing Permissions One last topic that we should touch on here is the ownership commands. If you are ROOT, you can change the ownership of files using the "chown username filename" command. As with most commands, there are many options. You can learn about those options by typing "man chown" Example: "chmod 777 Desktop" will allow EVERYBODY full access to read, write and execute. "chmod 644 Desktop" will all the owner (you) read and write access, the group read access, and everybody else (world) read access too. "chmod 700 Desktop" will give yourself full access while giving everybody else NOTHING.

Assignment Please answer the following questions: What is the command to make sure that the file "myfirstscript" is world executable, and at the same time you have full control and the group public has full control? If you see that the permissions for a file are "drwxr-xr-x", who can write to it? If you see that the permissions for a file are "-rwxrwxrwx", who can write to it? You see that the permissions on file greatText are "-rw-------", what command would you issue to make this file have the same permissions as the file in question number 3? What's the command to issue to make sure everybody in your group and yourself have read and write access to the file greatText but the world can only read it? You want everybody in the world to be able to execute your file, greatProgram, what is the command to accomplish this. (note: a program usually produces an output that is read). For webmasters: Why do you suppose cgi scripts are usually chmod 755?

Archiving Utilities in UNIX & LINUX In this lesson, we are going to practice using the tar, gzip, and bzip2 utilities. These archiving utilities are commonly used in Linux and UNIX systems. Every Operating System has its own archiving utilities for Back Up and Recovery.

TAR tar stands for Tape ARchive. It was originally designed for tape backups, but it is used to create a tar file anywhere on the filesystem. tar creates one "tar file" (also known as a "tarball") out of several files and directories. A tar file isn't compressed, it's just a heap of files assembled together in "one container". So, the tar file will take up the same amount of space as all the individual files combined, plus a little extra. A tar file can be compressed by using gzip or bzip2. Here are some examples: tar -xvf example.tar Extract the contents of example.tar and display the files as they are extracted. tar -cf backup.tar /home/ftp/pub Create a tar file named backup.tar from the contents of the directory /home/ftp/pub tar -tvf example.tar list contents of example.tar to the screen

Practice Log in to the linux box and make sure you are in the home directory. Do an ls -al to see what is in the home directory. We should have a directory called "Desktop". cd into that directory and look around. Type "cd" to bring yourself back to the home directory. Again, confirm that you are in the home directory. Type in the following command: "tar -cvf desktop.tar Desktop" (please pay attention to CaSe) Do an ls -al again to see what is in the directory now. You should see a file called desktop.tar Now type in "mv Desktop Desktop.old" to rename the Desktop directory. Do an ls -l to confirm that the directory name has been changed and there no longer is a directory named Desktop in the home directory. cd into the Desktop.old directory and confirm that the files are the same as what you saw in #2. cd back to your home directory (to move up (back) one directory, you can type in "cd .." Now type in the command "tar -xvf desktop.tar" to extract the contents of the archive. Do an ls -al again. You should see the original Desktop directory. cd into it and make sure the files are in it. Remove the tar file and the Desktop.old directories if everything worked properly. ("rm desktop.tar", "rm -rf Desktop.old")

GZIP gzip is the original UNIX ZIP format. It's common to first "tar" files and then compress them afterwards using gzip. These files are normally given the extentions .tar.gz to show that they are tar archives zipped up with gzip. You may also see the extension, .tgz. An archive that is compressed with gzip is compatible with WinZip and PkZip. So, a file zipped up on a UNIX box can be unzipped with a Windows box. Here are some examples: To compress a file using gzip, execute the following command: gzip filename.tar (where filename.tar is the name of the file you wish to compress) The result of this operation is a file called filename.tar.gz. By default, gzip will delete the filename.tar file. To decompress a file using gzip, execute the following command: gzip -d filename.tar.gz The result of this operation is a file called filename.tar. By default, gzip will delete the filename.tar.gz file. You can also decompress the file using the command: gunzip filename.tar.gz This is the same as using the gzip -d command. There are many options that you can use with gzip. Do a man on the utility to learn more.

BZIP2 bzip2 and bunzip2 are file compression and decompression utilities. The bzip2 and bunzip2 utilities are newer than gzip and gunzip and are rapidly gaining popularity. The bzip2 utility is capable of greater compression ratios than gzip. Therefore, a bzip2 file can be 10-20% smaller than a gzip version of the same file. Usually, files that have been compressed by bzip2 will have a .bz2 extension. The utilities work very similar to gzip and gunzip. Here are a couple of examples. To compress a file using bzip2, execute the following command: bzip2 filename.tar (where filename.tar is the name of the file you wish to compress) The result of this operation is a file called filename.tar.bz2. By default, bzip2 will delete the filename.tar file. To decompress a file using gzip, execute the following command: bunzip2 -d filename.tar.bz2 The result of this operation is a file called filename.tar. By default, bunzip2 will delete the filename.tar.bz2 file.

File Structure & Organization UNIX/Linux filesystems are very different from Windows. UNIX/Linux is organized in a hierarchy, starting with "slash." Slash is this: / The rest of the directories and subdirectories continue down from slash. For example, the directory, /etc/httpd/ , is a subdirectory in the the /etc (pronounced "etsie") directory. /etc/ is a directory in slash. Unlike Windows that represents drives as letters (e.g., a:,c:, e:), all devices, including hard drives, cdroms, and other storage media in Linux all fit into the normal directory structure. Devices are mounted onto the file system tree and, as a user, you might not be able to tell if a directory is actually located on your own hard drive or on a hard drive of another computer. Linux, allows for the great level of flexibility in terms of its file systems. You can literally put in four drives and "mount" them to various directories in your tree. Here are some common mounts you should know about:

/(Called root), this is equivalent to C:\ in the DOS/Windows world /(Called root), this is equivalent to C:\ in the DOS/Windows world. You cannot run a Linux system without the root partition. All other partitions are a subset of the root partition.swapUnless you have massive amounts of memory, you are going to need some swap space. In Windows, you have Win386.swp; here, it's a separate drive partition./bootThis contains the necessary stuff to start the machine, including the base kernel. This partition is optional, but usually present. You will not need to mess around in here if you have a running system./usrThis is the directory where global executables are stored. It can be read-only, if you want. Generally speaking, most software is installed here by default. /devThis is the directory where all of your devices are. There are a few useful examples for you to know. /dev/hda is the first ide hard drive. /dev/hdb is the second. /dev/sda would be the first SCSI drive, and /dev/sg0 is your robotic arm. /etcThis is where most configuration files are stored. You will spend a lot of time in here if you are an administrator. Most files require "root" access to change./varMany of the system log files are here, as well as spools (mail, printer...)/binThis directory is the home of binary executables. These include the common commands we have already learned like ls, cat, gzip and tar.