0% found this document useful (0 votes)
11 views18 pages

Lecture 02

This document provides a summary of a lecture on Linux shells and files. It discusses bash as the default shell for Linux and MacOS and how it acts as both an interpreter and programming language. It introduces key shell commands like ls, cd, cp, and mv for navigating and manipulating files. It also covers processes, inputs/outputs, file permissions, and the Linux file system structure. The document aims to familiarize students with basic Linux shell and file concepts covered in the lecture.

Uploaded by

dire
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views18 pages

Lecture 02

This document provides a summary of a lecture on Linux shells and files. It discusses bash as the default shell for Linux and MacOS and how it acts as both an interpreter and programming language. It introduces key shell commands like ls, cd, cp, and mv for navigating and manipulating files. It also covers processes, inputs/outputs, file permissions, and the Linux file system structure. The document aims to familiarize students with basic Linux shell and file concepts covered in the lecture.

Uploaded by

dire
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Lecture Participation Poll #2

Log onto pollev.com/cse374


Or
Text CSE374 to 22333

Lecture 2: Linux Shell & CSE 374: Intermediate


Programming Concepts and
Files Tools

1
Administrivia
▪HW 1 will release Monday
▪Class webpage coming later today
▪Class discussion board available
▪Linux accounts will be available later this afternoon
- Username = uwnetid
- Password = tempPassword
▪Meet some of your TAs!
- Dixon
- Andres
- Tom
- Leah

CSE 374 AU 20 - KASEY CHAMPION 2


3
4
Bash Language
Bash acts as a language interpreter
- commands are subroutines with arguments
- bash interprets the arguments and calls subroutine
- bash has its own variables and logic

Bash Java
Interpreted Compiled
Esoteric variable access Highly structured & strongly typed
everything is a string Strings have library processing
easy access to files and programs Data structures and libraries
good for quick & interactive programs good for large complex programs

5
Meet the Linux Shell
▪ Text based interface for Linux
operating system
▪ We will be using the “Bash” shell
- There are different versions, but for this
course we will only be using bash

▪Use echo $SHELL to check which


shell you are using
▪Bash in a unix shell and command
language that is the default login
shell for most Linux and MacOS
▪Interpreted, not compiled
- You’re on your own when things go
wrong
Local MacOS terminal connecting to remote Linux machine

CSE 374 AU 20 - KASEY CHAMPION 6


Commands in the Shell
▪The shell is a text-based interface that takes
commands instead of clicks
▪Commands are pre-existing programs
- <command name> <options> <input || output>

▪To learn about an individual command use


“man”
- <command name> man
- Short for “manual page”
- Can also use the --help option

echo man page

CSE 374 AU 20 - KASEY CHAMPION 7


Shell Interaction Basics
1. Open the terminal application on your local computer
2. Connect to Klaatu Linux server with
3. ssh <username>@klaatu.cs.washington.edu
4. Enter in your password, you will not see characters as you type

Basic Interactions:
▪You can use copy and paste with with your usual short cuts
▪You can navigate through your executed commands by using the up and down arrows
- Convenient way to rerun commands or to fix small errors in previous command

▪The history command will print the commands you’ve used this session to the terminal

CSE 374 AU 20 - KASEY CHAMPION 8


Running Programs
▪You can run a program by typing its path into the terminal
▪Some folders are globally visible, so you only need the program’s name
- /bin/ is globally visible because it is in the PATH shell variable

▪To run a program in the current directory you need to give the path
- ./local_program
- Running local_program by itself will not work because it’s not globally visible

▪All commands are bash files that are executed when you hit “enter” on a terminal line
- You can write and execute your own! More on that later

CSE 374 AU 20 - KASEY CHAMPION 9


Processes in the Shell
▪Programs running in the shell are called “processes”
- We refer to the code/instructions as the “program”
- We can run a given program many times, creating many processes
- Terminal can only run one process in the foreground at a time
- Use the ”&” special character to launch a process in the background
- EX: emacs &

▪Bash Shell has many built in programs


- Commands like cd and ls

▪Processes have Input and Outputs


- Inputs come in two main forms: arguments and stdin
- Arguments are strings separated by spaces given after the command
- EX: cp my/src dest/folder
- Arguments: “my/src” and “dest/folder”
- Arguments with spaces need to be wrapped in quotes EX: echo “hello world”
- Stdin or Standard Input is a stream that the user enters into the terminal
- Outputs can be stdout, stderr or a directed to an output file
- All redirections & string expansions or substitutions are done by the shell before the command

CSE 374 AU 20 - KASEY CHAMPION 10


Useful Commands
Command Operation Example
ls See folder contents ls -l
cd <folderName> Move into given folder cs Downloads
cp <source> <destination> Make a copy of given file in given destination cp file.txt myDir/
mv <oldName> <newname> Rename or move given existing file to given mv fil.txt file.txt
name/destination

cat <fileName> Print file contents to terminal window cat file.txt


touch <filename> Create empty file with given name touch file.txt
echo <string> Print given string to terminal window echo “hello world”
pwd Print working directory pwd
mkdir <directoryName> Create an empty directory at location specified mkdir ~/newDir
exit Exit the shell exit

CSE 374 AU 20 - KASEY CHAMPION 11


Other Useful Commands
Command Operation Example
pico <fileName> Create or edit files pico filename
echo <text> Print text echo hello world
pwd Print working directory’s absolute pwd
path
touch <filename> Create empty file touch filename
mkdir Create empty directory mkdir
find –name <filename> Search for file
exit Exit the shell

CSE 374 AU 20 - KASEY CHAMPION 12


Linux Demo
Recorded Demo from 374 Sp 20 Instructor Megan Hazen CSE 374 AU 20 - KASEY CHAMPION 13
Files
▪A collection of data used for long term
storage
- Stored on a hard drive
- Hard drive is the physical portion of a computer that
stores large amounts of data sits outside the CPU

▪Files have… Finder GUI view of


- Name folder
- Unique string within the folder
- Type
- Indicated by the extension at the end of the name
- Content
- Data contained within the file
- Location
- Folder trail from drive to name
- “breadcrumb”
ls –l view of folder
CSE 374 AU 20 - KASEY CHAMPION 14
Linux File Permissions
Permission Groups
▪ u – Owner
▪ g – Group
▪ o – Others
▪ a – All users
Permission Types
● r- read – a user’s ability to read the contents of the file.

● w - write – a user’s capability to write or modify a file or directory.

● x - execute – a user’s capability to execute a file or view the

contents of a directory.
reading ls -l
▪ _rw_rw_rw = owner, group and all users have read & write
permissions
▪ first character is either a - or a d : d means “directory”, “-” means file
chmod <group>+||-<permission> <file>
▪ chmod a-rw file1 : remove read and write permissions on
file1 for all users
▪ chmod a+rw file1 : add read and write permissions on file1
for all users

https://www.linux.com/training-tutorials/understanding-linux-file-permissions/ 15
File System
▪Files contain other files, branching out from the
root “/” forming a tree-like hierarchy
▪Files are located with a path of folders separated
by “/” this is called the “file path”
▪Paths starting with “/” are called absolute paths
- Start searching from the root of the file system
- EX: /usr/documents/myFiles/myFile.txt

▪Paths that do NOT start with “/” are called


relative paths
- Starts searching from current directory
Tree diagram of file
- EX: myFiles/myFile.txt
structure
▪pwd command will print the current directory

https://homepages.uc.edu/~thomam/Intro_Unix_Text/File_System.html CSE 374 AU 20 - KASEY CHAMPION 16


Demo: File Manipulation
CSE 374 AU 20 - KASEY CHAMPION 17
Questions?
Lecture Participation Poll #2

Log onto pollev.com/cse374


Or
Text CSE374 to 22333

CSE 374 AU 20 - KASEY CHAMPION 18

You might also like