Skip to content
KAGETERM

$ ./yonlendirme

Redirection and pipes

Last updated: status: in effect

Write output to a file, feed one command into another.

About this topic

Tool
Core commands
Level
Basic
Commands
6
Access
Free

Commands

echo "merhaba" > note.txt

Writes the output to a file; the old contents are lost.

echo "merhaba"
prints merhaba
>
redirect output to a file, overwrite
note.txt
file to write

echo "ikinci" >> note.txt

Appends the output to the end of the file; the old contents stay.

echo "ikinci"
prints ikinci
>>
append output to the end of a file
note.txt
file to append to

ls -l | wc -l

Feeds one command's output to another and counts the lines.

ls -l
lists the directory in detail
|
pipe: pass the output to the next command
wc -l
prints the line count

sort names.txt | uniq

Sorts, then collapses identical adjacent lines into one.

sort names.txt
sorts lines
|
pipe: pass the output to the next command
uniq
drops repeated adjacent lines

ls nofile 2> errors.log

Redirects only the error output to a file.

ls nofile
tries to list a file that does not exist
2>
redirect error output
errors.log
file the errors go to

history | grep ssh

Filters the command history.

history
list of commands you have typed
|
pipe: pass the output to the next command
grep ssh
pick lines that contain ssh

Start practising

Practise the commands in your browser: learn mode explains every part, exam mode shows only the question.

Open KAGETERM All topics