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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • 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. lvextend: command not found
  2. more: command not found
  3. RedHat / CentOS : Managing software RAID with mdadm
  4. dmenu Command Examples in Linux
  5. Shell Script to print pyramid of Stars
  6. CentOS / RHEL : How to set chroot jail for vsftp for all the users
  7. check-language-support: command not found
  8. How to uninstall chromium-chromedriver from Ubuntu
  9. 12 RPM (Red Hat Package Manager) Command Examples
  10. How to disable or enable an HBA without reboot under CentOS/RHEL

You May Also Like

Primary Sidebar

Recent Posts

  • qm Command Examples in Linux
  • qm wait Command Examples in Linux
  • qm start Command Examples in Linux
  • qm snapshot Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright