Command Line: Pipes and Redirection Flashcards

1
Q

Send output of a command to a file named myoutput and keep the myoutput contents

A

ls&raquo_space; myoutput

will append the output of ls command to the file named myoutput

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Send output of a command to a file named myoutput and overwrite contents

A

ls > myoutput

will overwrite the contents of the myoutput file and replace it with the current directory list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Read contents of a file to the terminal

A

cat filename.txt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Count words of a file

A

wc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Count lines of a file

A

wc -l

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Output errors of a command to a file

A

… 2> errorfileName.txt

For example if fakeFile.txt does not exist the following command will send the error the errors.txt
ls realFile.txt fakeFile.txt 2> errors.txt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

limit the output of a command to the first 4 items

A

command | head -4
for example: ls | head -4
will only show the first for filesystem items
pipes can be chained so we could: ls | head -4 | head -2 which will only show the 3rd and 4th items

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Command line operator uses the same file for input and output

A

<>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly