103.3 Perform basic file management Flashcards

1
Q

What command will let you read the contents of a compressed tarball without actually decompressing it?

A

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.

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

What does this expression mean in globbing? : [0-9]

A

It will match a range of numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
What does this command do? 
#ls [Pp]*.csv?
A

It will list files with names of any character length that start with a capital P or lower case p in their name.

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

What will #ls ????.txt do?

A

It will find any files with .txt extension that specifically have 4 characters in their name.

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

What is a wild card?

A

It is a symbol that can stand for one or more characters.

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

What does the star * character stand for?

A

It matches zero or more characters in an expression of globbing.

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

What does file globbing help with?

A

It allows to find or act on files that are matched using wildcards.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
What does this command do?
#find ~ -name "*.tar.*" -exec cp -v {} /home/admin  \;
A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
What does this command do?
#find . -empty -type f -exec rm -f {} \;
A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you close an exec statement in a command?

A
By using  \;  (backslash and semicolon)
#find . -empty -type f -exec rm -f {} \;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does the exec statement do in the file command?

A

The exec statement for the find command will act on the result of the find command itself.

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

How do you find a file type in a path?

A

find path -type f

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

How do you find a file type in a path?

A

find path -type f

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

How do you find files that are empty in a directory?

A

find path -empty

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

What command do you use to find a file that has been added to a directory prior to another one?

A

find path -newer filenameforreference

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

How do you find a file that has been accessed within a specific amount of time?

A
#find path -atime 2
2=48hrs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How do you find a file that has been changed within a specific amount of time?

A
#find path -ctime 1 
1 stands for the last 24 hours period. 
2 = 48hrs
3= 72hrs ....
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Which user can find files outside the user’s own home directory?

A

root. So you have to append the find command with [sudo]

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

What command decompresses a file created with xz?

A

unxz file.xz

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

How do you use the xz command to compress a single file?

A

xz passwd

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

How do you use the bunzip2 command to decompress a single file?

A

bunzip2 compressedfile.bz2

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

How do you use the gunzip command to decompress a single file?

A

gunzip file.gz

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

What is the syntax to compress a single file using bzip2?

A

bzip2 filetocompress

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

What do the commands gzip and bzip2 do to the original file it compresses?

A

It replaces the original file with the new compressed file.

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

How do you use the gzip command to compress a single file?

A

gzip filetocompress

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

What is the syntax to decompress a file created with bzip2?

A

tar -xvjf tarball.tar.bz2

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

What command compresses more a file, gzip or bzip2?

A

bzip2

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

What uses more cpu power to compress files, gzip or bzip2?

A

bzip2

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

What command extracts .gz compressed files?

A

gunzip

30
Q

What is the command to tar and compress with gzip in one go?

A
#tar -czf newcompressed.tgz dirtocompress
#tar -czf newcompressed.tar.gz dirtocompress
31
Q

What is the command to extract the contents of an archive tarball?

A

tar -xf tarball.tar

32
Q

What is the tar syntax to see the contents of a tarball without extracting it?

A

tar -tf tarball.tar

33
Q

What is the basic tar syntax to create a tarball?

A
#tar -cf tarballname.tar originalfileordir
#tar -cf tarball.gar /home/admin/
34
Q

What is the result of the tar command called?

A

A tarball

35
Q

Does tar compress files sizes?

A

No, it only bundles together a set of files. It occupies the same amount of disk space.

36
Q

What flag of the l command will display the size of a file in human readable format?

A

ls -lh filename

37
Q

What command will produce a random file of 10M ?

A

sudo dd if=/dev/urandom of=filename bs=1024K count=10

38
Q

What is a use of the dd command?

A

It is used to back up files.

39
Q

What does the dd command do?

A

It converts files and copies files.

40
Q

What does archiving do?

A

It bundles together a set of files or directories into a single file.

41
Q

How is ./ used when running a script?

A

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.

42
Q

What does the $PATH environment do?

A

It lists out all of the directories you can run an application from without specifying the absolute path to the particular application.

43
Q

How would you delete a directory with folders within?

A

rm -r /directoryname

44
Q

What will the command rmdir do if the folder contains other folders within?

A

It will fail. The rmdir command will only remove an empty directory.

45
Q

What command do you use to remove an empty folder?

A

rmdir foldername

46
Q

What command creates a brand new directory and subdirectories in one go?

A

mkdir -p /parentdir/childdir/childdir

47
Q

What command creates a brand new directory?

A

mkdir directoryname

48
Q

What are 2 ways to go from any location in the file system to the home directory?

A
  1. # cd ~

2. using the absolute path for the [cd] command

49
Q

How does bash know what the old location we were in?

A

Using the $OLDPWD environment variable

50
Q

Where does the pwd command get its information from?

A

From the pwd environment variable $PWD

51
Q

What command would you use to go from the current directory to the immediate directory above it?

A

cd ..

52
Q

What does the . and the .. mean in the output of ls -a?

A

. current directory

.. the directory above the current directory

53
Q

How can you tell a user is located at his own home directory?

A

By the tilde at the end of the prompt: [~]

54
Q

What command takes the user from any path to the user’s home directory?

A

cd

55
Q

What does the #file command do?

A

It tells the user the file type.

Example: ASCII text, gzip file, binary file, ASCII executable (for scripts).

56
Q

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?

A

mv -i

57
Q

What goes behind the scenes when using mv to rename a file?

A

We move the original file into a new file name.

58
Q

How can you force the rename of a file if the destination file name already exists?

A

mv -f

59
Q

What is the general syntax of the mv command?

A
#mv originalfile renamedfile
#mv originalfile /destinationfolder
60
Q

What does the mv command do?

A

It moves a file to a new location and also can rename a file

61
Q

What flag of the rm command forces removal of a directory that contains other folders within?

A

[-f] #rm -rf /etc

62
Q

Why would the #rm command fail to remove a directory?

A

Because it has other folders within.

63
Q

What flag of the #rm command interacts with the user to ask if we are sure we want to delete a file?

A

[-i] #rm -i test.sh

64
Q

What flag of the rm command forces a file to be deleted?

A

[-f ] #rm -f test.sh

65
Q

What flag of the cp command forces the overwriting of the copied command in the destination?

A

[-f]
EX:
#cp -f test.sh test.sh.bak

66
Q

What flag do you use for the cp command to prevent overwriting a file if the file already exists at the destination?

A

[-i]
EX:
#cp -i /etc/test.sh /etc/test.sh.bak
cp: overwrite ´test.sh.bak´?

67
Q

What is the flag that will display what the cp command is copying while doing it for a directory with directories within?

A

cp -vR originaldirectory directory_bak
Example:
#cp -vR directory locationofdirectory_bak

68
Q

What command is used to create a copy of a file, like a backup ?

A
#cp originalfile backupfile
Example:
#cp test.sh test.sh.bak
69
Q

What command is used to modify the timestamp of a file?

A

touch -m filename

70
Q

What are 2 of the uses for the #touch command?

A

touch is used to modify a file’s access time

touch is used to create an empty file

71
Q

What command provides a listing of folders and files?

A

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
72
Q

What is the syntax to find a file by name?

A
#find path -name filename
#find /home/admin -name  test.txt