0% found this document useful (0 votes)
8 views

W 4 Shell

Uploaded by

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

W 4 Shell

Uploaded by

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

Shell

H. Turgut Uyar

Date:
2022-09-30

Version:

1.0
Shell

interact with the O/S

many different shell programs: bash, zsh, …

runs in terminal, or "console"

prompt: waiting for command


User Information

username

userid

group id (linked to a group name)

home directory

default shell program

executed when the user logs in through a terminal


Commands

name of the executable to run

built-in shell commands


different between different shell programs

effectively a programming language

scripting: glueing programs


Command Arguments

commands can take arguments

switches for changing command behavior


short form: - followed by single character

long form: -- followed by argument name

short form arguments can be grouped to one switch

switches can have their own arguments


Displaying Text

echo: print a line of text

argument: line to print


-n: no newline at end

--help: display help


Navigation Directories

pwd: print working (current) directory

cd: change directory

argument: path of directory to change to

no argument: change to current user's home directory


Directory Listing

ls: list directory entries

argument: paths of entries to list


no argument: list entries in current directory
Directory Listing Switches

-l: long listing format

include more information (size, owner, …)


-h, --human-readable: readable size format

-R, --recursive: list subdirectories recursively

-S, --sort=size: sort by file size

-t, --sort=time: sort by time

-X, --sort=extension: sort by file extension


Directory Operations

mkdir: make directories

argument: paths of directories to create


-p, --parents: also create parent directories if needed

rmdir: remove directories

argument: paths of directories to delete

non-empty directories can not be deleted this way

-p, --parents: also remove parent directories if empty


File Contents

cat: concatenate files

print the contents of files


argument: paths of files to print

head: print the lines at the beginning

tail: print the lines at the end

-n NUM, --lines=NUM: number of lines to print


Deleting Files

rm: remove files

argument: paths of files to delete


-i: interactive (ask for confirmation)

-f: force (don't ask for confirmation)

-r: recursive (also delete subdirectories recursively)


File Operations

cp: copy files

mv: move files (also for renaming)

arguments: path of source file, destination

if destination is directory, keep original file name

-i: interactive (ask for confirmation if overwrite)

-f: force (don't ask for confirmation)

-r: recursive
File Ownership

every file has an owner and a group

chown: change owner of entries

chgrp: change group of entries

arguments: new owner / group, paths of entries to change

-R: recursive
File Permissions

user / group / other

read / write / execute

chmod: change mode of entries

arguments: new mode, paths of entries to change

-R: recursive
Processes

every running program is a process

multiple processes running the same program

ps: list running processes

kill: send a signal to a process


Environment

every program runs in an "environment"

user who started the program

current directory

current language
Environment Variables

environment data are kept in environment variables:

USER: current user

HOME: home directory of current user

PWD: current directory

LANG: current language

$ in front of name when using: $LANG


Path

PATH: in which directories to search for executables


Configuration Files

settings for programs

file name usually starts with .: "hidden" files

not hidden for security: just not listed by default

ls -a (--all)
I/O Streams

every process has standard I/O streams:

standard input (0): stdin (keyboard)

standard output (1): stdout (monitor)

standard error (2): stderr (monitor)


Redirection

I/O streams can be redirected

usually to a file

stdin: <

stdout: >

stderr: 2>
Piping

UNIX philosophy: small utilities that do one thing

connect the output of one to the input of the next: pipe

command1 | command2

command1 | command2 | command3 | ...


Pagination

more: paginate output


Program Result

successful completion: 0

failure: non-zero

$?: result of last command


Program Control

break running program: Ctrl-C

don't block the shell while the program is running


let program run in the background: &

suspend running program: Ctrl-Z (jobs, bg, fg)


Getting Help

man

info
Other Commands

du sed

df awk

tree

pstree

tee

rsync

You might also like