103.3 Perform basic file management Flashcards
What command will let you read the contents of a compressed tarball without actually decompressing it?
gzip: zcat tarball.tar.gz
bzip2: bzcat tarball.tar.bz2
xz: xzcat tarball.tar.xz
What does the caret character do in globbing? (^)
It matches any one character except those in the list. It is case sensitive. It excludes those characters.
What does this expression mean in globbing? : [0-9]
It will match a range of numbers
What does this command do? #ls [Pp]*.csv?
It will list files with names of any character length that start with a capital P or lower case p in their name.
What will #ls ????.txt do?
It will find any files with .txt extension that specifically have 4 characters in their name.
What is a wild card?
It is a symbol that can stand for one or more characters.
What does the star * character stand for?
It matches zero or more characters in an expression of globbing.
What does file globbing help with?
It allows to find or act on files that are matched using wildcards.
What does this command do? #find ~ -name "*.tar.*" -exec cp -v {} /home/admin \;
It will find in the home directory any files that have tar in their name and pass the output to exec to copy what find found and show verbosely what it is copying to /home/admin
What does this command do? #find . -empty -type f -exec rm -f {} \;
It will find within the home directory empty files types and execute a deletion without being prompted for confirmation for all results found by the find command.
How do you close an exec statement in a command?
By using \; (backslash and semicolon) #find . -empty -type f -exec rm -f {} \;
What does the exec statement do in the file command?
The exec statement for the find command will act on the result of the find command itself.
How do you find a file type in a path?
find path -type f
How do you find a file type in a path?
find path -type f
How do you find files that are empty in a directory?
find path -empty
What command do you use to find a file that has been added to a directory prior to another one?
find path -newer filenameforreference
How do you find a file that has been accessed within a specific amount of time?
#find path -atime 2 2=48hrs
How do you find a file that has been changed within a specific amount of time?
#find path -ctime 1 1 stands for the last 24 hours period. 2 = 48hrs 3= 72hrs ....
Which user can find files outside the user’s own home directory?
root. So you have to append the find command with [sudo]
What command decompresses a file created with xz?
unxz file.xz
How do you use the xz command to compress a single file?
xz passwd
How do you use the bunzip2 command to decompress a single file?
bunzip2 compressedfile.bz2
How do you use the gunzip command to decompress a single file?
gunzip file.gz
What is the syntax to compress a single file using bzip2?
bzip2 filetocompress
What do the commands gzip and bzip2 do to the original file it compresses?
It replaces the original file with the new compressed file.
How do you use the gzip command to compress a single file?
gzip filetocompress
What is the syntax to decompress a file created with bzip2?
tar -xvjf tarball.tar.bz2
What command compresses more a file, gzip or bzip2?
bzip2
What uses more cpu power to compress files, gzip or bzip2?
bzip2
What command extracts .gz compressed files?
gunzip
What is the command to tar and compress with gzip in one go?
#tar -czf newcompressed.tgz dirtocompress #tar -czf newcompressed.tar.gz dirtocompress
What is the command to extract the contents of an archive tarball?
tar -xf tarball.tar
What is the tar syntax to see the contents of a tarball without extracting it?
tar -tf tarball.tar
What is the basic tar syntax to create a tarball?
#tar -cf tarballname.tar originalfileordir #tar -cf tarball.gar /home/admin/
What is the result of the tar command called?
A tarball
Does tar compress files sizes?
No, it only bundles together a set of files. It occupies the same amount of disk space.
What flag of the l command will display the size of a file in human readable format?
ls -lh filename
What command will produce a random file of 10M ?
sudo dd if=/dev/urandom of=filename bs=1024K count=10
What is a use of the dd command?
It is used to back up files.
What does the dd command do?
It converts files and copies files.
What does archiving do?
It bundles together a set of files or directories into a single file.
How is ./ used when running a script?
You can use it to run a script that is not in your $PATH to run the script from a different location, provided you are already in that different path. Otherwise, you’d have to specify the absolute location of the application you want to run.
What does the $PATH environment do?
It lists out all of the directories you can run an application from without specifying the absolute path to the particular application.
How would you delete a directory with folders within?
rm -r /directoryname
What will the command rmdir do if the folder contains other folders within?
It will fail. The rmdir command will only remove an empty directory.
What command do you use to remove an empty folder?
rmdir foldername
What command creates a brand new directory and subdirectories in one go?
mkdir -p /parentdir/childdir/childdir
What command creates a brand new directory?
mkdir directoryname
What are 2 ways to go from any location in the file system to the home directory?
- # cd ~
2. using the absolute path for the [cd] command
How does bash know what the old location we were in?
Using the $OLDPWD environment variable
Where does the pwd command get its information from?
From the pwd environment variable $PWD
What command would you use to go from the current directory to the immediate directory above it?
cd ..
What does the . and the .. mean in the output of ls -a?
. current directory
.. the directory above the current directory
How can you tell a user is located at his own home directory?
By the tilde at the end of the prompt: [~]
What command takes the user from any path to the user’s home directory?
cd
What does the #file command do?
It tells the user the file type.
Example: ASCII text, gzip file, binary file, ASCII executable (for scripts).
How can you interact with the #mv command to be prompted if we want to overwrite a filename if the destination file name already exists?
mv -i
What goes behind the scenes when using mv to rename a file?
We move the original file into a new file name.
How can you force the rename of a file if the destination file name already exists?
mv -f
What is the general syntax of the mv command?
#mv originalfile renamedfile #mv originalfile /destinationfolder
What does the mv command do?
It moves a file to a new location and also can rename a file
What flag of the rm command forces removal of a directory that contains other folders within?
[-f] #rm -rf /etc
Why would the #rm command fail to remove a directory?
Because it has other folders within.
What flag of the #rm command interacts with the user to ask if we are sure we want to delete a file?
[-i] #rm -i test.sh
What flag of the rm command forces a file to be deleted?
[-f ] #rm -f test.sh
What flag of the cp command forces the overwriting of the copied command in the destination?
[-f]
EX:
#cp -f test.sh test.sh.bak
What flag do you use for the cp command to prevent overwriting a file if the file already exists at the destination?
[-i]
EX:
#cp -i /etc/test.sh /etc/test.sh.bak
cp: overwrite ´test.sh.bak´?
What is the flag that will display what the cp command is copying while doing it for a directory with directories within?
cp -vR originaldirectory directory_bak
Example:
#cp -vR directory locationofdirectory_bak
What command is used to create a copy of a file, like a backup ?
#cp originalfile backupfile Example: #cp test.sh test.sh.bak
What command is used to modify the timestamp of a file?
touch -m filename
What are 2 of the uses for the #touch command?
touch is used to modify a file’s access time
touch is used to create an empty file
What command provides a listing of folders and files?
The [ l ] command, It can be combined with:
- a for hidden files and folders
- l for long listing to see perms, user, group and date
- d for the name of a directory itself
- R to list recursively contents within a folder
What is the syntax to find a file by name?
#find path -name filename #find /home/admin -name test.txt