Posts

Filtering Input

Grep ( The Weapon) The  grep  command is a text filter that will search input and return lines, which contain a match to a given pattern. grep [ OPTIONS ] PATTERN [ FILE ] Follow Along Use the following command to switch to the  Documents  directory: sysadmin@localhost : ~ $ cd ~/Documents If the example below fails, repeat the example from Section 11: sysadmin@localhost : ~/Documents $ cp /etc/passwd . For example, the  passwd  file we previously copied into the  Documents  directory contains the details of special system accounts and user accounts on the system. This file can be very large, however the  grep command can be used filter out information about a specific user, like the  sysadmin  user. Use  sysadmin  as the pattern argument and  passwd  as the file argument: sysadmin@localhost : ~/Documents $ grep sysadmin passwd sysadmin :x:1001:1001:System Admi...

Removing Files

The  rm  command is used to delete files and directories. It is important to keep in mind that deleted files and directories do not go into a "trash can" as with desktop oriented operating systems. When a file is deleted with the  rm  command, it is almost always permanently gone. rm [ OPTIONS ] FILE Follow Along Use the following command to switch to the  Documents  directory: sysadmin@localhost : ~ $ cd ~/Documents Without any options, the  rm  command is typically used to remove regular files: sysadmin@localhost : ~/Documents $ rm linux.txt sysadmin@localhost : ~/Documents $ ls linux.txt ls: cannot access linux.txt: No such file or directory The  rm  command will ignore directories that it's asked to remove; to delete a directory, use the recursive option, either the  -r  or  -R  options. Just be careful since this will delete all files and all subdirectories: sysadmin@localhost : ~/Documents $...

Copying Files ( Part 2 )

The  dd  command is a utility for copying files or entire partitions at the bit level. dd [ OPTIONS ] OPERAND This command has several useful features, including: It can be used to clone or delete (wipe) entire disks or partitions. It can be used to copy raw data to removable devices, such as USB drives and CDROMs. It can backup and restore the MBR (Master Boot Record). It can be used to create a file of a specific size that is filled with binary zeros, which can then be used as a swap file (virtual memory). Let's examine the following example, the  dd  command creates a file named  /tmp/swapex  with 50 blocks of zeros that are one megabyte in size: sysadmin@localhost : ~ $ dd if=/dev/zero of=/tmp/swapex bs=1M count=50 50+0 records in 50+0 records out 52428800 bytes (52 MB) copied, 0.825745 s, 635 MB/s The  dd  command uses special arguments to specify how it will work. The following illustrates some of the more commonly used arg...

Copying Files ( Part 1 )

Creating copies of files can be useful for numerous reasons: If a copy of a file is created before changes are made, then it is possible to revert back to the original. It can be used to transfer a file to removable media devices. A copy of an existing document can be used as a template for a new document. cp [ OPTIONS ] SOURCE DESTINATION Follow Along Use the following command to switch to the  Documents  directory: sysadmin@localhost : ~ $ cd ~/Documents ​⁠​‌‌⁠⁠⁠⁠​ The  cp  command is used to copy files. Similar to the  mv  command it requires at least two arguments: a source and a destination. For example, to copy the  /etc/passwd  file to the current directory, use the following command: sysadmin@localhost : ~/Documents $ cp /etc/passwd . Note The second argument is the  .  character. Recall from the Changing Directories section that is a shortcut which represents the...