Full Transcript

LINUX ESSENTIALS (010-160): A TIME COMPRESSED RESOURCE TO PASSING THE LPI® LINUX... - Be CHAPTER SIX able to move, copy, and = delete Q B&B Aa files and directories + Understand hard and symbolic links + Understand wildcards and case sensitivity Linux File System + Understand file archiving in Linux...

LINUX ESSENTIALS (010-160): A TIME COMPRESSED RESOURCE TO PASSING THE LPI® LINUX... - Be CHAPTER SIX able to move, copy, and = delete Q B&B Aa files and directories + Understand hard and symbolic links + Understand wildcards and case sensitivity Linux File System + Understand file archiving in Linux From its multiuser inception, operating Linux system. was This designed means as that a any number of users can simultaneously work on a single machine. These users can connect to the system via different terminals or network connections while maintaining a separate storage area for personal information and individual desktop configurations. Among the users working on a machine, Linux also OBJECTIVES - Understand the : difference between Windows and Linux file systems - Be able to navigate through the file system the distinguishes between different kinds of user roles. A user can log into a Linux machine as a normal user or as... the root user, a superuser with privileges that authorize Page 73 of 208 « 35% ©) LINUX ESSENTIALS (010-160): QO Kindle Library A TIME COMPRESSED RESOURCE TO PASSING THE LPI® LINUX... =: Q [— them to access all portions of the system and to execute their syntax to list, create, delete, or edit files and their any necessary administrative tasks. properties. directories where all the user’s private data (like a tree-like structure. The topmost directory is the root documents, bookmarks, and emails) are stored. While a of the file system, which is notated as a single forward user can modify anything in their own home directory, slash (/). Note that the root of the file system is not to only the superuser can modify the system directories be confused with the root user or the root user’s home that directory (/home/root). In hold all the centralized configuration files and To modify these files and folders, a user can choose to use a GUI-based environment file manager or through a a Windows system, the root of the file system is designated as a backslash (\) and executable files on the system. within the desktop shell in the command usually denoted by the drive letter C (usually written as C:\). All the other directories in Linux can be accessed line environment. The traditional method on Linux and Unix from systems hierarchical structure using parent-child relationships. was to use the command line environment, but the GUI-based method is easier for most end users. Unlike While using the command to line is often faster, it does require some deeper knowledge of the commands and LN Within a Linux system, all files and directories are in All users, including the superuser, have their own home Aa root directory Windows, separate instead Page 74 of 208 « 35% the relies the on Linux and does are not arranged use in a backslashes components of a pathname, but forward slashes. Therefore, the Q) LINUX ESSENTIALS (010-160): QO Kindle Library private in data of a user in Windows instead be stored under might be stored RESOURCE TO PASSING THE LPI® LINUX... the directory tree unless they are mounted. Mounting a system at a specific location within the directory tree. If Linux does a device isn’t mounted, a normal user cannot access any data on the device or its partitions. Luckily, directory, drive, device, or network they are accessing appearance of the [— /home/diontraining/ in not use drive letters. Instead, a user can detect which the Q device means that it will become integrated into the file but documents. Additionally, Linux, unlike Windows, from =: it C:\users\diontraining\documents, might A TIME COMPRESSED pathname itself. For most automatically mount modern Linux distributions partitions and devices for their example, you might access the storage directory on the end secondary hard disk drive by using /dev/disk1/storage/. partitions to automatically mount when the system is started. Key File System Features and Linux is the concept of mounting unmounting During the Removable installation, devices users are usually and partitions, drives, and directories. When are connected. Gnome and becomes process, device yourself, you will use the mount letter to them. also detected However, Linux partitions or devices are usually not visible in version commands. Page 74 of 208 « 35% of Linux To learn a new device accessible. If you are using an a drive define such as KDE or will notify the end user when is mounted older Desktop environments Windows detects partitions and drives during the boot it assigns can and mounted automatically by the system when they Another crucial difference to understand between Windows users. and about the need to mount the and umount exact usage of these Aa LN LINUX ESSENTIALS (010-160): A TIME COMPRESSED RESOURCE TO PASSING THE LPI® LINUX... = Q Ba commands, please use the man pages for them on your on the three-letter extension. Many users still add the Linux system. three letter extensions, though, since it makes it easier Unlike Windows, Linux distinguishes between for users to identify a file’s type and use. Like uppercase and lowercase letters within the file system. Windows, Linux does distinguish between Therefore, if you change the file test.txt to TeST.txt or normal files and hidden files. In general, the system uses Test.txt, hidden files to hold configuration details. Hidden files Linux considers all three different files. This case sensitivity holds true for both files and directories are indicated by a dot in front of the file name, within the file system. So, if you have Letters and letters as.hiddenfile. In order to access a hidden file, you can as directories, Linux would treat them as two different switch the properties or options for the view in the file directories within. managers or use certain command syntax options in the Another major difference between Linux and such shell. Windows is the use of file extensions to define what a file As stated earlier, Linux is a multiuser system and, is used for. For example, in Windows a file will end in txt therefore, every file must belong to a specific user and if it is a text file. In Linux, files may have a file extension, a group. Only the owner such as.txt, but it is not required. Instead, the operating the root user) can grant system looks at the contents to access of the file to determine which application can read it instead of simply relying them. Linux of a other file or users distinguishes directory the (or permission between three different types of access permissions: write permissions, Page 75 of 208 « 36% Qh LINUX ESSENTIALS (010-160): A TIME COMPRESSED RESOURCE TO PASSING THE LPI® LINUX... read permissions, and execute permissions. Users can = Q Ba change except through direct intervention by the system only access a file or a folder if they have at least a read administrator. For example, permission to it. There are several ways to change the are considered static files. On access permissions automated scripts, servers, or other devices can change of files and folders: either via the doing the each certain need Linux things, for some their directory distro all Linux has developers standardization structures. its own in the To address way of recognize layout executable the program other hand, files users, variable files. For example, most of the files stored in a shell or with the help of the desktop's file manager. Although users’ home directory are variable files since the user can easily change their contents. of Navigating Files and Directories this need, the Filesystem Hierarchy Standard (FHS) was created. The Now that we have an overview of the file system, FHS makes an important distinction between shareable it is time to learn how to navigate around it from the and unshareable files. Shareable files may be reasonably command line. But, before you can manipulate files and shared between computers, directories, it is important to understand which files are such as user data files and program binary files. Unshareable files contain systemspecific information, FHS makes a second such as configuration important distinction Qh in which directories. files. The The Is command, short for list, provides this between information. If no command line options are used with static files and variable files. Static files do not usually the command, the output will simply display the files in Page 76 of 208 « 37% Q) LINUX ESSENTIALS (010-160): QO Kindle Library A TIME COMPRESSED RESOURCE TO PASSING THE LPI® LINUX... = Q B&B the current directory. However, additional options and include the “-d” option. If you want to learn about the ls file or directory specifications can be provided to display command in more detail, type man ls at the prompt to more display the man page for the ls command. detailed information. For example, using the '"- a" option displays all files including hidden files, such The cd command, short for change directory, as the files and folders which begin with a dot. If you changes the current directory to another one provided instead use the "-1" option, it displays a detailed output, by the user. Although which includes permission strings, ownership, file sizes, matter and file creation dates in addition to the filenames. referring to certain file manipulation commands. When Another useful option is the “-d” option, which is used when working with in a directory that holds a wildcard with Ils directories. many that When working subdirectories, matches one or for working Linux many with uses the current commands, the cd a forward it command, directory will do doesn’t matter not slash as a directory when forget that separator, using as opposed to the backslash (\) used in Windows more this purpose. The forward slash and backslash are not subdirectories may get an unexpected result: the output interchangeable, will show the files in the matched subdirectories, rather proper one for the operating system they are using. In than the information on the subdirectories themselves. fact, the backslash has a different meaning in Linux: a To get information backslash serves as a “quote” or “escape” character to the contents on the subdirectories rather than of those subdirectories, you can instead so it is up to the user to use for the enter otherwise hard-to-specify characters like spaces Page 77 of 208 « 37% Aa LINUX ESSENTIALS (010-160): A TIME COMPRESSED RESOURCE TO PASSING THE LPI® LINUX... = Q as part of a filename. Typing cd followed by a forward in /home/user1/file.txt, which refers to the file.txt file slash and the directory name or path to change to will in user1’s home make the shell switch to that directory. Do take note that begin with the single forward slash since they start at depending on the distro and shell being used, changing the root of the file system. A home directory reference uses the tilde character to prompt displayed by the shell. To know the complete refer to the user’s home directory. If a filename begins path of the current location, the we can always enter with that character, it is as if the path to the user’s home (present working directory) at the directory has been substituted for the tilde. For user1, ~/ directory may the pwd command file.txt is equivalent to the absolute reference of /home/ command prompt. Remember that Linux uses a unified directory tree. This means that all the files on the system user1/file.txt. A relative reference are refers to a file reference that located relative to a single root directory (/), which is is made relative to the current directory. Every Linux represented by using the single forward slash character. directory Files and directories can be referenced in three includes two special hidden subdirectories known as dot (.) and dot dot (..). Dot (.) refers to the current directory. This is also ways: absolute references, home directory references, or file known as the present working directory. Personally, I to be referenced relative to the root directory, such as always refer to it as “here”. Therefore, if you want to relative references. An absolute reference allows a Page 78 of 208 « 38% Aa directory. Absolute references always not actually reflect in the the current B&B Q) LINUX ESSENTIALS (010-160): QO Kindle Library A TIME COMPRESSED =: Q [— within the shell. create a relative path, you can use the single dot as your starting point within RESOURCE TO PASSING THE LPI® LINUX... a command or file’s paths. Normally, commands The dot dot (..) refers to the parent directory. This files that are created manipulate by them. programs For or example, a is the directory one level above the current directory. graphics program like GIMP might create a new graphics Again, this is used heavily when creating relative paths file. The exact process to create a file differs depending to different files and directories across the filesystem. on the program, but most GUI programs typically use a For example, if user2 is working in the directory / menu option called Save or Save As to create and save home/user2/, user2 can refer to userl’s home directory a file. Text-based programs within the command by using../userl. This references the directory above / often provide a similar functionality, but the details of home/user2 how it is done vary greatly from one program to another. (/home) and then the subdirectory user 1 The most basic file creation program is touch. The within that directory. touch command is Manipulating Files We can manipulate line files by using many a new, different empty acommand line program that creates text file at the location provided parameter when the command as a first runs. To create a commands. Files can be created, copied them from one new file, simply type “touch” followed by the name of location or folder to another, moved, renamed, or even a file; for example, type “touch newfile.txt” to create deleted from the file system using different commands an empty Page 79 of 208 « 38% file called newfiletxt within your present Aa LN LINUX ESSENTIALS (010-160): QO Kindle Library working directory. Normally, it is not A TIME COMPRESSED necessary RESOURCE TO PASSING THE LPI® LINUX... to If you want to move or rename a = Q B&B file, we use the create a file of a particular type, since a program will same automatically create the matching the file type needed command, for its file format. Sometimes, though, it is helpful to uses syntax and usage that is like the cp command. If a create an empty file just to create a few disposable files filename is specified with the destination, the file will be to test some other command while you are learning your renamed while being moved. If a filename is specified, way around the shell and its usage. and the destination directory is the same as the source Another command that is useful in working with command for both. which This command stands for move. The mv is the mv command directory, the file will be renamed but not moved. The files is the cp command. This command, short for copy, mv is used to copy files from one directory to another. It the new file replaces the original file instead of simply can be used in three different ways: to paste an option duplicating for a source filename and a destination filename, command’s like cp, except that it. Also, when a effects are much the source and target files are on the destination directory name, or both. The cp command same filesystem, mv rewrites directory entries without also physically moving the file’s data on the disk. When provides many other options that modify its a behavior. To learn all the details about the cp command, file moves from one filesystem to another, though, mv please type “man cp” in the shell to get a list of all the copies the file to the new options and corresponding functions. original file from the source disk. To learn more about Page 80 of 208 « 39% disk and then deletes the Aa LINUX ESSENTIALS (010-160): A TIME COMPRESSED RESOURCE TO PASSING THE LPI® LINUX... the mv command, type “man mv” from the command Sometimes, files are no longer needed on a system. When this command, occurs, which we can stands delete these for remove. files the By typing rm Q Ba One thing that is important to realize about the rm command prompt to view its man page. = is that it does not implement any kind of functionality like the recycle bin within the Windows operating system. Once a file or directory is deleted "rm with rm, it is gone and cannot be recovered except by filename," the file in the current directory will be deleted using low-level forensic file recovery tools, which are from the filesystem. To delete an entire directory tree, well beyond the scope of this introductory course in use the -r option along with a directory name. This -r Linux. Users should always be careful when using the rm stands for recursive and causes the directory and all its command, especially when using the -r switch or when files to be deleted. Another useful option, the -i switch, running the command using root privileges. allows the rm command to prompt before deleting each Hard and Symbolic Links individual file. This switch is a safety measure to make sure that the files are really intended to be deleted and In Linux, sometimes it is handy to refer to a single is especially useful when using rm within an automated file using multiple names rather than creating several script. rm copies of the file. To do this, a user can create multiple and to learn more about them please type links to a file. This is similar to the concept of using a There command, are several other “man rm” at the command prompt. options for the shortcut within Windows. In Linux, there are two types Page 81 of 208 « 39% Qh LINUX ESSENTIALS (010-160): QO Kindle Library A TIME COMPRESSED RESOURCE TO PASSING THE LPI® LINUX... =: Q ££ of links supported by the operating system: hard links a symbolic link file, Linux redirects the access to the and symbolic links. We can create both types by using original file. Because symbolic links work by filename the In command, known as the link command. references, A hard link is a duplicate directory entry where they can where directory entry and the link both connect to the low- linkname is the name level filesystem structures, within a single filesystem. neither of the filenames hard When holds filename is the original name of the file and of the new link to create. This symbolic link is similar to the idea of what most end a hard link, users are familiar with, as it works like a shortcut within over the the Windows filesystem. other. Instead, they are both tied directly to the file’s Wildcards data structures and data. To create a hard link, type "In filename linkname," where filename is the original name of the file and linkname is the name of the link to create. that refers to another file by name. To exist any priority A symbolic link, also known as a boundaries. can links using filesystem create a symbolic link, type "In -s filename linkname," both entries point to the same file. Because the actual data cross When working with files and directories within the command line, a user may want to refer to multiple soft link, is a file items simultaneously. To do this, utilize a wildcard. A This means wildcard is a symbol or set of symbols that stands in that the symbolic link is a file that holds another file’s name for other characters. Wildcards and, when you tell a program to read to or write from is also sometimes called globbing. Linux utilizes three Page 82 of 208 « 40% can refer to files and Aa LN LINUX ESSENTIALS (010-160): QO Kindle Library A TIME COMPRESSED RESOURCE TO PASSING THE LPI® LINUX... =: Q [— different types of wildcards when referencing items in case, the words ball, bell, bowl, bull, and bale would all be the returned. filesystem: the question mark, the asterisk, and bracketed values. Bracketed To better explain the use of these three types of values can replace any character from within the brackets into the search term. For example, if wildcards, pretend you have a directory containing five I enter the command “1s b[aou][lw]1” any files that match different files all starting with the letter B: ball, bell, the letters from within the brackets would be returned. bowIl, bull, bale. In this case, the words ball, bowl, bull would be returned The question mark can replace a single character. For example, if I enter the command “ls b??1” then each file since they can be made by replacing the second and third characters with characters from within the brackets. Wildcards are implemented by the shell and are then that starts with the letter b, has two other letters, and then ends with the letter 1 will be returned. In this case, passed to the command. the words ball, bell, bowl, and bull would all be returned enters the command “1s b??1”, the shell matches b??1 with since they meet the criteria, but the word bale would not. the three files bowl, ball, and bull outputs the results of An asterisk can replace any single character or multiple characters. For example, if I enter the command the command as if the user entered “Is ball bell bowl bull”. “Is b*” then any file that starts with a b will be returned since the * can replace all the letters after the b. In this For example, when the user Please be Page 83 of 208 « 41% take extremely note, careful however, when using that you wildcards. need to If you Aa LN LINUX ESSENTIALS (010-160): QO Kindle Library are careless, wildcards can =: Q [— content of each is exactly the same, the filesystem still and sometimes undesired consequences. For example, considers each as three distinct and different files due to copying two files using wildcards to another directory their different type cases. result in copying to RESOURCE TO PASSING THE LPI® LINUX... unexpected but forgetting to give the lead A TIME COMPRESSED destination the first file while directory may overwriting the within Case Sensitivity is a other unique native filesystem characteristic operating systems like sensitive. This Linux compared Windows, where filesystem from of the follow this media, a non-Linux filesystem, it is highly likely that case-insensitive rules example, NTFS exact same characters but have different type case. Windows), For example, a single directory can hold files called even removable case distinct and separate files whenever they contain the and, some partition on a dual-boot computer, or using a network For AFILE.TXT function to sensitivity, this means that filenames are not treated as and a Linux, then their files will always will apply. Afiletxt, primarily If a user only uses media that is formatted insensitivity is commonplace. Since Linux utilizes case afile.txt, is case sensitivity. But, if a user is accessing a non-Linux is case of sensitivity Linux filesystem and not of the operating system itself, though. second and, in essence, deleting it. Linux’s Case if the if you formatted volume are accessing a (which is commonly FAT or used in then case insensitivity will apply, and the Linux operating system can understand and use that case insensitivity without any issues. Page 84 of 208 « 41% Aa LN LINUX ESSENTIALS (010-160): QO Kindle Library A TIME COMPRESSED But, to further complicate things, some shells (like bash) and programs always assume case sensitivity, even RESOURCE TO PASSING THE LPI® LINUX... well as to perform the =: file-manipulation Q [— commands discussed earlier, such as list, copy, rename, and move. if they are accessing a case-insensitive filesystem. Due to The mkdir command, short for make directory, is this, it is a best practice to always treat your files with used to create a directory. To create a new case sensitivity regardless of the operating system or named newfolder in the current directory, simply type filesystem format you are using if you are working with “mkdir Linux and other operating systems. like right-clicking the mouse and selecting New Folder within Manipulating Directories Most users are filesystem since directories by filesystem, folders familiar most using GUI file are with file folder managers technically the GUI on in the command a Windows prompt. machine. For This is more options with mkdir command, please refer to the mkdir folders icons. newfolder” directory In called within a man page. The represent the Linux directories. destroys rmdir command, or deletes short for remove a directory. directory, To delete a directory named newfolder in the current directory, simply type Linux naturally provides both GUI-based and command “rmdir line tools to manipulate directories located within the using rmdir, remember that file and directory names are filesystem. These include directory-specific commands case sensitive in the Linux filesystem, so it is important that allow users to create and delete directories, as Page 85 of 208 « 42% newfolder” in the command prompt. When Aa LN LINUX ESSENTIALS (010-160): QO Kindle Library A TIME COMPRESSED to specify the correct case to avoid accidentally deleting RESOURCE TO PASSING THE LPI® LINUX... rmdir Q [— delete. the wrong directory. The =: As stated before, the filesystem considers directories command can only delete empty a special file type. These special files simply hold the directories, though. If a directory contains any files or user’s directories, the rmdir command will fail. The -p option, manipulation tools covered previously can manipulate however, can delete a set of nested directories, if none of directories, too. There are some caveats to this general them hold any non-directory files. rule, though. To within rm delete the directories directory command with tree, containing you the recursive can files instead (-r) option. anywhere use the Because it can delete directories that are non-empty, rm with other files. Because of this, most of the file First, the touch command cannot create a directory. Instead, the command mkdir makes a new directory. If the touch command is executed on a directory, it will refresh and update the directory’s time stamp instead. since it The cp command can copy a directory, but only if the can delete files not intended to be deleted. Therefore, user specifies the -r or -a options to copy the directory it is considered a best practice to first execute the ls and all its contents. -r command move the -r option becomes potentially dangerous to display the directory and its contents before attempting to run rm -r to ensure that you are or rename a options are utilized. fully aware of the files and directories you are about to Page 86 of 208 « 42% Similarly, the mv command can directory if the right syntax and Aa LN LINUX ESSENTIALS (010-160): QO Kindle Library A TIME COMPRESSED RESOURCE TO PASSING THE LPI® LINUX... =: Q [— When creating links in the Linux filesystem, the user program is a popular tool for archiving various data files can only create symbolic links to a directory using the In into a single file, called an archive file, while the original -s command. This is because the Linux filesystem does files remain not support or allow hard links to a directory. resulting archive file can become quite large, it is often safely stored on the disk. Because the compressed via the tar program into what is known as Archiving Files a tarball. In fact, tarballs are often used for transferring A file-archiving tool collects a group of files into a multiple files between computers and are considered the single package file. This allows us to easily move the universal method single file around on a single filesystem; back up the file Linux. to a recordable DVD, USB flash drive, or other removable numerous options, but the most common options are all media; that is needed for most users. or transfer the file across a network. supports several archiving commands Linux function, but the most prominent ones are tar and zip. The tar program’s name stands for tape archiver. The tar program When to perform this for distributing source code within running the use only one command option. To create is a complex tar command, command the user with must with at least one qualifier or a tar archive, enter the command Even though it was originally designed for backing up “tar -c tarfile.tar file1 txt file2txt”. This command will files to backup tapes, tar can back up or archive data to create the filesystem, a hard drive, or removable media. The tar the two text files: filel.txt and file2.txt. To create Page 86 of 208 « 43% a new tarfile called tarfiletar, which contains a Aa LN LINUX ESSENTIALS (010-160): QO Kindle Library A TIME COMPRESSED RESOURCE TO PASSING THE LPI® LINUX... = Q £— a compressed tar file, enter the command “tar a.gz extension in its filename. To uncompress a.gz file, -czf tarfile.tar.gz file1.txt file2.txt”. This command will simply use gunzip. tarball, perform the same functions as the previous one but will If a file was compressed with bunzip2, it will have also compress the file using gzip to reduce the file size. To a.bz2 extension in its filename. To uncompress learn about all the functions of the tar command, please file, simply use bzip2. If a file was compressed with xz, it will have a.xz consult its man page. Three other a.bz2 common rather programs individual files, than directories like tar creates. can creating These extension in its filename. To uncompress a.xz file, you compress must use unxz. compressed programs Each are gzip, of these three compression formats are bzip2, and xz. They take the original file, compress it, supported within the tar program as well. If you use and create a new file with the same name but add a file compression extension to indicate the type of compression format. own unique extension to the filename to indicate the Unfortunately, most programs cannot read a within the tar program, it will add its compression used. If the tarball was compressed with compressed file, so the file must first be uncompressed gzip, it will add the -tgz to extension to the filename. If using the proper program prior to other programs using the tarball was compressed with bzip2, then.tbz,.tbz2, the file. or.tb2 is used. It the tarball was compressed with xz, If a file was compressed by gunzip, it will have then.txz will be used. Page 87 of 208 « 43% Aa LINUX ESSENTIALS (010-160): A TIME COMPRESSED RESOURCE TO PASSING THE LPI® LINUX... The CHAPTER SEVEN command environment is an Q Ba Qh extremely powerful tool. As previously discussed, wildcards can substitute Searching and Extracting line = Data for a single character, multiple characters from a provided subset, or any character for part of a file name. This same concept can also search for data within a file or files, as well. In this chapter, you will learn how to search for and extract data within various files and commands using redirection and wildcards. But first, it is imperative that you understand how to link multiple commands together using the concepts of command redirect and input/output redirection. Command Redirection OBJECTIVES - Understand how to redirect output using pipes ;. - Be able to redirect operators using grep _. - Be able to search for patterns within data files.. Command redirection allows a user to reroute the. ; standard input to a second program or command. This. ; _o... is performed using a pipeline or command line pipe. A Page 89 of 208 « 44% ©) LINUX ESSENTIALS (010-160): QO Kindle Library A TIME COMPRESSED RESOURCE TO PASSING THE LPI® LINUX... [— commands commands. This key is usually found above the Enter This key on the keyboard and accessed by pressing the Shift complex tasks, resulting in less pauses in execution as key down while pressing the backslash key. well, since the system won't have to wait for the user to Pipelines ways. For command can be useful example, the when lengthy applied in various output of the quick execution consecutively. of commands and input the next command. cat (which displays the contents of a file to the for and run them Q pipe is created by using a vertical bar (|) between the two allows in sequence =: The grep command is commonly used in pipelines to search for keywords within the output of a given screen) can be piped together with the less command command. This command searches for files that contain to show only one page of content at a time. This avoids a specified string and returns the name of the file and, jumping if it is a text file, the line containing that string. The to the last page of the file and not seeing the content in the rest of the file. The more command grep command can also display one page of content at a time when for a specific string. To use grep, a user simply types combined with cat, but it operates a bit differently than the command’s name, grep, an optional set of switches the less command. and parameters, a regular expression, and an optional more commands, To learn more please about cat, less, and consult their dedicated man filename if desired. If you are planning to enter the world of system pages. By using pipes, can also search within a specified file a user can perform two or more administration Page 90 of 208 « 44% or cybersecurity, you will need to get Aa LN LINUX ESSENTIALS (010-160): A TIME COMPRESSED RESOURCE TO PASSING THE LPI® LINUX... comfortable using the grep command. is a security operation for finding information files contained Management center from in a Security This command analyst’s across best Information and Q programs rely on this feature to enable them to process Event data. For instance, raw text files fed through a program search the text for specified patterns. In addition to beyond the scope of this book, but to learn more about redirecting output to files or input from files, a program’s the command please consult its detailed man pages for output can be passed to another program as an input the complete list of options it supports. through the process of piping, as covered earlier in this chapter. Input/Output Redirection into another by using the pipe, a user can also redirect if you need to save a program’s output for that involves the xargs is a related command, which enables a user to generate command line options from files or another programs’ output. A Linux the input/output of a command to other locations. For example, In addition to all of this, there technique In addition to redirecting the output of one command supported system has two by default: type standard of output output and that are standard future reference, you can redirect that output to a file. error. The standard output is used for normal program Similarly, the input to can be redirected messages. For example, when you run the ls command, from a file, instead of requiring the user to enter it by the output is sent to the standard output and, therefore, a command Qh Although input redirection may sound strange, some log server. In-depth usage of the grep tool is Ba using the keyboard. friend different = Page 91 of 208 « 45% Q) LINUX ESSENTIALS (010-160): QO Kindle Library A TIME COMPRESSED displayed on your screen. The standard error, on the RESOURCE TO PASSING THE LPI® LINUX... =: Q output to the end of the current file. By default, this 2> creates a new file that will have the standard error also displays on the screen, but users can redirect these redirected to the file. If the file already exits, its contents messages if desired. will be overwritten. other hand, outputs error messages. 2>> appends the standard error to an existing file. If There are several redirection operators available to more fully control where information is output to, the file doesn’t’ already exist, a new > creates a new file containing the standard output. If added to the end of the file. &> creates a new file that contains both the standard the specified file already exists, it will be overwritten. For example, if the command “ls > contents.txt” is executed, output and standard error output. the exists, its contents will be overwritten. of the ls command will be saved to the contents.txt file and nothing would be displayed to the screen. like the If the file already There are also several redirection operators available to more fully control where information is input from in >> appends the standard output to an existing file. Just one is created. If it does exist, the standard error output will simply be displayed to, and/or saved to. output [— command above, we could redirect the shell. < sends the the contents of the specified file to the output of the ls command to the file contents.txt, but command in place of the standard input. For example, if instead of overwriting the file, we would simply add our I had a text file called input.txt that contained a single Page 91 of 208 « 45% Aa LN LINUX ESSENTIALS (010-160): QO Kindle Library A TIME COMPRESSED RESOURCE TO PASSING THE LPI® LINUX... =: Q [— line of text that said b??1 and entered the command “1s < but if you go on to become a Linux developer then it may input.txt”, the output would be equivalent to entering ls become more useful to you at that time. b??l at the command prompt.

Use Quizgecko on...
Browser
Browser