• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to truncate /var/log/lastlog File

by admin

/var/log/lastlog is a binary file that holds information about the last time that users logged in to the system. The lastlog file is a sparse file, which means that the apparent size reported by “ls -l” is larger than the actual disk usage of the file(du), because not all blocks in the file are allocated on disk.

Sparse file is a type of computer file that attempts to use file system space more efficiently when blocks allocated to the file are mostly empty. This is achieved by writing brief information (metadata) representing the empty blocks to disk instead of the actual “empty” space which makes up the block, using less disk space (i.e. sparse files contain blocks of zeros whose existence is recorded, but have no space allocated on disk). The full block size is written to disk as the actual size only when the block contains “real” (non-empty) data.

When reading sparse files, the file system transparently converts metadata representing empty blocks into “real” blocks filled with zero bytes at run-time. The application is unaware of this conversion. Sparse files are commonly used for disk images, database snapshots, log files, etc.

The lastlog file contains information about the last time a user has logged into the system. If you wish to retain this information, then use the lastlog command to export the log information before recreating the /var/log/lastlog file or copy the existing /var/log/lastlog file to alternate location.

1. Take backup of existing lastlog content.

# lastlog > /tmp/lastlog.txt

OR

# cp /var/log/lastlog /opt/lastlog.bkp

2. Now overwrite file using any one of the following command:

# >/var/log/lastlog

OR

# cat > /var/log/lastlog

Filed Under: Linux

Some more articles you might also be interested in …

  1. How to Configure GNOME Console Login Banner in CentOS/RHEL 7 and 8
  2. “docker build” Command Examples
  3. git config Command Examples
  4. box: A PHP application for building and managing Phars
  5. rofi Command Examples in Linux
  6. How to Configure a Fiber-Channel Over Ethernet (FCoE) Interface in CentOS/RHEL
  7. bzfgrep: Find any fixed strings separated by new lines in bzip2 compressed files using fgrep
  8. All Linux Compress/Decompress Commands
  9. “aws s3 mb” Command Examples
  10. gh api: Makes authenticated HTTP requests to the GitHub API and prints the response

You May Also Like

Primary Sidebar

Recent Posts

  • gixy Command Examples
  • gitsome Command Examples
  • gitmoji Command Examples
  • gitlint Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright