Four Flashcards
what are the file descriptor number of standard file input and output
stdin 0 cat output.txt
stderr 2 command file 2> errorfile.txt
How to create an empty file
> newfile.name
How to discard unwanted output
command > /dev/null
The output to /dev/null is ignored by the shell
How to discard both the output and the error output
command &> /dev/null
The cheat sheet for file checkings
Operator Description
- a file Returns true if file exists
- b file Returns true if file exists and is a block special file
- c file Returns true if file exists and is a character special file
- d file Returns true if file exists and is a directory
- e file Returns true if file exists
- r file Returns true if file exists and is readable
- s file Returns true if file exists and has a greater size that zero
- s file Returns true if file exists and has a greater size that zero
- w file Returns true if file exists and is writable
- x file Returns true if file exists and is executable
- N file Returns true if the file exists and has been modified since it was last read
What is the normal exit value of a successful command
$? which is always 0 when command is implemented successfully
what is the value of grep command when the string is not present
the exit value is non-zero then
How to specify a exit value for a script
when exit is explicitly given, the exit value is the value of the last command
What is command1 && command2
and command1 || command2
command1 && command2: command2 is executed iff command1 gives a 0 exit value
command1 || command2: command2 is executed iff command1 gives a non-zero value
What is the difference between
grep into string
grep “string”
redirect error output
./scripts.sh 2>scripts.err
Append a output
command_output»_space; file
strd output to strd output
2>&1
error output to standard output
what does
-tells the I/O that in the file, the leading tab character is ignored