Linux Book Review for Quiz 4 (Chapters 17-19 in book - not slides)

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Find using the -delete Action

Action - Delete the currently matching file.

Find using the -print Action

Action - Output the full pathname of the matching file to standard output. This is the default action if no other action is specified.

Find using the -ls Action

Action - Perform the equivalent of ls -dils on the matching file. Output is sent to standard output.

Find using the -quit Action

Action - Quit once a match has been made.

rsync Definition

Definition -

Regular Expressions Definition

Definition - These are symbolic notations used to identify patterns in text. In some ways, they resemble the shell's wildcard method of matching file and pathnames but on a much grander scale. They are supported by many command line tools and by most programming languages to facilitate the solution of text manipulation problems.

gzip Definition

Definition - This command program is used to compress one or more files. When executed, it replaces the original file with a compressed version of the original. The corresponding gunzip program is used to restore compressed files to their original, uncompressed form.

Archiving Definition

Definition - This is a common file-management task often used in conjunction with compression. It is the process of gathering up many files and bundling them together into a single large file. It is often done as part of system backups. It is also used when old data is moved from a system to some type of long-term storage.

grep Program Definition

Definition - This is actually derived from the phrase "global regular expression print," so we can see that this program has something to do with regular expressions. In essence, this program searches text files for the occurrence text matching a specified regular expression and outputs any line containing a match to standard output.

tar Definition

Definition - This is the classic tool for archiving files. Its name, short for tape archive, reveals its roots as a tool for making backup tapes. While it is still used for that traditional task, it is equally adept on other storage devices. We often see filenames that end with the extension .tar or .tgz, which indicate a "plain" archive and a gzipped archive, respectively. This type of archive can consist of a group of separate files, one or more directory hierarchies, or a mixture of both.

Compressing files Definition

Definition - This is the process of removing redundancy from data. These algorithms (the mathematical techniques used to carry out the compression) fall into two general categories. Lossless and Lossy

zip Definition

Definition - This program is both a compression tool and an archiver. The file format used by the program is familiar to Windows users, as it reads and writes .zip files. In Linux, however, gzip is the predominant compression program, with bzip2 being a close second.

lossless compression Definition

Definition - This type of compression preserves all the data contained in the original. This is the only one a computer can tolerate (No computer can tolerate lossed data). This means that when a file is restored from a compressed version, the restored file is exactly the same as the original, uncompressed version.

lossy compression Definition

Definition - This type of compression removes data as the compression is performed to allow more compression to be applied. When a lossy file is restored, it does not match the original version; rather, it is a close approximation. Examples of lossy compression are JPEG (for images) and MP3 (for music).

unzip Command Example

Example - [me@linuxbox ~]$ cd foo [me@linuxbox foo]$ unzip ../playground.zip

rsync Example

Example - [me@linuxbox ~]$ rsync -av playground foo This command is invoked like this: rsync options source destination where source and destination are one of the following: ● A local file or directory ● A remote file or directory in the form of [user@]host:path ● A remote rsync server specified with a URI of rsync://[user@]host[:port]/path Note that either the source or the destination must be a local file. Remote-to-remote copying is not supported. We've included both the -a option (for archiving — causes recursion and preservation of file attributes) and the -v option (verbose output) to make a mirror of the playground directory within foo. While the command runs, we will see a list of the files and directories being copied. At the end, we will see a summary message like this indicating the amount of copying performed: sent 135759 bytes received 57870 bytes 387258.00 bytes/sec total size is 3230 speedup is 0.02 if we run it again, it will show a different result

zip Command Example

Example - [me@linuxbox ~]$ zip -r playground.zip playground In this Example, we include the -r option for recursion. If you dont use the -r, only the playground directory is stored. Although the addition of the extension .zip is automatic, we will include the file extension for clarity. During the creation of the zip archive, zip will normally display a series of messages like this: adding: playground/dir-020/file-Z (stored 0%) adding: playground/dir-020/file-Y (stored 0%) adding: playground/dir-020/file-X (stored 0%) adding: playground/dir-087/ (stored 0%) adding: playground/dir-087/file-S (stored 0%) These messages show the status of each file added to the archive. zip will add files to the archive using one of two storage methods: either it will "store" a file without compression, as shown here, or it will "deflate" the file that performs compression. The numeric value displayed after the storage method indicates the amount of compression achieved. Since our playground contains only empty files, no compression is performed on its contents.

Find using the ~ Action Example

Example - find ~ This produced a list of every file and subdirectory contained within our home directory. It produced a list because the -print action is implied if no other action is specified. Thus, our command could also be expressed as follows: find ~ -print

Find Files Testing parameters

Find Test Parameters - File Type .....Description b ......................Block special device file c ......................Character special device file d ......................Directory f .......................Regular file l .......................Symbolic link

tar using the -r Mode

Mode - Append specified pathnames to the end of an archive.

tar using the -c Mode

Mode - Create an archive from a list of files and/or directories.

tar using the -x Mode

Mode - Extract an archive.

tar using the -t Mode

Mode - List the contents of an archive.

gzip -d Option

Option - Decompress. This causes gzip to act like gunzip. Long option can be written as followed: --decompress --uncompress

Find using the -noleaf Option

Option - Direct find not to optimize its search based on the assumption that it is searching a Unix-like file system. This is needed when scanning DOS/Windows file systems and CD-ROMs.

Find using the -mount Option

Option - Direct find not to traverse directories that are mounted on other file systems.

Find using the -depth Option

Option - Direct find to process a directory's files before the directory itself. This option is automatically applied when the -delete action is specified.

gzip -h Option

Option - Display usage information. Long option can be written as followed: --help

gzip -v Option

Option - Display verbose messages while compressing. Long option can be written as followed: --verbose

grep with ""-h"" option

Option - For multi-file searches, suppress the output of filenames. Long option can be written as followed: --no-filename

gzip -f Option

Option - Force compression even if a compressed version of the original file already exists. Long option can be written as followed: --force

gzip -r Option

Option - If one or more arguments on the command line is a directory, recursively compress files contained within them. Long option can be written as followed: --recursive

grep with ""-i"" option

Option - Ignore case. Do not distinguish between uppercase and lowercase characters. Long option can be written as followed: --ignore-case

grep with ""-v"" option

Option - Invert match. Normally, grep prints lines that contain a match. This option causes grep to print every line that does not contain amatch. Long option can be written as followed: --invert-match

grep with ""-L"" option

Option - Like the -l option, but print only the names of files that do not contain matches. Long option can be written as followed: --files-without-match

gzip -l Option

Option - List compression statistics for each file compressed. Long option can be written as followed: --list

grep with ""-n"" option

Option - Prefix each matching line with thenumber of the line within the file. Long option can be written as followed: --line-number

grep with ""-l"" option

Option - Print the name of each file that contains a match instead of the lines themselves. Long option can be written as followed: --files-with-matches

grep with ""-c"" option

Option - Print the number of matches (or non-matches if the -v option is also specified) instead of the lines themselves. Long option can be written as followed: --count

gzip -number Option

Option - Set amount of compression. number is an integer in the range of 1 (fastest, least compression) to 9 (slowest, most compression). The values 1 and 9 may also be expressed as --fast and --best, respectively. The default value is 6.

Find using the -maxdepth levels Option

Option - Set the maximum number of levels that find will descend into a directory tree when performing tests and actions.

Find using the -mindepth levels Option

Option - Set the minimum number of levels that find will descend into a directory tree before applying tests and actions.

gzip -t Option

Option - Test the integrity of a compressed file. Long option can be written as followed: --test

gzip -c Option

Option - Write output to standard output and keep the original files. Long option can be written as followed: --stdout --to-stdout

Find with ( ) Logical Operator Test

Test - Groups tests and operators together to form larger expressions. This is used to control the precedence of the logical evaluations. By default, find evaluates from left to right. It is often necessary to override the default evaluation order to obtain the desired result. Even if not needed, it is helpful sometimes to include the grouping characters to improve the readability of the command. Note that since the parentheses have special meaning to the shell, they must be quoted when using them on the command line to allow them to be passed as arguments to find. Usually the backslash character is used to escape them.

Find with -iname pattern Test

Test - Like the -name test but case-insensitive.

Find with -empty Test

Test - Match empty files and directories.

Find with -nouser Test

Test - Match file and directories that do not belong to a valid user. This can be used to find files belonging to deleted accounts or to detect activity by attackers.

Find with -group name Test

Test - Match file or directories belonging to group. group may be expressed either as a group name or as a numeric group ID.

Find with -nogroup Test

Test - Match files and directories that do not belong to a valid group.

Find with -newer file Test

Test - Match files and directories whose contents were modified more recently than the specified file. This is useful when writing shell scripts that perform file backups. Each time you make a backup, update a file (such as a log) and then use find to determine which files have changed since the last update.

Find with -name pattern Test

Test - Match files and directories with the specified wildcard pattern.

Find with -size n Test

Test - Match files of size n.

Find with -type c Test

Test - Match files of type c.

Find with -user name Test

Test - Match files or directories belonging to user name. The user may be expressed by a username or by a numeric user ID.

Find with -perm mode Test

Test - Match files or directories that have permissions set to the specified mode. mode can be expressed by either octal or symbolic notation.

Find with -cmin n Test

Test - Match files or directories whose content or attributes were last modified exactly n minutes ago. To specify less than n minutes ago, use -n, and to specify more than n minutes ago, use +n.

Find with -cnewer file Test

Test - Match files or directories whose contents or attributes were last modified more recently than those of file.

Find with -ctime n Test

Test - Match files or directories whose contents or attributes were last modified n*24 hours ago.

Find with -mmin n Test

Test - Match files or directories whose contents were last modified n minutes ago.

Find with -mtime n Test

Test - Match files or directories whose contents were last modified n*24 hours ago.

Find with -inum n Test

Test - Match files with inode number n. This is helpful for finding all the hard links to a particular inode.

Find with -or Logical Operator Test

Test - Match if a test on either side of the operator is true. This can be shortened to -o

Find with -not Logical Operator Test

Test - Match if the test following the operator is false. This can be abbreviated with an exclamation point (!)

Find with -and Logical Operator Test

Test - Match if the tests on both sides of the operator are true. This can be shortened to -a. Note that when no operator is present, -and is implied by default

Find with -samefile name Test

Test - Similar to the -inum test. Match files that share the same inode number as file name.

bzip2 & bunzip2 command

command - A block sorting file compressor (unzip uncompresses) BZip; better compression;.bz2 file suffix

xargs command

command - Build and execute command lines from standard input

touch command

command - Change file times

gzip & gunzip command

command - Compress or expand files (unzip uncompresses) GNU Zip; fast, portable; mostpopular; .gz file suffix

compress command

command - Compress or expand files (unzip uncompresses) traditional unix; .Z file suffix

uuendode command

command - Compress or expand files (unzip uncompresses) uuencoded (replaced by MIME)

stat command

command - Display file or file system status

zip command

command - Package and Compress or expand files (unzip uncompresses) Windows Zip format; .zip file suffix

rsync command

command - Remote file and directory synchronization

tar command

command - Tape archiving utility

xargs Command

command - command performs an interesting function. It accepts input from standard input and converts it into an argument list for a specified command.

Exec Command

command - exec rm '{}' ';' This command is an arbitrary command which uses the {} brackets as a symbolic representation of the current pathname, and the semicolon is a required delimiter indicating the end of the command. Since the brace and semicolon characters have special meaning to the shell, they must be quoted or escaped.

Find using the -xargs Command Example

example - ""find ~ -type f -name 'foo*' -print | xargs ls -l -rwxr-xr-x 1 me me 224 2007-10-29 18:44 /home/me/bin/foo -rw-r--r-- 1 me me 0 2016-09-19 12:53 /home/me/foo.txt Here we see the output of the find command piped into xargs, which, in turn, constructs an argument list for the ls command and then executes it.""

Find using the -or Logical Operator Example

example - ( expression 1 ) -or ( expression 2 ) Example of Using the ""or"" logical Operator [me@linuxbox ~]$ find ~ \( -type f -not -perm 0600 \) -or \( -type d-not -perm 0700 \)

Find Example

example - [me@linuxbox ~]$ find ~

Find with a type -d test Example

example - [me@linuxbox ~]$ find ~ -type d | wc -l This type of test used with the find searching will locate only directories

Find with -type -name & wildcard Example

example - [me@linuxbox ~]$ find ~ -type f -name "*.JPG" -size +1M | wc -l In this example, we add the -name test followed by the wildcard pattern. Notice how we enclose it in quotes to prevent pathname expansion by the shell. Next, we add the -size test followed by the string "+1M". The leading plus sign indicates that we are looking for files larger than the specified number. A leading minus sign would change the meaning of the string to be smaller than the specified number. Using no sign means, "match the value exactly." The trailing letter M indicates that the unit of measurement is megabytes.

Find with a type -f test Example

example - [me@linuxbox ~]$ find ~ -type f | wc -l This type of test used with the find searching will locate only regular files

Find with Piping Example

example - [me@linuxbox ~]$ find ~ | wc -l

grep with ""-l"" option example

example - [me@linuxbox ~]$ grep -l bzip dirlist*.txt dirlist-bin.txt In this example, we use this to list the files that contained the matches rather than the matches themselves by using the -l option.

Locate Example

example - [me@linuxbox ~]$ locate bin/zip

Locate With Grep Example

example - [me@linuxbox ~]$ locate zip | grep bin

gzip & gunzip Example

example - [me@linuxbox ~]$ ls -l /etc > foo.txt [me@linuxbox ~]$ ls -l foo.* -rw-r--r-- 1 me me 15738 2018-10-14 07:15 foo.txt [me@linuxbox ~]$ gzip foo.txt [me@linuxbox ~]$ ls -l foo.* -rw-r--r-- 1 me me 3230 2018-10-14 07:15 foo.txt.gz [me@linuxbox ~]$ gunzip foo.txt [me@linuxbox ~]$ ls -l foo.* -rw-r--r-- 1 me me 15738 2018-10-14 07:15 foo.txt In this example, we create a text file named foo.txt from a directory listing. Next, we run gzip, which replaces the original file with a compressed version named foo.txt.gz. In the directory listing of foo.*, we see that the original file has been replaced with the compressed version and that the compressed version is about one-fifth the size of the original. We can also see that the compressed file has the same permissions and time- stamp as the original. Then the next step we run the gunzip program to uncompress the file. Afterward, we can see that the compressed version of the file has been replaced with the original, again with the permissions and timestamp preserved

bzip2 Example

example - [me@linuxbox ~]$ ls -l /etc > foo.txt [me@linuxbox ~]$ ls -l foo.txt -rw-r--r-- 1 me me 15738 2018-10-17 13:51 foo.txt [me@linuxbox ~]$ bzip2 foo.txt [me@linuxbox ~]$ ls -l foo.txt.bz2 -rw-r--r-- 1 me me 2792 2018-10-17 13:51 foo.txt.bz2 [me@linuxbox ~]$ bunzip2 foo.txt.bz2 As we can see, bzip2 can be used the same way as gzip. All the options (except for -r) that we discussed for gzip are also supported in bzip2. Note, however, that the compression-level option (-number) has a somewhat different meaning to bzip2. bzip2 comes with bunzip2 and bzcat for decompressing files. bzip2 also comes with the bzip2recover program, which will try to reco

grep Example

example - [me@linuxbox ~]$ ls /usr/bin | grep zip This will list all the files in the /usr/bin directory whose names contain the substring zip.

tar using the -x Mode Example

example - [me@linuxbox ~]$ mkdir foo [me@linuxbox ~]$ cd foo [me@linuxbox foo]$ tar xf ../playground.tar [me@linuxbox foo]$ ls playground This example let's extract the playground in a new location. We will do this by creating a new directory named foo, changing the directory and extracting the tar archive.

tar Example

example - [me@linuxbox ~]$ tar cf playground.tar playground This command creates a tar archive named playground.tar that contains the entire playground directory hierarchy. We can see that the mode and the f option, which is used to specify the name of the tar archive, may be joined together and do not require a leading dash. Note, however, that the mode must always be specified first, before any other option.

tar using the -t Mode Example

example - [me@linuxbox ~]$ tar tf playground.tar This Example lists the contents of the archive

tar using the -tv Mode Example

example - [me@linuxbox ~]$ tar tvf playground.tar This Example lists the contents of the archive with extra detailed listing by using the verbose option

Find using the -delete Action Example

example - find ~ -type f -name '*.bak' -delete We can use find to delete files that meet certain criteria. For example, to delete files that have the file extension .bak (which is often used to designate backup files). In this example, every file in the user's home directory (and its subdirectories) is searched for filenames ending in .bak. When they are found, they are deleted.

Find using the -print Action Example

example - find ~ -type f -name '*.bak' -print This command will look for every regular file (-type f) whose name ends with .bak (-name '*.bak') and will output the relative pathname of each matching file to standard output (-print). But this has the ""and"" operator hiden in the expression. To show it you could write this code like this: find ~ -type f -and -name '*.bak' -and -print

Find using the -exec Command and the ""-OK"" Action

example - find ~ -type f -name 'foo*' -ok ls -l '{}' ';' < ls ... /home/me/bin/foo > ? y -rwxr-xr-x 1 me me 224 2007-10-29 18:44 /home/me/bin/foo < ls ... /home/me/foo.txt > ? y -rw-r--r-- 1 me me 0 2016-09-19 12:53 /home/me/foo.txt In this example, we search for files with names starting with the string foo and execute the command ls -l each time one is found. Using the -ok action prompts the user before the ls command is executed.

find command

tools - Search for files the hard way by using a directory hierarchy. This searches a given directory (and its subdirectories) for files based on a variety of attributes. It can be used to identify files that meet specific criteria. It does this through the (slightly strange) application of options, tests, and actions.

locate command

tools - This finds files by name the easy way. It performs a rapid database search of pathnames, and then outputs every name that matches a given substring


Ensembles d'études connexes

NEB - LifeIN - Uses of Life Insurance

View Set

chapter 6 interest groups in texas

View Set

Health Insurance exam guaranteed

View Set