Unix 2 Flashcards
This UNIX command displays the current date and time.
date
This Unix command displays the current month in a calendar format.
cal
This Unix command shows the number of disk blocks (512 byte units) being used by the contents of the current directory.
du
This Unix command prints a few lines from the beginning of a file.
head
This Unix command prints a few lines from the end of a file.
tail
This Unix command reorganizes the input according to the given option.
sort
This Unix command extracts columns out of text files.
cut
This Unix command bundles files into an archive (similar to zip).
tar
This Unix command compares two files and finds the differences between them.
diff
This Unix command searches for information using regular expressions.
grep
The default place where a process reads its input. Usually the keyboard input.
stdin
The default place where a process writes its output. Usually, the terminal display on the monitor.
stdout
The default place where a process can send its error messages. Usually, also the terminal display on the monitor.
stderr
To redirect input from a file, which operator is used in the command?
<
To redirect output from a file, which operator is used in a command?
>
Example:
cal > todaysCal.txt
Stores the output of the cal command into todaysCal.txt
If todaysCal.txt doesn’t exit, it will be created!
True or False: Input and output can be redirected at the same time.
True
Example:
a.out < input12.txt > testout.txt
The input to a.out will come from input12.txt instead of the keyboard, and the output from a.out will go to testout.txt instead of the terminal display.
This command FAILS (or works improperly) if the input file does not exist! Output file will be created if it doesn’t already exist. If it does exist, the contents of the file will be deleted and replaced entirely with the output from this command.
This operator appends to a file rather than redirecting output to it.
> >
It will add output to the end of the file and leave whatever contents were already there intact.
This allows the standard output of one program to be used as the standard input of another program.
The | operator takes the output from the command on the left and feeds it as standard input to the command at the right of the pipe. Pipes are more efficient because it uses data directly instead of creating user accessible files and writing them to disk.
(pipe)
How do you run multiple Unix commands on the same line?
Separate them with semicolons (;)
ls -l; cal; date
How would you continue typing a command on the next line?
A backslash \ at the end of the line will prompt the user to continue after pressing enter.
Putting the rest of the command in and pressing enter will then run the entire command as though it were all entered at once.
Which date command outputs something like:
Wed Nov 22 10:57:12 EST 2023
date
This is the default output for date.
Abbreviated day of the week, abbreviated month, day of the month, time in h:m:s, time zone, and the year.
day/mon/h:m:s/zone/year
Which date format string would output:
2023-11-22
date +%Y-%m-%d
Full year-month number-day number
Which date format string would output:
11/22/23
date +%m/%d/%y
Month number/day number/truncated year number
Which date format string would output:
The number of days since January 1st of that year.
date +%j
Which date format string would output:
10:58, November 22-23
date +”%H:%M, %B %d-%y”
Note the quotation marks as they are required for the string formatting.
What is the Unix Timestamp?
The number of seconds elapsed since January 1st, 1970 UTC.
What is the syntax for the “cut” command?
cut [options] filename