Character & Block Devices, bzip2, Inodes, Links, Find & Mount

Classified in Technology

Written at on English with a size of 3.74 KB.

Character Devices and Block Devices

Character devices read and write data as a byte stream. Examples of character devices are printers and keyboards that allow the handling of a single byte at a time.

Block devices read and write information in fragments ("blocks") to the block device at a time. Examples include hard drives, floppy disks, and CD/ROM drives.

Locate Command

The locate command writes the names of files and directories that match a given pattern. It is the fastest of the two commands because it depends on a database (updated daily by default) instead of looking in real-time. It finds files that have been deleted since the last update of the database.

bzip2 Command

The bzip2 command tends to generate more compact compressed files but is more CPU-intensive. Files compressed with bzip2 are uncompressed with bunzip2. The bzip2 command supports the following options:

  • -c: Redirect the output to stdout.
  • -d: Decompress instead of compressing the file.

INodes

An INode is a data structure that stores information about each file, including:

  • Pointer to the physical file
  • Filename
  • Owner and group IDs
  • Permissions
  • Size
  • Date of last access
  • Number of links to the file

stat shows the information on the INode.

bzip2 Compression

-9: Set the compression ratio. The higher the number, the better the compression.

bzip2 -9 *.txt (Compress all files ending with .txt in the current directory using the bzip2 command)

Compressing with bzip2

The bzip2 command only serves to compress. To decompress, the bunzip2 command is used.

Examples:

  • bzip2 document_to_compress
  • bzip2 -d document_to_decompress.bz2
  • bunzip2 document_to_decompress.bz2

Hard Links and Soft Links

Hard Links

  • Create a new pointer to a file.
  • All the attributes of links are equal.
  • If we delete a link, the file remains.
  • ls -l to see the number of links.

Soft Links

  • Simply point to an existing file.
  • Allow:
    • Linking directories.
    • Linking non-existing files.
    • Linking to other file systems.
  • If the original file is deleted, the link will not work because it points to nothing.

Find Command

Search with the find command for all the proxy files and back them up (practice):

This generates a detailed list of each file with HTML. One plus is:

# find . -name '*.html' -exec cat {} >> backups;

This makes a copy of all files it finds in a folder called "backups".

Mount a Windows Partition

  • First, open a console as root (if you use Ubuntu, prepend sudo to all commands).
  • Now create the directory where we will mount the Windows partition:

    mkdir /mnt/windows

  • To mount Windows, you should know which partition it is in, so we do:

    fdisk -l | grep NTFS

  • We know that this partition is (/dev/hdaX). Now:

    mount -t ntfs /dev/hdaX /mnt/windows

  • Replace X with the number of the Windows partition (The result gave us fdisk -l | grep NTFS).
  • We can see Windows files in /mnt/windows. To avoid having to always do this process, we write in the /etc/fstab:

    nano /etc/fstab

  • And add the following line:

Entradas relacionadas: