1.2 Given a scenario, manage files and directories Flashcards
Command: cp
copies files or directories to another location
Syntax: cp [options] SOURCE DESTINATION
What 2 options can be used with the cp command to also include the contents of a directory?
-r or -R
Command: mkdir
creates a new directory
Syntax: mkdir [options] DIRECTORY
What option must be used with command mkdir to create all directories in the path if they don’t exist, i.e. /folder1/folder2/directory?
-p
Command: rmdir
removes a directory, if it is empty
Syntax: rmdir [options] DIRECTORY
Command: ls
lists the contents of a directory
Syntax: ls [options] DIRECTORY
Command: pwd
prints full name of the current working directory
Command: cd
changes the current working directory
Syntax: cd [path/directory]
Command: cat
shows, read-only, text of a file
Syntax: cat [filename]
Command: less
like cat, but content is shown with paging
Syntax: less [filename]
Define vi(m)
default text editor included with Linux distributions, can be complex to use
Define nano
Simple, easy to use CLI text editor that must be installed
ls -a, what does the switch “a” do
shows all files/folders, including hidden
ls -l, what does the switch “l” do
long - shows more detailed information, such as permissions, file size, etc…
Command: touch
creates the file, if it doesn’t exist, otherwise updates the modification of the file
Syntax: touch [filename]
Define tar command
- compresses files and directories into a single file
- maintains directory structure and other features such as file permissions
What is the tar command used to backup a directory to a tar file?
tar -cvf [name of tar file] [directory/file to backup]
*note “v” is optional, enables verbose mode to show the progress
What is the tar command used to restore a tar file?
tar -xvf [tar filename]
What does the “d” switch do for tar command?
Compares a directory to the tar file and identifies differences
What does the “J” switch do for tar command?
Specifies use of the xz utility for compression/decompression (.xz)
What does the “z” switch do for tar command?
Specifies use of the gzip utility for compression/decompression (.gz)
What does the “j” switch do for tar command?
Specifies use of the bzip2 utility for compression/decompression (.bz2)
What does the “r” switch do for tar command?
Adds files to the end of an existing tar archive
What does the “t” switch do for tar command?
Lists the files in the tar archive file
How can one back up only the files that have changed since a previous tar backup?
The “u” switch will append files to the tar archive only if the modification date is newer than the file in the tar archive
What is the syntax and switch to restore a tar file to a specified location
tar -xf [tar filename] -C [location]
How do you add files to an existing tar archive?
The “r” switch
What is the basic gzip syntax to compress a file? What potential issue happens using this syntax?
- gzip [filename]
- The original, uncompressed file, is replaced with the new compressed file
What is the syntax to compress a file with gzip to a new file without overwriting the original file?
gzip -C [filename to compress] > [newfilename]
What switch decompresses a file with gzip?
“d”
What gzip switch lists the files in a compressed file?
“l”
What gzip switch recursively compresses all files & sub-directories, and is equal to tar -z?
“r”
What is the basic command syntax to compress a file with xz?
xz [filename]
*this overwrites the original file
What is the syntax to compress a file with xz to a new file without overwriting the original file?
xz -k [filename]
What switch decompresses a file compressed with xz?
“d”