Managing Files Flashcards

1
Q

Many commands produce “_______” output. Normally, output is displayed on the screen.

A

Visible.

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

Linux likes to think of everything as a…?

A

file.

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

One of the features of the bash command shell is that the output which would normally be directed at the screen through _______ can, instead be redirected to some other file. (This is done by using the special redirection symbol, >.

A

STDOUT

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

cat…?

A

Concatenate File(s) to standard output.

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

Cat command copies each of the…?

A

files listed to standard output. (If more than one file is listed, this effectively concatenates the files. As for any other command, this output will display on the screen by default, but could also be redirected to a file. We will use it to display a file by naming a single file and not redirecting the results.)

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

If the file already exists, redirection will….?

A

delete and re-create the file empty, then capture the new output. If, however, a double arrow (») is used, the new output is appended to the file. If&raquo_space; is used and the target file does not exist, it is created, just as if > had been used.

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

The > symbol is an example of a…?

A

shell meta-character, that is, a symbol with special meaning which the bash shell sees and interprets before the rest of the command is acted upon.

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

Simplest command that produces visible output is…?

A

Echo. (This command takes whatever text is typed as part of the command and echos it to STOUT (usually the display).)

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

Duplicate copies of files can be created with the …?

A

cp (copy) comand.

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

cp [OPTIONS] {SOURCE} {TARGET}

cp [OPTIONS] {SOURCE…} {DIRECTORY}

A

In the first form, a copy of the SOURCE file is made as TARGET. In the second form, one or more files can be copied at one time to a directory. A copy of SOURCE, …, is made in DIRECTORY and named DIRECTORY/SOURCE, …. With the appropriate options (not discussed here - try man cp) whole subdirectory trees can be copied at once.

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

Make a copy of mysong.midi and name the copy backup.midi….?

A

cp mysong.midi backup.midi

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

Make a copy of mynovel.txt in /tmp….?

A

cp mynovel.txt /tmp

The resulting file will be named /tmp/mynovel.txt.

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

Copy the files songs.tar and novels.tgz into the directory /tmp….?

A

cp songs.tar novels.tgz /tmp

The resulting files will be named /tmp/songs.tar and /tmp/novels.tgz.

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

Make a copy of webpage.html from your home directory to the current directory…?

A

cp ~/webpage.html .

The resulting file will be named ./webpage.html.

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

Files can be moved from one directory to another, or from one name to another (renamed), with…?

A

the mv (move) command.

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

mv [OPTION…] {SOURCE} {TARGET}

mv [OPTION…] {SOURCE…} {DIRECTORY}

A

In the first form, the SOURCE file is renamed as TARGET. In the second form, one or more files can be moved at one time to a directory. The files SOURCE, …, are moved to DIRECTORY and named DIRECTORY/SOURCE, …. SOURCE can be a directory, in which case the directory is moved/renamed.

17
Q

Linux treats the name of a file as being distinctly separate from the…?

A

contents of the file. (Even though the command mv stems from the word “move”, mv rarely actually moves data around. Instead the, file system merely records a name change. If the name changes from /somedir/somefile to /somedir/newname, we see this as “renaming” the file. If the name changes from /somedir/somefile to /newdir/somename, we see this as “moving” the file. If the name changes from /somedir/somefile to /newdir/newname, we see this as a double change, both moving and renaming. But to Linux, all of these are the same thing, a change in the FQN for the file.)

18
Q

Rename mysong.midi as backup.midi….?

A

mv mysong.midi backup.midi

19
Q

Move mynovel.txt to /tmp…?

A

mv mynovel.txt /tmp

The resulting file will be named /tmp/mynovel.txt.

20
Q

Move both songs.tar and novels.tgz to /tmp….?

A

mv songs.tar novels.tgz /tmp

The resulting files will be named /tmp/songs.tar and /tmp/novels.tgz.

21
Q

Move webpage.html from your home directory to the current working directory…?

A

mv ~/webpage.html .

The resulting file will be named ./webpage.html.

22
Q

Rename the html subdirectory of the current working directory to public_html…?

A

mv html public_html

This renames ./html as ./public_html, assuming that ./public_html does not already exist - see the next example.

23
Q

Your cwd is your home directory. You have two subdirectories, ~/images and ~/html. Move the images directory to the html directory….?

A

mv images html
The resulting directory will be named ~/html/images. Note the similarity between this example and the previous one. The critical difference is that, in this case, the target directory ~/html already existed, so mv moved the source directory inside (underneath) the target. In the previous example, the target directory did not already exist, so mv renamed the source directory to the new name.

24
Q

Files can be removed (erased, deleted) with the…?

A

rm (remove) command.

25
Q

rm [OPTIONS] {FILE…}

A

Removes the FILE(s) from the filesystem. Technically, it unlinks the FILE(s), a distinction which will be made more clear later. With the appropriate options (not discussed here - try man rm) whole subdirectory trees can be removed at once.

26
Q

rm cannot remove a directory unless …?

A

special command options are used. (There is a separate command, rmdir, for this purpose)

27
Q

rm command can remove…?

A

entire directory trees at once. (In the hands of the superuser it can delete the entire contents of the filesystem in a single stroke – not usually what was intended)

28
Q

documentation for rm includes the following statement….?

A

Note that if you use rm to remove a file, it is usually possible to recover the contents of that file.” While this may be true, it requires expertise beyond the scope of this course, so, for all practical purposes, you should treat this command as non-reversible.

29
Q

Delete mysong.midi…?

A

rm mysong.midi

30
Q

Remove both songs.tar and novels.tgz…?

A

rm songs.tar novels.tgz

31
Q

Remove photos.html from your home directory…?

A

rm ~/photos.html

32
Q

Command redirection with >, and the commands cp and mv all can….?

A

name target files. (Normally, these are new filenames, and the commands create the files. But if an exisiting file is named as a target for redirection, cp or mv, the existing file will be destroyed without warning. This is known as clobbering a file. Because the problem can be so surprisingly subtle to a new user.