04 Manipulating Files and Directories Flashcards
What does the wildcard * match?
Any characters
What does the wildcard ? match?
Any single character
What does the wildcard [characters] match?
Any characters of the set [characters]
What does the wildcard [!characters] match?
Any characters that don’t belong to the set [characters]
What does the wildcard [[:class:]] match?
Any characters that belong to the specified class
What does the special class [:alnum:] match?
Any alphanumeric characters
What does the special class [:alpha:] match?
Any alphabetic characters
What does the special class [:digit:] match?
Any number
What does the special class [:lower:] match?
Any lower-case characters
What does the special class [:upper:] match?
Any uppercase characters
Which files would the wildcard * match?
All files
Which files would the wildcard g* match?
Any files that begin with “g”
Which files would the wildcard b*.txt match?
Any files that begin with “b” and end with “.txt”
Which files would the wildcard Data??? match?
Any files beginning with “Data” followed by exactly 3 characters
Which files would the wildcard [abc]* match
Any files that begin with the lower-case letters “a”, “b”, or “c”
Which files would the wildcard BACKUP.[0-9][0-9][0-9] match?
Any files beginning with “BACKUP.” followed by exactly 3 numerals
Which files would the wildcard [[:upper:]]* match?
Any files beginning with an upper-case letter
Which files would the wildcard [![:digit:]]* match?
Any file not beginning with a numeral
Which files would the wildcard *[[:lower:]123]
Any file ending with a lower-case letter or a “1”,”2”,or”3”
How many directories can you create using a single instance of the mkdir command?
You can make multiple directories using mkdir in a single instance…mkdir dir1 dir2 dir3…etc
What would be the result of the following command:
cp item1 item2
File or directory Item1 would be copied to file or directory item2
What would be the result of the following command:
cp item1… dir1
File item1 would be copied into dir1
Describe the use of the following cp options:
-a / –archive
Copy files/dirs with their existing attributes, instead of the attributes of the user performing the copy
Describe the use of the following cp options:
-i / –interactve
Prompt for confirmation before copying (and possibly overwriting) the destination item.
Describe the use of the following cp options:
-r / –recursive
Recursively copy (go into each subdirectory and copy) the directory contents
Describe the use of the following cp options:
-u / –update
Only copy items that are new or have changed.
Describe the use of the following cp options:
-v / –verbose
Display informative messages as copy progresses
Describe the use of the mv command
Moves or renames files
Describe the use of the following mv options:
-i / –interactive
Prompt for confirmation before moving/renaming (and possibly overwriting) the destination item.
Describe the use of the following mv options:
-u / –update
When moving files from one directory to another, only move the files that don’t exist or are newer than existing corresponding files
Describe the use of the following mv options:
-v / –verbose
Display informative messages as move progresses
Describe the use of the rm command
Remove (delete) files or directories
Describe the use of the following rm options:
-i / –interactive
Prompt for confirmation before deleting a file
Describe the use of the following rm options:
-r / –recursive
If a directory being deleted has subdirectories, remove them, too. This option must be specified in order to delete a directory
Describe the use of the following rm options:
-f / –force
Don’t prompt when deleting files, ignore non-existent files
Describe the use of the following rm options:
-v / –verbose
Display informative messages as the deletion is performed.
What are two restrictions to keep in mind when creating hard links?
- Hard link cannot refer to file on another filesystem
2. Hard links cannot refer to a directory
True or False: every file has a single hard link that gives that file its name
True
True or False: a hard link is completely indistinguishable from the referenced file itself
True. Hard links have no special indicators of their link
True or False: if a hard link is deleted, the file that it links to is also deleted
False
How do you create a hard link to a file?
ln file link
True or False: a symlink can represent a file or a directory
True. Hardlinks can only reference files
True or False: a symlink is a text pointer to a referenced file or directory
True
True or False: if a symlink is deleted, only the link is removed; the original file remains intact
True
What is the term for the situation that occurs when a file is symlinked and the original file is deleted
a “broken” link
How would you determine if an item is hard linked?
Hardlinks are indistinguishable from originals. You would need to compare the inodes of the two files to see if they referenced the same “portion” of the disk. You could do that by ls -li
How would you create a symlink to the file foo.txt?
Go to location where you wish to create the symlink and create it relative to the original. For example, if the symlink is to be created in directory ‘baz’ and the original is in the parent directory:
pwd
baz
ln -s ../foo.txt bar.txt