SlideShare a Scribd company logo
1 of 24
Lesson 8
• Flow of data
• redirects
• Input and output
• pipe
• tee
Work Flow
Input and output redirection
bash shell, and the other shells employed by Linux allow the user to specify what
should happen to the input and output of programs that run.
shell creates new processes as follows:
1. shell reads the commands to be executed
2. shell opens the files which will be needed (open(2) for files, pipe(2) for streams)
3. shell creates the new processes which will be executed (fork(2) each process)
4. Each new process is connected to the appropriate plumbing (dup2(2) each redirection)
5. Control of processes is passed to programs the user asked for (execve(2) each
command)
shell processes input and output
Standard Streams
Input and output
Normal Flow of Data:
Output Redirects
Simple output redirection. Creates/overwrites file:
Output Redirects
stderr output redirection. Creates/overwrites file.
Output Redirects
Combined out & err redirection. Creates/overwrites files.
File names must be different!
Output Redirects
Combined out & err redirection. Creates/overwrites files.
Only one file name, used for both output streams
Redirecting Standard Output
Standard output redirection (>, >>)
Standard output is the terminal, by default.
The following redirections are possible:
[jack@foo jack]$ uptime
5:09pm up 8:26, 6 users, load average: 0.22, 0.20, 0.20
No redirection
Redirection to a file (“>” means “to”). If the file already exists, it is overwritten.
[jack@foo jack]$ uptime > Uptime-file
[jack@foo jack]$ ls -l Uptime-file
-rw-rw-r-- 1 jack jack 62 Apr 8 17:09 Uptime-file
[jack@foo jack]$ cat Uptime-file
5:09pm up 8:26, 6 users, load average: 0.13, 0.18, 0.19
Redirection appending to a file (“>>” means “to the end of”)
[jack@foo jack]$ uptime >> Uptime-file
[jack@foo jack]$ cat Uptime-file
5:09pm up 8:26, 6 users, load average: 0.13, 0.18, 0.19
5:10pm up 8:27, 6 users, load average: 0.24, 0.21, 0.20
Redirecting to a program. Here the output of uptime is being piped as the input to wc.
jack@foo jack]$ uptime | wc
1 10 62
Standard error redirection (2>, 2>>, 2>&1)
[jack@foo jack]$ tar cf sysconfig.tar /etc/sysconfig
tar: Removing leading `/' from member names
tar: /etc/sysconfig/rhn/systemid: Cannot open: Permission denied
tar: /etc/sysconfig/rhn/up2date-keyring.gpg: Cannot open: Permission
denied
tar: /etc/sysconfig/iptables: Cannot open: Permission denied
tar: /etc/sysconfig/static-routes: Cannot open: Permission denied
tar: Error exit delayed from previous errors
Output sent to stderr:
•Error messages (command 2>/dev/null)
•Warning messages (command 2>> warning.log)
•Debugging and progress indicators (command 2>&1 | less )
If stderr is not redirected, error output is displayed on the terminal.
Standard error redirection (2>, 2>>, 2>&1)
The notation 2>&1 means “stderr(2) to copy of stdout(1)”.
The following all send standard error output to the same destination as standard output:
• command >file 2>&1
• command 2>file 1>&2
• command &> file
• command >& file (this is not the preferred method)
• command 2>&1 | anothercommand
discard the output and the errors from the commands, sending them to /dev/null.
[jack@foo jack]$ tar vcf pam.tar /etc/sysconfig >/dev/null 2>&1
[jack@foo jack]$ nosuchcommandorfilename 2>/dev/null 1>&2
[jack@foo jack]$ ls -la /root 2>/dev/null 1>&2
[jack@foo jack]$ updatedb >& /dev/null &
[jack@foo jack]$ killall -HUP inetd sendmail &> /dev/null
[jack@foo jack]$ killall -HUP inetd sendmail &> /dev/null
commands send standard error output to the same destination standard output (a program).
[jack@foo jack]$ bash -x /etc/init.d/network restart 2>&1 | less
[jack@foo jack]$ tar -c / 2>&1 | less
[jack@foo jack]$ strace mailq 2>&1 | less
Output Redirects Summary
> file
capture stdout to file; overwrites; > is equivalent to 1>
2> file
capture stderr to file; overwrites
> file 2> file2
capture stdout to file; capture stderr to file2; overwrites
>> file
capture stdout to file; appends; >> is equivalent to 1>>
2>> file
capture stderr to file; appends
>> file 2>> file2
capture stdout to file; capture stderr to file2; appends
> file 2>&1
capture stdout to file; capture stderr to file; overwrites
>> file 2>&1
capture stdout to file; capture stderr to file; appends
Input Redirects
Simple input redirection
Input Redirects
• Input redirection isn’t common anymore - now cmds can handle their
own file I/O
• Input and output redirection can be combined:
cat < who.all > cat.who.all
cat < who.all 2> cat.who.all.err
cat < who.all > cat.who.all.all 2>&1
Redirecting Standard Input
Standard input redirection (<, <<EOF, |)
[jack@foo jack]$ wc
Hello. I typed this line. I typed and typed. I wondered, as I typed, how many words I was typing. Tis
wondrous that as I typed, bash piped.
<Ctrl+D>
4 28 143
Standard input is terminal by default. Following redirections are possible:
Read input from the terminal:
Read input from file with <. standard input anonymous: wc does not know file name which it is reading
from.
[jack@foo jack]$ wc < /etc/passwd
46 62 2010
Read input from a program using the pipe redirection. Here cat is piping its output to wc.
[jack@foo jack]$ cat /etc/passwd | wc
46 62 2010
Read input from script or cmdline. Operator << is traditionally followed by EOF, but any letters can be used.
When a line is found which consists only of EOF, that's the end of the input. This is called a “here
document”.
[jack@foo jack]$ wc << EOF
> Hello
> There are
> Four lines
> I think
> EOF
4 7 35
Pipes
The output of who is piped into the input of wc -l
This produces a count of the current user sessions
Piping Output to Next Command
Pipes
Pipeline – Ability to join input and output of processes together.
To set up a pipe use pipe symbol | between cmds that generates output.
Generally, data piped is text, but its possible to join far too many processes together.
Pipes can be chained as needed, and can also be combined with redirection:
who | fgrep bob | wc -l > bob.sessions
It’s even possible to intermix pipes and redirection! Just keep streams straight:
who 2> who.errors | fgrep bob 2>&1 | wc -l
The tee Command
tee – divert a copy to a file
tee is like a teepiece for pipes (or T piece).
tee takes one argument, a filename, and will feed all input from stdin to file,
simultaneously feeding output to stdout.
tee forks its input stream, sending one copy to file on disk, and another
copy to stdout
By default tee is like redirection > and overwrites contents in the files specified.
To apend use tee -a.

More Related Content

What's hot

What's hot (18)

linux-commandline-magic-Joomla-World-Conference-2014
linux-commandline-magic-Joomla-World-Conference-2014linux-commandline-magic-Joomla-World-Conference-2014
linux-commandline-magic-Joomla-World-Conference-2014
 
Basic unix commands
Basic unix commandsBasic unix commands
Basic unix commands
 
Basic linux commands
Basic linux commands Basic linux commands
Basic linux commands
 
Unit 7 standard i o
Unit 7 standard i oUnit 7 standard i o
Unit 7 standard i o
 
50 most frequently used unix
50 most frequently used unix50 most frequently used unix
50 most frequently used unix
 
Linux Network commands
Linux Network commandsLinux Network commands
Linux Network commands
 
Basics of unix
Basics of unixBasics of unix
Basics of unix
 
50 Most Frequently Used UNIX Linux Commands -hmftj
50 Most Frequently Used UNIX  Linux Commands -hmftj50 Most Frequently Used UNIX  Linux Commands -hmftj
50 Most Frequently Used UNIX Linux Commands -hmftj
 
UNIX Basics and Cluster Computing
UNIX Basics and Cluster ComputingUNIX Basics and Cluster Computing
UNIX Basics and Cluster Computing
 
commands v2.3.1
commands v2.3.1commands v2.3.1
commands v2.3.1
 
Phd3
Phd3Phd3
Phd3
 
Linux Networking Commands
Linux Networking CommandsLinux Networking Commands
Linux Networking Commands
 
How to Avoid Common Mistakes When Using Reactor Netty
How to Avoid Common Mistakes When Using Reactor NettyHow to Avoid Common Mistakes When Using Reactor Netty
How to Avoid Common Mistakes When Using Reactor Netty
 
Gdps ftp server access instructions
Gdps ftp server access instructionsGdps ftp server access instructions
Gdps ftp server access instructions
 
Unix Basics For Testers
Unix Basics For TestersUnix Basics For Testers
Unix Basics For Testers
 
Unix commands in etl testing
Unix commands in etl testingUnix commands in etl testing
Unix commands in etl testing
 
Iss letcure 7_8
Iss letcure 7_8Iss letcure 7_8
Iss letcure 7_8
 
Linux basic commands with examples
Linux basic commands with examplesLinux basic commands with examples
Linux basic commands with examples
 

Viewers also liked (20)

register
registerregister
register
 
Fat 32 file system
Fat 32 file systemFat 32 file system
Fat 32 file system
 
17 registers
17 registers17 registers
17 registers
 
Registers
RegistersRegisters
Registers
 
Registers and-common-bus
Registers and-common-busRegisters and-common-bus
Registers and-common-bus
 
FAT vs NTFS
FAT vs NTFSFAT vs NTFS
FAT vs NTFS
 
Processor types
Processor typesProcessor types
Processor types
 
Digital 9 16
Digital 9 16Digital 9 16
Digital 9 16
 
Cpu
CpuCpu
Cpu
 
COMPUTER MEMORY
COMPUTER MEMORYCOMPUTER MEMORY
COMPUTER MEMORY
 
File System and File allocation tables
File System and File allocation tablesFile System and File allocation tables
File System and File allocation tables
 
Instruction set of 8085
Instruction set  of 8085Instruction set  of 8085
Instruction set of 8085
 
8086 instruction set with types
8086 instruction set with types8086 instruction set with types
8086 instruction set with types
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Types of instructions
Types of instructionsTypes of instructions
Types of instructions
 
cache memory
cache memorycache memory
cache memory
 
04 Cache Memory
04  Cache  Memory04  Cache  Memory
04 Cache Memory
 
Registers
RegistersRegisters
Registers
 
Cache memory presentation
Cache memory presentationCache memory presentation
Cache memory presentation
 
Processor powerpoint
Processor powerpointProcessor powerpoint
Processor powerpoint
 

Similar to Licão 08 system redirects

101 3.4 use streams, pipes and redirects
101 3.4 use streams, pipes and redirects101 3.4 use streams, pipes and redirects
101 3.4 use streams, pipes and redirectsAcácio Oliveira
 
101 3.2 process text streams using filters
101 3.2 process text streams using filters101 3.2 process text streams using filters
101 3.2 process text streams using filtersAcácio Oliveira
 
Course 102: Lecture 8: Composite Commands
Course 102: Lecture 8: Composite Commands Course 102: Lecture 8: Composite Commands
Course 102: Lecture 8: Composite Commands Ahmed El-Arabawy
 
101 3.5 create, monitor and kill processes v2
101 3.5 create, monitor and kill processes v2101 3.5 create, monitor and kill processes v2
101 3.5 create, monitor and kill processes v2Acácio Oliveira
 
3.5 create, monitor and kill processes v2
3.5 create, monitor and kill processes v23.5 create, monitor and kill processes v2
3.5 create, monitor and kill processes v2Acácio Oliveira
 
Linux or unix interview questions
Linux or unix interview questionsLinux or unix interview questions
Linux or unix interview questionsTeja Bheemanapally
 
Data file handling
Data file handlingData file handling
Data file handlingTAlha MAlik
 
Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3kognate
 
Time Series Database and Tick Stack
Time Series Database and Tick StackTime Series Database and Tick Stack
Time Series Database and Tick StackGianluca Arbezzano
 
How to admin
How to adminHow to admin
How to adminyalegko
 
Licão 06 process text streams with filters
Licão 06 process text streams with filtersLicão 06 process text streams with filters
Licão 06 process text streams with filtersAcácio Oliveira
 
Tips
TipsTips
Tipsmclee
 
theday, windows hacking with commandline
theday, windows hacking with commandlinetheday, windows hacking with commandline
theday, windows hacking with commandlineidsecconf
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell ScriptingJaibeer Malik
 
Odoo command line interface
Odoo command line interfaceOdoo command line interface
Odoo command line interfaceJalal Zahid
 
One-Liners to Rule Them All
One-Liners to Rule Them AllOne-Liners to Rule Them All
One-Liners to Rule Them Allegypt
 

Similar to Licão 08 system redirects (20)

101 3.4 use streams, pipes and redirects
101 3.4 use streams, pipes and redirects101 3.4 use streams, pipes and redirects
101 3.4 use streams, pipes and redirects
 
101 3.2 process text streams using filters
101 3.2 process text streams using filters101 3.2 process text streams using filters
101 3.2 process text streams using filters
 
Course 102: Lecture 8: Composite Commands
Course 102: Lecture 8: Composite Commands Course 102: Lecture 8: Composite Commands
Course 102: Lecture 8: Composite Commands
 
lec4.docx
lec4.docxlec4.docx
lec4.docx
 
101 3.5 create, monitor and kill processes v2
101 3.5 create, monitor and kill processes v2101 3.5 create, monitor and kill processes v2
101 3.5 create, monitor and kill processes v2
 
3.5 create, monitor and kill processes v2
3.5 create, monitor and kill processes v23.5 create, monitor and kill processes v2
3.5 create, monitor and kill processes v2
 
Linux
LinuxLinux
Linux
 
OS_lab_file.pdf
OS_lab_file.pdfOS_lab_file.pdf
OS_lab_file.pdf
 
Linux or unix interview questions
Linux or unix interview questionsLinux or unix interview questions
Linux or unix interview questions
 
Data file handling
Data file handlingData file handling
Data file handling
 
Nithi
NithiNithi
Nithi
 
Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3
 
Time Series Database and Tick Stack
Time Series Database and Tick StackTime Series Database and Tick Stack
Time Series Database and Tick Stack
 
How to admin
How to adminHow to admin
How to admin
 
Licão 06 process text streams with filters
Licão 06 process text streams with filtersLicão 06 process text streams with filters
Licão 06 process text streams with filters
 
Tips
TipsTips
Tips
 
theday, windows hacking with commandline
theday, windows hacking with commandlinetheday, windows hacking with commandline
theday, windows hacking with commandline
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell Scripting
 
Odoo command line interface
Odoo command line interfaceOdoo command line interface
Odoo command line interface
 
One-Liners to Rule Them All
One-Liners to Rule Them AllOne-Liners to Rule Them All
One-Liners to Rule Them All
 

More from Acácio Oliveira

Security+ Lesson 01 Topic 24 - Vulnerability Scanning vs Pen Testing.pptx
Security+ Lesson 01 Topic 24 - Vulnerability Scanning vs Pen Testing.pptxSecurity+ Lesson 01 Topic 24 - Vulnerability Scanning vs Pen Testing.pptx
Security+ Lesson 01 Topic 24 - Vulnerability Scanning vs Pen Testing.pptxAcácio Oliveira
 
Security+ Lesson 01 Topic 25 - Application Security Controls and Techniques.pptx
Security+ Lesson 01 Topic 25 - Application Security Controls and Techniques.pptxSecurity+ Lesson 01 Topic 25 - Application Security Controls and Techniques.pptx
Security+ Lesson 01 Topic 25 - Application Security Controls and Techniques.pptxAcácio Oliveira
 
Security+ Lesson 01 Topic 21 - Types of Application Attacks.pptx
Security+ Lesson 01 Topic 21 - Types of Application Attacks.pptxSecurity+ Lesson 01 Topic 21 - Types of Application Attacks.pptx
Security+ Lesson 01 Topic 21 - Types of Application Attacks.pptxAcácio Oliveira
 
Security+ Lesson 01 Topic 19 - Summary of Social Engineering Attacks.pptx
Security+ Lesson 01 Topic 19 - Summary of Social Engineering Attacks.pptxSecurity+ Lesson 01 Topic 19 - Summary of Social Engineering Attacks.pptx
Security+ Lesson 01 Topic 19 - Summary of Social Engineering Attacks.pptxAcácio Oliveira
 
Security+ Lesson 01 Topic 23 - Overview of Security Assessment Tools.pptx
Security+ Lesson 01 Topic 23 - Overview of Security Assessment Tools.pptxSecurity+ Lesson 01 Topic 23 - Overview of Security Assessment Tools.pptx
Security+ Lesson 01 Topic 23 - Overview of Security Assessment Tools.pptxAcácio Oliveira
 
Security+ Lesson 01 Topic 20 - Summary of Wireless Attacks.pptx
Security+ Lesson 01 Topic 20 - Summary of Wireless Attacks.pptxSecurity+ Lesson 01 Topic 20 - Summary of Wireless Attacks.pptx
Security+ Lesson 01 Topic 20 - Summary of Wireless Attacks.pptxAcácio Oliveira
 
Security+ Lesson 01 Topic 22 - Security Enhancement Techniques.pptx
Security+ Lesson 01 Topic 22 - Security Enhancement Techniques.pptxSecurity+ Lesson 01 Topic 22 - Security Enhancement Techniques.pptx
Security+ Lesson 01 Topic 22 - Security Enhancement Techniques.pptxAcácio Oliveira
 
Security+ Lesson 01 Topic 15 - Risk Management Best Practices.pptx
Security+ Lesson 01 Topic 15 - Risk Management Best Practices.pptxSecurity+ Lesson 01 Topic 15 - Risk Management Best Practices.pptx
Security+ Lesson 01 Topic 15 - Risk Management Best Practices.pptxAcácio Oliveira
 
Security+ Lesson 01 Topic 13 - Physical Security and Environmental Controls.pptx
Security+ Lesson 01 Topic 13 - Physical Security and Environmental Controls.pptxSecurity+ Lesson 01 Topic 13 - Physical Security and Environmental Controls.pptx
Security+ Lesson 01 Topic 13 - Physical Security and Environmental Controls.pptxAcácio Oliveira
 
Security+ Lesson 01 Topic 14 - Disaster Recovery Concepts.pptx
Security+ Lesson 01 Topic 14 - Disaster Recovery Concepts.pptxSecurity+ Lesson 01 Topic 14 - Disaster Recovery Concepts.pptx
Security+ Lesson 01 Topic 14 - Disaster Recovery Concepts.pptxAcácio Oliveira
 
Security+ Lesson 01 Topic 06 - Wireless Security Considerations.pptx
Security+ Lesson 01 Topic 06 - Wireless Security Considerations.pptxSecurity+ Lesson 01 Topic 06 - Wireless Security Considerations.pptx
Security+ Lesson 01 Topic 06 - Wireless Security Considerations.pptxAcácio Oliveira
 
Security+ Lesson 01 Topic 04 - Secure Network Design Elements and Components....
Security+ Lesson 01 Topic 04 - Secure Network Design Elements and Components....Security+ Lesson 01 Topic 04 - Secure Network Design Elements and Components....
Security+ Lesson 01 Topic 04 - Secure Network Design Elements and Components....Acácio Oliveira
 
Security+ Lesson 01 Topic 02 - Secure Network Administration Concepts.pptx
Security+ Lesson 01 Topic 02 - Secure Network Administration Concepts.pptxSecurity+ Lesson 01 Topic 02 - Secure Network Administration Concepts.pptx
Security+ Lesson 01 Topic 02 - Secure Network Administration Concepts.pptxAcácio Oliveira
 
Security+ Lesson 01 Topic 01 - Intro to Network Devices.pptx
Security+ Lesson 01 Topic 01 - Intro to Network Devices.pptxSecurity+ Lesson 01 Topic 01 - Intro to Network Devices.pptx
Security+ Lesson 01 Topic 01 - Intro to Network Devices.pptxAcácio Oliveira
 
Security+ Lesson 01 Topic 08 - Integrating Data and Systems with Third Partie...
Security+ Lesson 01 Topic 08 - Integrating Data and Systems with Third Partie...Security+ Lesson 01 Topic 08 - Integrating Data and Systems with Third Partie...
Security+ Lesson 01 Topic 08 - Integrating Data and Systems with Third Partie...Acácio Oliveira
 
Security+ Lesson 01 Topic 07 - Risk Related Concepts.pptx
Security+ Lesson 01 Topic 07 - Risk Related Concepts.pptxSecurity+ Lesson 01 Topic 07 - Risk Related Concepts.pptx
Security+ Lesson 01 Topic 07 - Risk Related Concepts.pptxAcácio Oliveira
 
Security+ Lesson 01 Topic 05 - Common Network Protocols.pptx
Security+ Lesson 01 Topic 05 - Common Network Protocols.pptxSecurity+ Lesson 01 Topic 05 - Common Network Protocols.pptx
Security+ Lesson 01 Topic 05 - Common Network Protocols.pptxAcácio Oliveira
 
Security+ Lesson 01 Topic 11 - Incident Response Concepts.pptx
Security+ Lesson 01 Topic 11 - Incident Response Concepts.pptxSecurity+ Lesson 01 Topic 11 - Incident Response Concepts.pptx
Security+ Lesson 01 Topic 11 - Incident Response Concepts.pptxAcácio Oliveira
 
Security+ Lesson 01 Topic 12 - Security Related Awareness and Training.pptx
Security+ Lesson 01 Topic 12 - Security Related Awareness and Training.pptxSecurity+ Lesson 01 Topic 12 - Security Related Awareness and Training.pptx
Security+ Lesson 01 Topic 12 - Security Related Awareness and Training.pptxAcácio Oliveira
 
Security+ Lesson 01 Topic 17 - Types of Malware.pptx
Security+ Lesson 01 Topic 17 - Types of Malware.pptxSecurity+ Lesson 01 Topic 17 - Types of Malware.pptx
Security+ Lesson 01 Topic 17 - Types of Malware.pptxAcácio Oliveira
 

More from Acácio Oliveira (20)

Security+ Lesson 01 Topic 24 - Vulnerability Scanning vs Pen Testing.pptx
Security+ Lesson 01 Topic 24 - Vulnerability Scanning vs Pen Testing.pptxSecurity+ Lesson 01 Topic 24 - Vulnerability Scanning vs Pen Testing.pptx
Security+ Lesson 01 Topic 24 - Vulnerability Scanning vs Pen Testing.pptx
 
Security+ Lesson 01 Topic 25 - Application Security Controls and Techniques.pptx
Security+ Lesson 01 Topic 25 - Application Security Controls and Techniques.pptxSecurity+ Lesson 01 Topic 25 - Application Security Controls and Techniques.pptx
Security+ Lesson 01 Topic 25 - Application Security Controls and Techniques.pptx
 
Security+ Lesson 01 Topic 21 - Types of Application Attacks.pptx
Security+ Lesson 01 Topic 21 - Types of Application Attacks.pptxSecurity+ Lesson 01 Topic 21 - Types of Application Attacks.pptx
Security+ Lesson 01 Topic 21 - Types of Application Attacks.pptx
 
Security+ Lesson 01 Topic 19 - Summary of Social Engineering Attacks.pptx
Security+ Lesson 01 Topic 19 - Summary of Social Engineering Attacks.pptxSecurity+ Lesson 01 Topic 19 - Summary of Social Engineering Attacks.pptx
Security+ Lesson 01 Topic 19 - Summary of Social Engineering Attacks.pptx
 
Security+ Lesson 01 Topic 23 - Overview of Security Assessment Tools.pptx
Security+ Lesson 01 Topic 23 - Overview of Security Assessment Tools.pptxSecurity+ Lesson 01 Topic 23 - Overview of Security Assessment Tools.pptx
Security+ Lesson 01 Topic 23 - Overview of Security Assessment Tools.pptx
 
Security+ Lesson 01 Topic 20 - Summary of Wireless Attacks.pptx
Security+ Lesson 01 Topic 20 - Summary of Wireless Attacks.pptxSecurity+ Lesson 01 Topic 20 - Summary of Wireless Attacks.pptx
Security+ Lesson 01 Topic 20 - Summary of Wireless Attacks.pptx
 
Security+ Lesson 01 Topic 22 - Security Enhancement Techniques.pptx
Security+ Lesson 01 Topic 22 - Security Enhancement Techniques.pptxSecurity+ Lesson 01 Topic 22 - Security Enhancement Techniques.pptx
Security+ Lesson 01 Topic 22 - Security Enhancement Techniques.pptx
 
Security+ Lesson 01 Topic 15 - Risk Management Best Practices.pptx
Security+ Lesson 01 Topic 15 - Risk Management Best Practices.pptxSecurity+ Lesson 01 Topic 15 - Risk Management Best Practices.pptx
Security+ Lesson 01 Topic 15 - Risk Management Best Practices.pptx
 
Security+ Lesson 01 Topic 13 - Physical Security and Environmental Controls.pptx
Security+ Lesson 01 Topic 13 - Physical Security and Environmental Controls.pptxSecurity+ Lesson 01 Topic 13 - Physical Security and Environmental Controls.pptx
Security+ Lesson 01 Topic 13 - Physical Security and Environmental Controls.pptx
 
Security+ Lesson 01 Topic 14 - Disaster Recovery Concepts.pptx
Security+ Lesson 01 Topic 14 - Disaster Recovery Concepts.pptxSecurity+ Lesson 01 Topic 14 - Disaster Recovery Concepts.pptx
Security+ Lesson 01 Topic 14 - Disaster Recovery Concepts.pptx
 
Security+ Lesson 01 Topic 06 - Wireless Security Considerations.pptx
Security+ Lesson 01 Topic 06 - Wireless Security Considerations.pptxSecurity+ Lesson 01 Topic 06 - Wireless Security Considerations.pptx
Security+ Lesson 01 Topic 06 - Wireless Security Considerations.pptx
 
Security+ Lesson 01 Topic 04 - Secure Network Design Elements and Components....
Security+ Lesson 01 Topic 04 - Secure Network Design Elements and Components....Security+ Lesson 01 Topic 04 - Secure Network Design Elements and Components....
Security+ Lesson 01 Topic 04 - Secure Network Design Elements and Components....
 
Security+ Lesson 01 Topic 02 - Secure Network Administration Concepts.pptx
Security+ Lesson 01 Topic 02 - Secure Network Administration Concepts.pptxSecurity+ Lesson 01 Topic 02 - Secure Network Administration Concepts.pptx
Security+ Lesson 01 Topic 02 - Secure Network Administration Concepts.pptx
 
Security+ Lesson 01 Topic 01 - Intro to Network Devices.pptx
Security+ Lesson 01 Topic 01 - Intro to Network Devices.pptxSecurity+ Lesson 01 Topic 01 - Intro to Network Devices.pptx
Security+ Lesson 01 Topic 01 - Intro to Network Devices.pptx
 
Security+ Lesson 01 Topic 08 - Integrating Data and Systems with Third Partie...
Security+ Lesson 01 Topic 08 - Integrating Data and Systems with Third Partie...Security+ Lesson 01 Topic 08 - Integrating Data and Systems with Third Partie...
Security+ Lesson 01 Topic 08 - Integrating Data and Systems with Third Partie...
 
Security+ Lesson 01 Topic 07 - Risk Related Concepts.pptx
Security+ Lesson 01 Topic 07 - Risk Related Concepts.pptxSecurity+ Lesson 01 Topic 07 - Risk Related Concepts.pptx
Security+ Lesson 01 Topic 07 - Risk Related Concepts.pptx
 
Security+ Lesson 01 Topic 05 - Common Network Protocols.pptx
Security+ Lesson 01 Topic 05 - Common Network Protocols.pptxSecurity+ Lesson 01 Topic 05 - Common Network Protocols.pptx
Security+ Lesson 01 Topic 05 - Common Network Protocols.pptx
 
Security+ Lesson 01 Topic 11 - Incident Response Concepts.pptx
Security+ Lesson 01 Topic 11 - Incident Response Concepts.pptxSecurity+ Lesson 01 Topic 11 - Incident Response Concepts.pptx
Security+ Lesson 01 Topic 11 - Incident Response Concepts.pptx
 
Security+ Lesson 01 Topic 12 - Security Related Awareness and Training.pptx
Security+ Lesson 01 Topic 12 - Security Related Awareness and Training.pptxSecurity+ Lesson 01 Topic 12 - Security Related Awareness and Training.pptx
Security+ Lesson 01 Topic 12 - Security Related Awareness and Training.pptx
 
Security+ Lesson 01 Topic 17 - Types of Malware.pptx
Security+ Lesson 01 Topic 17 - Types of Malware.pptxSecurity+ Lesson 01 Topic 17 - Types of Malware.pptx
Security+ Lesson 01 Topic 17 - Types of Malware.pptx
 

Recently uploaded

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Recently uploaded (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

Licão 08 system redirects

  • 1. Lesson 8 • Flow of data • redirects • Input and output • pipe • tee
  • 3. Input and output redirection bash shell, and the other shells employed by Linux allow the user to specify what should happen to the input and output of programs that run. shell creates new processes as follows: 1. shell reads the commands to be executed 2. shell opens the files which will be needed (open(2) for files, pipe(2) for streams) 3. shell creates the new processes which will be executed (fork(2) each process) 4. Each new process is connected to the appropriate plumbing (dup2(2) each redirection) 5. Control of processes is passed to programs the user asked for (execve(2) each command)
  • 6. Input and output Normal Flow of Data:
  • 7. Output Redirects Simple output redirection. Creates/overwrites file:
  • 8. Output Redirects stderr output redirection. Creates/overwrites file.
  • 9. Output Redirects Combined out & err redirection. Creates/overwrites files. File names must be different!
  • 10. Output Redirects Combined out & err redirection. Creates/overwrites files. Only one file name, used for both output streams
  • 12. Standard output redirection (>, >>) Standard output is the terminal, by default. The following redirections are possible: [jack@foo jack]$ uptime 5:09pm up 8:26, 6 users, load average: 0.22, 0.20, 0.20 No redirection Redirection to a file (“>” means “to”). If the file already exists, it is overwritten. [jack@foo jack]$ uptime > Uptime-file [jack@foo jack]$ ls -l Uptime-file -rw-rw-r-- 1 jack jack 62 Apr 8 17:09 Uptime-file [jack@foo jack]$ cat Uptime-file 5:09pm up 8:26, 6 users, load average: 0.13, 0.18, 0.19 Redirection appending to a file (“>>” means “to the end of”) [jack@foo jack]$ uptime >> Uptime-file [jack@foo jack]$ cat Uptime-file 5:09pm up 8:26, 6 users, load average: 0.13, 0.18, 0.19 5:10pm up 8:27, 6 users, load average: 0.24, 0.21, 0.20 Redirecting to a program. Here the output of uptime is being piped as the input to wc. jack@foo jack]$ uptime | wc 1 10 62
  • 13. Standard error redirection (2>, 2>>, 2>&1) [jack@foo jack]$ tar cf sysconfig.tar /etc/sysconfig tar: Removing leading `/' from member names tar: /etc/sysconfig/rhn/systemid: Cannot open: Permission denied tar: /etc/sysconfig/rhn/up2date-keyring.gpg: Cannot open: Permission denied tar: /etc/sysconfig/iptables: Cannot open: Permission denied tar: /etc/sysconfig/static-routes: Cannot open: Permission denied tar: Error exit delayed from previous errors Output sent to stderr: •Error messages (command 2>/dev/null) •Warning messages (command 2>> warning.log) •Debugging and progress indicators (command 2>&1 | less ) If stderr is not redirected, error output is displayed on the terminal.
  • 14. Standard error redirection (2>, 2>>, 2>&1) The notation 2>&1 means “stderr(2) to copy of stdout(1)”. The following all send standard error output to the same destination as standard output: • command >file 2>&1 • command 2>file 1>&2 • command &> file • command >& file (this is not the preferred method) • command 2>&1 | anothercommand discard the output and the errors from the commands, sending them to /dev/null. [jack@foo jack]$ tar vcf pam.tar /etc/sysconfig >/dev/null 2>&1 [jack@foo jack]$ nosuchcommandorfilename 2>/dev/null 1>&2 [jack@foo jack]$ ls -la /root 2>/dev/null 1>&2 [jack@foo jack]$ updatedb >& /dev/null & [jack@foo jack]$ killall -HUP inetd sendmail &> /dev/null [jack@foo jack]$ killall -HUP inetd sendmail &> /dev/null commands send standard error output to the same destination standard output (a program). [jack@foo jack]$ bash -x /etc/init.d/network restart 2>&1 | less [jack@foo jack]$ tar -c / 2>&1 | less [jack@foo jack]$ strace mailq 2>&1 | less
  • 15. Output Redirects Summary > file capture stdout to file; overwrites; > is equivalent to 1> 2> file capture stderr to file; overwrites > file 2> file2 capture stdout to file; capture stderr to file2; overwrites >> file capture stdout to file; appends; >> is equivalent to 1>> 2>> file capture stderr to file; appends >> file 2>> file2 capture stdout to file; capture stderr to file2; appends > file 2>&1 capture stdout to file; capture stderr to file; overwrites >> file 2>&1 capture stdout to file; capture stderr to file; appends
  • 17. Input Redirects • Input redirection isn’t common anymore - now cmds can handle their own file I/O • Input and output redirection can be combined: cat < who.all > cat.who.all cat < who.all 2> cat.who.all.err cat < who.all > cat.who.all.all 2>&1
  • 19. Standard input redirection (<, <<EOF, |) [jack@foo jack]$ wc Hello. I typed this line. I typed and typed. I wondered, as I typed, how many words I was typing. Tis wondrous that as I typed, bash piped. <Ctrl+D> 4 28 143 Standard input is terminal by default. Following redirections are possible: Read input from the terminal: Read input from file with <. standard input anonymous: wc does not know file name which it is reading from. [jack@foo jack]$ wc < /etc/passwd 46 62 2010 Read input from a program using the pipe redirection. Here cat is piping its output to wc. [jack@foo jack]$ cat /etc/passwd | wc 46 62 2010 Read input from script or cmdline. Operator << is traditionally followed by EOF, but any letters can be used. When a line is found which consists only of EOF, that's the end of the input. This is called a “here document”. [jack@foo jack]$ wc << EOF > Hello > There are > Four lines > I think > EOF 4 7 35
  • 20. Pipes The output of who is piped into the input of wc -l This produces a count of the current user sessions
  • 21. Piping Output to Next Command
  • 22. Pipes Pipeline – Ability to join input and output of processes together. To set up a pipe use pipe symbol | between cmds that generates output. Generally, data piped is text, but its possible to join far too many processes together. Pipes can be chained as needed, and can also be combined with redirection: who | fgrep bob | wc -l > bob.sessions It’s even possible to intermix pipes and redirection! Just keep streams straight: who 2> who.errors | fgrep bob 2>&1 | wc -l
  • 24. tee – divert a copy to a file tee is like a teepiece for pipes (or T piece). tee takes one argument, a filename, and will feed all input from stdin to file, simultaneously feeding output to stdout. tee forks its input stream, sending one copy to file on disk, and another copy to stdout By default tee is like redirection > and overwrites contents in the files specified. To apend use tee -a.