CLOs - Searching for files Flashcards
When commands are executed, how many standard file streams (descriptors) are there open for use?
- standard input (stdin)
- standard output (stdout)
- standard error (stderr)
What are open files in Linuxs?
- internally represented by file descriptors
- these are represented by numbers starting at zero
- stdin is file descriptor 0
- stdout is file descriptor 1
- stderr is file descriptor 2
- typically other files are opened in addition to these three, which are opened by default
How can you change the input of a program called do_something that reads from stdin to an input file?
$ do_something < input-file
How can you sent the output of a program called do_something to a file?
$ do_something > output-file
How can you redirect stderr to a seperate file?
Using stderr’s file descriptor number (2):
$ do_something 2> error-file
How do you give out stdout into a file using file descriptor numbers?
$ do_something 1> output-file
instead of
$ do_something > output-file
How do you write both stdout and stderr into the same file?
And in Bash?
$ do_something > all-output-file 2>&1
bash:
$ do_something >& all-output-file
What use have pipes in Linux?
To chain together multiple simple commands instead of having complex programs with multiple modes and options
Why is the pipeline extra efficient in Linux?
- because later commands in the chain do not have to wait for earliert commands to finish to start processing data in their input streams
How can you find files in you file-hierarchy?
using locate and find utilities
How do you use locate?
$ locate zip | grep bin
How does locate work and how can you force an update?
- uses a database created by a related utility updatedb for search
- in background automatically updated once a day, but can be forced with running updatedb from command line as root user