Unix 2 Flashcards

1
Q

This UNIX command displays the current date and time.

A

date

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

This Unix command displays the current month in a calendar format.

A

cal

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

This Unix command shows the number of disk blocks (512 byte units) being used by the contents of the current directory.

A

du

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

This Unix command prints a few lines from the beginning of a file.

A

head

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

This Unix command prints a few lines from the end of a file.

A

tail

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

This Unix command reorganizes the input according to the given option.

A

sort

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

This Unix command extracts columns out of text files.

A

cut

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

This Unix command bundles files into an archive (similar to zip).

A

tar

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

This Unix command compares two files and finds the differences between them.

A

diff

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

This Unix command searches for information using regular expressions.

A

grep

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

The default place where a process reads its input. Usually the keyboard input.

A

stdin

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

The default place where a process writes its output. Usually, the terminal display on the monitor.

A

stdout

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

The default place where a process can send its error messages. Usually, also the terminal display on the monitor.

A

stderr

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

To redirect input from a file, which operator is used in the command?

A

<

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

To redirect output from a file, which operator is used in a command?

A

>

Example:
cal > todaysCal.txt

Stores the output of the cal command into todaysCal.txt
If todaysCal.txt doesn’t exit, it will be created!

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

True or False: Input and output can be redirected at the same time.

A

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.

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

This operator appends to a file rather than redirecting output to it.

A

> >

It will add output to the end of the file and leave whatever contents were already there intact.

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

This allows the standard output of one program to be used as the standard input of another program.

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How do you run multiple Unix commands on the same line?

A

Separate them with semicolons (;)

ls -l; cal; date

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

How would you continue typing a command on the next line?

A

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.

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

Which date command outputs something like:
Wed Nov 22 10:57:12 EST 2023

A

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

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

Which date format string would output:
2023-11-22

A

date +%Y-%m-%d

Full year-month number-day number

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

Which date format string would output:
11/22/23

A

date +%m/%d/%y

Month number/day number/truncated year number

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

Which date format string would output:
The number of days since January 1st of that year.

A

date +%j

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

Which date format string would output:
10:58, November 22-23

A

date +”%H:%M, %B %d-%y”

Note the quotation marks as they are required for the string formatting.

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

What is the Unix Timestamp?

A

The number of seconds elapsed since January 1st, 1970 UTC.

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

What is the syntax for the “cut” command?

A

cut [options] filename

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

Write a cut command to get all the characters between the third and the tenth in each line of the file test.txt

A

cut -c 3-10 test.txt

syntax: cut -c [# of start line]-[# of end line] [filename]

29
Q

What if you wanted to see what -wouldn’t- be included in the cut command:
cut -c 3-10 test.txt

A

cut -c 3-10 –complement test.txt

This will essentially show the inverse of the cut command.

Syntax: cut [options] –complement [filename]

30
Q

What does cut [options] –output-delimeter [new dl] [filename] do?

A

Changes the output delimiter from space to the given delimiter

31
Q

What is the syntax of the sort function?

A

sort [options] [filename]

32
Q

Which sort option sorts in reverse order?

A

sort -r [filename]

33
Q

Which sort option sorts numerical content as numbers instead of in lexicographic order?

A

sort -n [filename]

34
Q

Which sort option ignores case while sorting?

A

sort -f [filename]

35
Q

Which sort option checks if a file is already sorted and then prints the lines that are not in order? If the file is already sorted, there will be no output.

A

sort -c [filename]

36
Q

Which sort option sorts the file contents and removes any duplicates?

A

sort -u [filename]

37
Q

When the sort command is run, does it change the original file by default?

A

No.

38
Q

What is the command to get the Unix Timestamp?

A

date +%s

39
Q

If you wanted to get the calendar for a particular day, month, and year, how would you write the cal command to do that? Let’s say you wanted the calendar for january 1983 with a highlight on the 8th day.

A

cal 8 1 1983

syntax: cal [day] [month] [year]

40
Q

What is the general syntax for the tar command?

A

tar [options] [filenames]

41
Q

What does the tar option:

-c

do?

A

Inserts files into a tar file

42
Q

What does the tar option:

-f

do?

A

Use the name of the tar file that is specified after it

43
Q

What does the tar option:

-v

do?

A

Output the name of each file as it is inserted into or extracted from a tar file

44
Q

What does the tar option:

-x

do?

A

Extract the files from a tar file

45
Q

What does the tar option:

-t

do?

A

List contents of an archive

46
Q

What does the tar option:

-z

do?

A

performs gzip / gunzip if necessary

47
Q

What would be the result of running the line:

tar -cvf proj.tar proj

A

If proj is a directory, this will insert the directory and all files and subdirectories (recursively) (-c), output the files being inserted (-v) and name the resulting archive proj.tar (-f).

Note that if proj.tar already existed it will simply be overwritten; previous information will be lost.

48
Q

What would be the result of running the line:

tar -cvf prog.tar *.c *.h

A

All files ending in .c or .h will be archived in prog.tar

49
Q

When a tar file is opened by another user, what happens from a permissions perspective?

A

All original permissions settings of the files are retained, but the user id becomes that of the user opening the tar archive.

50
Q

What would be the result of running the line:

tar -xvf proj.tar

A

Extract all files from proj.tar into the current directory (-x), output the names of the files extracted (-v) from name of tar file (-f)

51
Q

What would be the result of running the following line:

tar -xvzf proj.tar.gz

A

Extract files (-x), output filenames (-v), unzip files as well (-z), name of tar file (-f)

52
Q

What is the general syntax of zipping a file?

A

gzip [filename]

The original file will be GONE after zipping!

You can add the -v option: gzip -v [filename] to display the verbose output of files being zipped.

53
Q

What are the two ways you can unzip a .gz file?

A

gzip -d [filename].gz

or

gunzip [filename].gz

54
Q

What is the general syntax for comparing two files with the diff command?

A

diff [options] [file 1] [file 2]

55
Q

What does the diff option:

-b

do?

A

Treats groups of spaces as one with regards to the comparison between the two files. It essentially ignores any “extra” spaces when doing the comparison.

56
Q

What does the diff option:

-i

do?

A

Ignores case of letters between the two files when comparing them

57
Q

What does the diff option:

-r

do?

A

Includes directories in the comparison

e.g.

diff -r [directory 1] [directory2]

58
Q

What does the diff option:

-w

do?

A

Ignores ALL spaces and tabs when making the comparison

59
Q

What does the cmp command do?

A

Compares two files byte-by-byte and tells you where they differ. Used for binary and executable files as opposed to diff which is used for text files.

Syntax: cmp [options] [file1] [file2]

60
Q

When comparing two files with the diff command, if two lines are identical between the files, what is output?

A

Nothing. The diff command only shows differences, not matches.

61
Q

When comparing two files with the diff command, if a line is present in the second file and not in the first, what will precede that line in the output?

A

>

62
Q

When comparing two files with the diff command, if a line is present in the first file and not in the second, what will precede that line in the output?

A

<

63
Q

What is the general syntax for a grep search?

A

grep [options] [search pattern] [files]

64
Q

If you wanted to grep a file to find every pattern of characters (not necessarily words) in the file myfile.txt that starts with the letter c and ends with the letter p, how would you write that command?

A

grep ‘c.*p’ myfile.txt

65
Q

Write a single Unix command to extract all the files from the “myProj.tar” archive in the current directory into an existing subdirectory in the current directory, called “ProjectFiles”. You may assume that you have the required permissions.` Do not print verbose output.

A

tar -xf myProj.tar -C ProjectFiles/

66
Q

Which of the following will print the names of all the files with a number in it?

A

ls|grep ‘[[:digit:]]’

67
Q

Write a Unix command to print the changes from ”version1.txt” to “version2.txt”, disregarding extra spaces and case, to a file called “change.log”. You may assume that all the files are in the current directory, and you have the necessary permissions. You may delete an older version of “change.log” if one existed.

A

diff -wi version1.txt version2.txt > change.log

68
Q

Write a UNIX command to print today’s date in the MonthName dd, yyyy format

A

date+”%b %d, %Y”
or
date+”%B %d, %Y”

69
Q
A