Managing Files Flashcards
Many commands produce “_______” output. Normally, output is displayed on the screen.
Visible.
Linux likes to think of everything as a…?
file.
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, >.
STDOUT
cat…?
Concatenate File(s) to standard output.
Cat command copies each of the…?
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.)
If the file already exists, redirection will….?
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»_space; is used and the target file does not exist, it is created, just as if > had been used.
The > symbol is an example of 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.
Simplest command that produces visible output is…?
Echo. (This command takes whatever text is typed as part of the command and echos it to STOUT (usually the display).)
Duplicate copies of files can be created with the …?
cp (copy) comand.
cp [OPTIONS] {SOURCE} {TARGET}
cp [OPTIONS] {SOURCE…} {DIRECTORY}
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.
Make a copy of mysong.midi and name the copy backup.midi….?
cp mysong.midi backup.midi
Make a copy of mynovel.txt in /tmp….?
cp mynovel.txt /tmp
The resulting file will be named /tmp/mynovel.txt.
Copy the files songs.tar and novels.tgz into the directory /tmp….?
cp songs.tar novels.tgz /tmp
The resulting files will be named /tmp/songs.tar and /tmp/novels.tgz.
Make a copy of webpage.html from your home directory to the current directory…?
cp ~/webpage.html .
The resulting file will be named ./webpage.html.
Files can be moved from one directory to another, or from one name to another (renamed), with…?
the mv (move) command.
mv [OPTION…] {SOURCE} {TARGET}
mv [OPTION…] {SOURCE…} {DIRECTORY}
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.
Linux treats the name of a file as being distinctly separate from the…?
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.)
Rename mysong.midi as backup.midi….?
mv mysong.midi backup.midi
Move mynovel.txt to /tmp…?
mv mynovel.txt /tmp
The resulting file will be named /tmp/mynovel.txt.
Move both songs.tar and novels.tgz to /tmp….?
mv songs.tar novels.tgz /tmp
The resulting files will be named /tmp/songs.tar and /tmp/novels.tgz.
Move webpage.html from your home directory to the current working directory…?
mv ~/webpage.html .
The resulting file will be named ./webpage.html.
Rename the html subdirectory of the current working directory to public_html…?
mv html public_html
This renames ./html as ./public_html, assuming that ./public_html does not already exist - see the next example.
Your cwd is your home directory. You have two subdirectories, ~/images and ~/html. Move the images directory to the html directory….?
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.
Files can be removed (erased, deleted) with the…?
rm (remove) command.
rm [OPTIONS] {FILE…}
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.
rm cannot remove a directory unless …?
special command options are used. (There is a separate command, rmdir, for this purpose)
rm command can remove…?
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)
documentation for rm includes the following statement….?
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.
Delete mysong.midi…?
rm mysong.midi
Remove both songs.tar and novels.tgz…?
rm songs.tar novels.tgz
Remove photos.html from your home directory…?
rm ~/photos.html
Command redirection with >, and the commands cp and mv all can….?
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.