Assume that username is cse. The user s home directory will be /home/cse. You may remember what the relative pathname for users home directory is: ~

Similar documents
Introduction to Linux

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

Hands-on Keyboard: Cyber Experiments for Strategists and Policy Makers

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

Lec 1 add-on: Linux Intro

Perl and R Scripting for Biologists

CS/CIS 249 SP18 - Intro to Information Security

CSCI 2132 Software Development. Lecture 4: Files and Directories

Mills HPC Tutorial Series. Linux Basics I

Shell. SSE2034: System Software Experiment 3, Fall 2018, Jinkyu Jeong

Introduction: What is Unix?

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

Files and Directories

Operating systems fundamentals - B10

Introduction to remote command line Linux. Research Computing Team University of Birmingham

Files

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

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

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

CSCI 2132 Software Development. Lecture 5: File Permissions

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

Useful Unix Commands Cheat Sheet

Course 144 Supplementary Materials. UNIX Fundamentals

CS395T: Introduction to Scientific and Technical Computing

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

bash startup files Linux/Unix files stty Todd Kelley CST8207 Todd Kelley 1

Unix. Examples: OS X and Ubuntu

Introduction to the UNIX command line

Introduction to Unix May 24, 2008

Unix Handouts. Shantanu N Kulkarni

Overview LEARN. History of Linux Linux Architecture Linux File System Linux Access Linux Commands File Permission Editors Conclusion and Questions

The kernel is the low-level software that manages hardware, multitasks programs, etc.

CSN09101 Networked Services. Module Leader: Dr Gordon Russell Lecturers: G. Russell

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

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

CS246 Spring14 Programming Paradigm Notes on Linux

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

NASA Lecture 2 (with lab) 2018/03/05 Michael Tsai Kai-Ling Lo

Basic UNIX commands. HORT Lab 2 Instructor: Kranthi Varala

UNIX. The Very 10 Short Howto for beginners. Soon-Hyung Yook. March 27, Soon-Hyung Yook UNIX March 27, / 29

Review of Fundamentals

Introduction to Unix The Windows User perspective. Wes Frisby Kyle Horne Todd Johansen

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

Introduction of Linux

Linux for Beginners. Windows users should download putty or bitvise:

A Brief Introduction to Unix

Practical Session 0 Introduction to Linux

Files (review) and Regular Expressions. Todd Kelley CST8207 Todd Kelley 1

Filesystem and common commands

INF322 Operating Systems

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

Linux Kung-Fu. James Droste UBNetDef Fall 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

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

Introduction to the shell Part II

CS4350 Unix Programming. Outline

Outline. Structure of a UNIX command

: the User (owner) for this file (your cruzid, when you do it) Position: directory flag. read Group.

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

Linux Command Line Primer. By: Scott Marshall

Short Read Sequencing Analysis Workshop

PESIT Bangalore South Campus

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

The Unix Shell. Permissions

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

UNIX COMMANDS AND SHELLS. UNIX Programming 2015 Fall by Euiseong Seo

Processes are subjects.

Introduction to Linux

Introduction to Linux

EECS 470 Lab 5. Linux Shell Scripting. Friday, 1 st February, 2018

CS Fundamentals of Programming II Fall Very Basic UNIX

FILESYSTEMS. Mmmm crunchy

Lab Working with Linux Command Line

Exercise Sheet 2. (Classifications of Operating Systems)

TEL2821/IS2150: INTRODUCTION TO SECURITY Lab: Operating Systems and Access Control

Unix Internal Assessment-2 solution. Ans:There are two ways of starting a job in the background with the shell s & operator and the nohup command.

UNIX Quick Reference

Introduction To Linux

Command-line interpreters

5/20/2007. Touring Essential Programs

Chapter 9. Shell and Kernel

unix intro Documentation

Unix Introduction to UNIX

More Raspian. An editor Configuration files Shell scripts Shell variables System admin

Unix Guide. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : December, More documents are freely available at PythonDSP

Introduction To. Barry Grant

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

Week 5 Lesson 5 02/28/18

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

Lab 2A> ADDING USERS in Linux

INTRODUCTION TO LINUX

Introduction in Unix. Linus Torvalds Ken Thompson & Dennis Ritchie

Oracle EXAM - 1Z Oracle Solaris Certified Associate Exam. Buy Full Product.

Week 2 Lecture 3. Unix

Lezione 8. Shell command language Introduction. Sommario. Bioinformatica. Mauro Ceccanti e Alberto Paoluzzi

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

Chapter 1 - Introduction. September 8, 2016

Introduction to Linux

LAB #7 Linux Tutorial

Transcription:

Introduction to Open Source Software Development Spring semester, 2017 School of Computer Science and Engineering, Pusan National University Joon-Seok Kim LINUX: COMMANDS

Review Lab #1 2

Create Directories Assume that username is cse. The user s home directory will be /home/cse. You may remember what the relative pathname for users home directory is: ~ $ pwd /home/cse/workspace/lab1 You need to create the Workspace directory in the home directory. Also, you should make Lab1 directory in the Workspace directory. The following are best practice: $ mkdir ~/Workspace $ cd ~/Workspace $ mkdir Lab1 $ cd ~ $ mkdir Workspace $ cd Workspace $ mkdir Lab1 $ cd $ mkdir Workspace $ cd Workspace $ mkdir Lab1 3

Copy Files Assume that the config file is copied from /etc/python/debian_config file. $ ls -l total 4 -rw-r--r-- 1 cse cse 94 3월 7 12:00 config lrwxrwxrwx 1 cse cse 16 3월 7 12:00 link ->../../201624000 The following are best practice: $ cp /etc/python/debian_config ~/Workspace/Lab1/config $ cd ~/Workspace/Lab1 $ cp /etc/python/debian_config config $ cd /etc/python/debian_config $ cp debian_config ~/Workspace/Lab1/config 4

Create Symbolic Links Assume that you created a directory with student id (e.g. 201624000) in the home directory. $ ls -l total 4 -rw-r--r-- 1 cse cse 94 3월 7 12:00 config lrwxrwxrwx 1 cse cse 16 3월 7 12:00 link ->../../201624000 You should create a symbolic link, named link, to the directory. $ cd ~/Workspace/Lab1 $ ln -s../../201624000 link $ cd ~ $ ln -s 201624000 Workspace/Lab1/link 5

Modify Timestamp Assume that the date is after 2017-03-07. Otherwise, a year will appear instead of time. (e.g. 2017) $ ls -l total 4 -rw-r--r-- 1 cse cse 94 3월 7 12:00 config lrwxrwxrwx 1 cse cse 16 3월 7 12:00 link ->../../201624000 Even though a symbolic link has a pointer to a file or directory, it has its own inode and data block. The default touch command may modify timestamp of the referenced file. Therefore, you have to add option -h into touch command to modify timestamps of a symbolic link. For more information, perform man touch and see -h option. $ cd ~/Workspace/Lab1 $ touch -h -t 03071200 link 6

Files and Metadata 7

Hard and Soft Link Hard and soft link mechanism inode # File Name Hard Link Original File Soft Link Metadata Address Inode#1 Inode#2 Data blocks File data Link data Partition A Partition B 8

File Type and Status (1/2) Commands file stat getfacl Brief description Determine file type Display file or file system status Get file access control lists $ cd ~/Workspace/Lab1; ln -s ~/201624000 symlink $ file symlink symlink: symbolic link to /home/cse/201624000/ $ stat symlink File: 'symlink' -> '/home/cse/201624000/' Size: 25 Blocks: 0 IO Block: 4096 symbolic link Device: 801h/2049d Inode: 978763 Links: 1 Access: (0777/lrwxrwxrwx) Uid: ( 1000/cse) Gid: ( 1000/cse) Access: 2017-03-09 00:13:26.735502135 +0900 Modify: 2017-03-09 00:13:24.107502206 +0900 Change: 2017-03-09 00:13:24.107502206 +0900 Birth: - $ 9

File Type and Status (2/2) $ stat -L symlink File: 'symlink' Size: 4096 Blocks: 8 IO Block: 4096 directory Device: 801h/2049d Inode: 983073 Links: 2 Access: (0775/drwxrwxr-x) Uid: ( 1000/cse) Gid: ( 1000/cse) Access: 2017-03-09 00:13:05.151502717 +0900 Modify: 2017-03-09 00:13:05.127502718 +0900 Change: 2017-03-09 00:13:05.127502718 +0900 Birth: - $ stat -f symlink File: "symlink" ID: 9229d5a17a15e5e3 Namelen: 255 Type: ext2/ext3 Block size: 4096 Fundamental block size: 4096 Blocks: Total: 4869551 Free: 3773331 Available: 3520211 Inodes: Total: 1245184 Free: 1017083 10

Notation of Permissions Symbolic Notation Numeric Notation ---------- 0000 no permissions Meaning -rwx------ 0700 read, write, & execute only for owner -rwxrwx--- 0770 read, write, & execute for owner and group -rwxrwxrwx 0777 ---x--x--x 0111 execute --w--w--w- 0222 write --wx-wx-wx 0333 write & execute -r--r--r-- 0444 read -r-xr-xr-x 0555 read & execute read, write, & execute for owner, group and others SECURITY RISK -rw-rw-rw- 0666 read & write -rwxr----- 0740 owner can read, write, & execute; group can only read; others have no permissions 11

Command: getfacl $ cd ~; getfacl.bashrc # file:.bashrc # owner: cse # group: cse user::rwgroup::r-- other::r-- $ getfacl Documents # file: Documents/ # owner: cse # group: cse user::rwx group::r-x other::r-x $ 12

Permission Commands chmod chgrp chown su sudo passwd Brief description Change file mode bits Change group ownership Change file owner and group Change user ID or become superuser Execute a command as another user Change user password 13

Command: chmod, sudo, su $ cd ~/Workspace/Lab1 $ ls -l config -rw-r--r-- 1 cse cse 94 3 월 9 05:00 config $ chmod 777 config $ ls -l config -rwxrwxrwx 1 cse cse 94 3 월 9 05:00 config $ chmod a-x config $ ls -l config -rw-rw-rw- 1 cse cse 94 3 월 9 05:00 config $ chmod o+x config $ ls -l config -rwxrw-rw- 1 cse cse 94 3 월 9 05:00 config $ sudo su - [sudo] password for cse: # pwd /root # cd /home/cse/workspace/lab1 # 14

Command: chown, chgrp # chgrp root config # ls -l config -rwxrwxr-x 1 cse root 94 3월 9 05:00 config # chown root:cse config # ls -l config -rwxrwxr-x 1 root cse 94 3월 9 05:00 config # chown root:root config # chmod 750 config # ls -l config -rwxr-x--x 1 root root 94 3월 9 05:00 config # exit logout $ cat config cat: config: Permission denied $ sudo cat config [sudo] password for cse: [DEFAULT] # how to byte-compile (comma separated: standard, optimize) byte-compile = standard 15

I/O Streams The Unix / Linux standard I/O streams with numbers: Handle Name Description 0 stdin Standard input 1 stdout Standard output 2 stderr Standard error Redirection metacharacters for redirection of I/O Character Action > Redirect standard output >& Redirect standard output and standard error < Redirect standard input >> Append standard output >>& Append standard output and standard error 16

I/O Streams with Command Command Syntax command > file command 2> file command > file 2>&1 command < file command < file.in > file.out command >> file command 2>> file command >> file 2>&1 command <<c command command2 command 2>&1 command2 Task Send stdout to a file Send stderr to file Send stdout and stderr to file Read stdin from a file Read stdin from file.in andsend stdout to file.out Append stdout to the end of a file Append stderr to the end of a file Append stdout and stderr to the end of file Read stdin from the keyboard until the character c Pipe stdout to command2 Pipe stdout and stderr to command2 17

Echo and I/O Stream (1/3) $ echo Hello Hello stdin echo stdout Hello (keyboard) (console) stderr (console) 18

Echo and I/O Stream (2/3) $ echo Hello > example.txt $ echo Hello 1> example.txt Hello stdin echo stdout example.txt (keyboard) (file) stderr (console) 19

Echo and I/O Stream (3/3) $ echo Hello 1> example.txt 2> example.txt $ echo Hello > example.txt 2>&1 Hello stdin echo stdout example.txt (keyboard) (file) stderr 20

Pipe $ cat example.txt grep llo example.txt input cat stdout grep (file) (console) stderr stderr (console) (console) 21

Print Commands Commands echo cat head tail more less grep Brief description Display a line of text Concatenate files and print on the standard output Output the first part of files Output the last part of files File perusal filter for crt viewing (space, enter key) Opposite of more Print lines matching a pattern 22

Command: echo $ echo 'This is the "first" line!'; echo "This is the 'second' line." This is the "first" line! This is the 'second' line. $ echo -e 'This is the first line!\nthis is the second line.' This is the first line! This is the second line. $ echo "This is the first redirection example." > example.txt $ cat example.txt This is the first redirection example. $ echo "This is append mode." >> example.txt $ cat example.txt This is the first redirection example. This is append mode. $ echo "overwrite the file" > example.txt $ cat example.txt overwrite the file $ 23

Command: cat $ cat > example.txt I am typing this text. To escape, you need to send signal Control-C. ^C $ cat example.txt I am typing this text. To escape, you need to send signal Control-C. $ cat ~/.bashrc # ~/.bashrc: executed by bash(1) for non-login shells. # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) # for examples # If not running interactively, don't do anything case $- in *i*) ;; *) return;; esac... 24

Command: head and tail $ head n 8 ~/.bashrc # ~/.bashrc: executed by bash(1) for non-login shells. # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) # for examples # If not running interactively, don't do anything case $- in *i*) ;; *) return;; $ tail n 8 ~/.bashrc # this, if it's already enabled in /etc/bash.bashrc and /etc/profile # sources /etc/bash.bashrc). if! shopt -oq posix; then if [ -f /usr/share/bash-completion/bash_completion ]; then. /usr/share/bash-completion/bash_completion elif [ -f /etc/bash_completion ]; then. /etc/bash_competion fi $ 25

Command: more, less $ dmesg... $ dmesg more... $ dmesg less... $ dmesg grep usb [ 0.365482] usbcore: registered new interface driver usbfs [ 0.365491] usbcore: registered new interface driver hub [ 0.365521] usbcore: registered new device driver usb [ 1.483609] usb usb1: New USB device found, idvendor=1d6b, idproduct=0002 [ 1.483612] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1 [ 1.483614] usb usb1: Product: EHCI Host Controller [ 1.483615] usb usb1: Manufacturer: Linux 4.8.0-36-generic ehci_hcd [ 1.483617] usb usb1: SerialNumber: 0000:02:03.0 [ 1.484925] usb usb2: New USB device found, idvendor=1d6b, idproduct=0001 [ 1.484927] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1 [ 1.484929] usb usb2: Product: UHCI Host Controller [ 1.484931] usb usb2: Manufacturer: Linux 4.8.0-36-generic uhci_hcd [ 1.484932] usb usb2: SerialNumber: 0000:02:00.0 $ dmesg grep pci less 26

Editors $ apropos editor grep text ed (1) - line-oriented text editor ex (1) - Vi IMproved, a programmers text editor gedit (1) - text editor for the GNOME Desktop gnome-text-editor (1) - text editor for the GNOME Desktop red (1) - line-oriented text editor rview (1) - Vi IMproved, a programmers text editor rvim (1) - Vi IMproved, a programmers text editor sed (1) - stream editor for filtering and transforming text vi (1) - Vi IMproved, a programmers text editor view (1) - Vi IMproved, a programmers text editor vim (1) - Vi IMproved, a programmers text editor xedit (1) - simple text editor for X $ gedit newfile.txt $ xedit newfile.txt $ nano newfile.txt $ vi newfile.txt 27