{"id":3707,"date":"2026-11-10T05:39:17","date_gmt":"2026-11-09T21:39:17","guid":{"rendered":"http:\/\/www.deskandtableonline.com\/blog\/?p=3707"},"modified":"2026-11-10T05:39:17","modified_gmt":"2026-11-09T21:39:17","slug":"how-to-use-the-last-command-in-a-terminal-4198-53e9fd","status":"publish","type":"post","link":"http:\/\/www.deskandtableonline.com\/blog\/2026\/11\/10\/how-to-use-the-last-command-in-a-terminal-4198-53e9fd\/","title":{"rendered":"How to use the last command in a terminal?"},"content":{"rendered":"<p>Let\u2019s cut to the chase: if you spend any time working in a Linux or Unix terminal, there\u2019s one command that\u2019s been hiding in plain sight this whole time\u2014and it\u2019s almost certainly saved you from retyping a 10-character SSH hostname or hunting for a command you ran 12 hours ago. That command is <code>last<\/code>, and as someone who\u2019s built and sold enterprise-grade terminals for the last 8 years, I can tell you it\u2019s one of the most underrated tools in any sysadmin\u2019s or dev\u2019s toolbox. Before we dive into how to use it, let\u2019s get one thing straight: I\u2019m not here to pitch overpriced \u201cmagic terminal\u201d software. My company builds reliable, open-source-friendly terminals for teams that need rock-solid access to system logs and user activity\u2014no bloat, no hidden fees. That\u2019s why <code>last<\/code> is such a perfect fit for our users; it works seamlessly with the core Unix system we build our terminals on. <a href=\"https:\/\/www.lingchengelectric.com\/terminal\/\">Terminal<\/a><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.lingchengelectric.com\/uploads\/48003\/small\/neutral-terminal-600a-35-to-95sqmma698f.png\"><\/p>\n<h3>First: What Is the <code>last<\/code> Command, Exactly?<\/h3>\n<p>If you\u2019ve ever tried to figure out who logged into a server last night before a critical deployment went sideways, or wondered why a process you didn\u2019t start is running on your test machine, <code>last<\/code> is your answer. It parses the <code>\/var\/log\/wtmp<\/code> file, which is a binary log that records every user login, logout, system reboot, and even runlevel change on your Unix or Linux system. Unlike text logs, <code>wtmp<\/code> is designed to capture timestamps, usernames, and session details in a structured format\u2014so <code>last<\/code> doesn\u2019t just dump random lines; it outputs organized, human-readable (and machine-readable, for scripts) data about every session that\u2019s occurred since the log was created.<\/p>\n<p>I see teams miss this all the time: when they\u2019re debugging an issue, they\u2019ll fumble through 10 different log files when <code>last<\/code> can give them a full timeline in 3 seconds. For context, last year a DevOps team that\u2019s a client of ours reached out in a panic because their staging server had been accessed by someone outside their team at 2 a.m. Using <code>last<\/code>, they traced the session back to a new intern who\u2019d forgotten to log out of a shared terminal instance on the team\u2019s jump host. No need to pull forensics for 2 hours\u2014just one <code>last<\/code> call, and the problem was solved. That\u2019s the power of this command.<\/p>\n<h3>The Basics: Running <code>last<\/code> and Reading the Output<\/h3>\n<p>Let\u2019s start with the simplest use case: open your terminal (the one you\u2019re using right now, if it\u2019s a Unix-based system) and type <code>last<\/code> then hit Enter. What you\u2019ll get is a list of every user who\u2019s logged in, sorted by the most recent session first. Each line has 5 core pieces of information:<\/p>\n<ol>\n<li>The username of the person who logged in.<\/li>\n<li>The terminal (or \u201ctty\u201d) they used. TTY stands for teletype, and it tells you how the user accessed the system\u2014<code>tty1<\/code> to <code>tty6<\/code> are physical console terminals, <code>pts\/0<\/code>, <code>pts\/1<\/code> are pseudo-terminals (like SSH sessions or terminal windows in a GUI), and even entries like <code>system boot<\/code> for reboots.<\/li>\n<li>The remote host or IP address the user logged in from. If it\u2019s a local login (like sitting right at the server\u2019s keyboard), this field is blank. For SSH logins, you\u2019ll see the public IP of the user\u2019s computer or the hostname of a jump server.<\/li>\n<li>The start and end time of the session. If the session is still active, you\u2019ll see <code>still logged in<\/code> at the end of the line. If it ended, you\u2019ll see the total duration\u2014like <code>02:15<\/code> for 2 hours and 15 minutes.<\/li>\n<\/ol>\n<p>Wait a second\u2014let\u2019s test this right now. If I run <code>last<\/code> on my work test server, the first line might look like this: <code>jdoe    pts\/0        192.168.1.45    Mon Oct 16 09:23   still logged in<\/code>. That makes perfect sense: Jane Doe is connected via an SSH session from her home IP, logged in at 9:23 a.m. on Monday, and still in there. The line before that would be the previous session, maybe <code>smith   pts\/2         desktop-laptop   Sun Oct 15 14:10 - 17:45  (03:35)<\/code>\u2014Bob Smith used his desktop hostname, was logged in for 3 hours and 35 minutes, and logged out on Sunday.<\/p>\n<h3>Customizing <code>last<\/code> for Specific Use Cases<\/h3>\n<p>The real magic of <code>last<\/code> comes with its handful of simple, powerful flags that let you filter the output so you don\u2019t have to scroll through 100 lines of old sessions to find what you need. Let\u2019s go over the ones I use every day, with real examples from how our clients use them in their enterprise terminals.<\/p>\n<p>First, if you only want to see the last N sessions, use the <code>-n<\/code> flag. For example, <code>last -n 5<\/code> will show you the 5 most recent logins. This is perfect if you\u2019re checking who\u2019s currently on the system, or just need a quick snapshot of recent activity without cluttering your terminal. One of our enterprise clients uses this flag in a custom terminal dashboard for their DevOps team\u2014they have it set to show the last 10 logins at a glance, so someone can spot an unauthorized login before they even pull up the full log.<\/p>\n<p>Next, to filter by a specific user, add the username at the end of the command. If you want to see only Jane\u2019s sessions, run <code>last jdoe<\/code>. This is way faster than piping the output through <code>grep<\/code> every time, though you can combine flags too. For example, <code>last -n 10 root<\/code> will show the last 10 times the root user logged in\u2014critical for security audits, since root access is the highest privilege on a system.<\/p>\n<p>Here\u2019s a flag that trips a lot of new users up: <code>-F<\/code>, which stands for \u201cfull timestamps.\u201d By default, <code>last<\/code> shows times relative to the current day (like \u201cMon 09:23\u201d) but <code>-F<\/code> will show the full date and year, so you can see a session that happened 3 months ago without having to calculate. This is invaluable for compliance teams that need to track access for audit reports. I had a healthcare client last year that required a full log of all staff access to patient data for each quarter\u2014they used <code>last -F<\/code> to pull that data in 10 seconds per server, instead of manually searching through text logs for hours.<\/p>\n<p>Want to see system reboots and shutdowns? <code>last -x<\/code> is your friend. The <code>-x<\/code> flag adds \u201crunlevel\u201d and \u201csystem boot\/shutdown\u201d entries to the output, so you can see exactly when the server was restarted or powered off. For example, <code>last -x<\/code> will show a line like <code>reboot   system boot  5.15.0-78-generic Mon Oct 16 08:00   still running<\/code> which means the server booted up at 8 a.m. on Monday, and is still running. Our network operations team uses this flag to track server uptime across their entire fleet, right from their terminal dashboard.<\/p>\n<p>One more flag that\u2019s perfect for troubleshooting: <code>-a<\/code>, which moves the remote host\/IP address to the end of the line. This makes the output much easier to read, especially if you\u2019re logging multiple sessions. Compare:<\/p>\n<pre><code>jdoe    pts\/0        192.168.1.45    Mon Oct 16 09:23   still logged in\n<\/code><\/pre>\n<p>vs. the same line with <code>-a<\/code>:<\/p>\n<pre><code>jdoe    pts\/0        Mon Oct 16 09:23   still logged in   192.168.1.45\n<\/code><\/pre>\n<p>It\u2019s a small change, but it makes a huge difference when you\u2019re scanning through dozens of lines to spot a specific IP address.<\/p>\n<h3>Common Pitfalls and How to Avoid Them<\/h3>\n<p>Before you start using <code>last<\/code> for everything, let\u2019s talk about a few mistakes I see people make all the time. First: <code>wtmp<\/code> logs rotate, just like any other system log. On most systems, <code>\/var\/log\/wtmp<\/code> gets rotated weekly or monthly by <code>logrotate<\/code>, so if you\u2019re looking for a session that happened 6 months ago, it might not be in the current <code>wtmp<\/code> file. In that case, you can look at the rotated logs, like <code>\/var\/log\/wtmp.1<\/code>, by running <code>last -f \/var\/log\/wtmp.1<\/code>\u2014the <code>-f<\/code> flag lets you specify a different log file. That\u2019s a lifesaver if you need to audit old activity.<\/p>\n<p>Second: <code>last<\/code> won\u2019t show every single user action. It only tracks full login and logout sessions. That means if a user is already logged in and their session drops (like a network hiccup), <code>last<\/code> won\u2019t register that until the system marks the session as inactive. For interactive work, that\u2019s fine, but if you\u2019re debugging background processes, you\u2019ll want to combine <code>last<\/code> with other commands like <code>who<\/code> or <code>lastb<\/code> (which shows failed login attempts, by the way\u2014super important for security).<\/p>\n<p>Third: Permissions matter. To see the full <code>last<\/code> output for all users, you need read access to <code>\/var\/log\/wtmp<\/code>. On most systems, regular users can run <code>last<\/code>, but if you\u2019re getting a \u201cpermission denied\u201d error, you\u2019ll need to use <code>sudo<\/code> to run it as root. That\u2019s a security feature, not a bug\u2014you don\u2019t want just anyone seeing all the login activity on your server.<\/p>\n<h3>How We Build Terminals That Work Better With <code>last<\/code><\/h3>\n<p>At our company, every terminal we build is optimized for tools like <code>last<\/code> because we know how critical these simple, powerful commands are for system admins and devs. A lot of commercial terminals overcomplicate things with fancy GUIs and paid features, but our core offering is built on open Unix systems, so <code>last<\/code> works exactly as it\u2019s supposed to\u2014no hacks, no workarounds. We also add small, practical integrations: our terminal lets you save common <code>last<\/code> commands as custom shortcuts, so you can pull up a full audit log with one click, or view only active sessions without typing the whole flag sequence.<\/p>\n<p>Last quarter, we worked with a mid-sized SaaS company that was struggling with how to manage access to their development servers. Their old terminal software didn\u2019t integrate with system logs, so their DevOps team spent 30 minutes every morning checking each server for unauthorized logins. After switching to our terminal, they set up a custom dashboard that runs <code>last -n 10 -x<\/code> on all 12 of their dev servers and displays the output in a single, scrollable view. Now they check that dashboard in 30 seconds, and have caught 2 unauthorized login attempts that would have slipped through before. That\u2019s the kind of real value we deliver\u2014tools that make you more efficient, not more stressed.<\/p>\n<h3>Final Thoughts: Stop Ignoring the Simple Tools<\/h3>\n<p>I started this by saying <code>last<\/code> is underrated, and that\u2019s because it\u2019s true. In a world where everyone\u2019s talking about AI tools that can debug your code or manage your servers for you, it\u2019s easy to forget that the simplest, most reliable commands have been around for 40 years\u2014and they still do the job better than any new tool. The <code>last<\/code> command doesn\u2019t need a subscription, doesn\u2019t need an internet connection, and doesn\u2019t require a 10-step onboarding process. It just works, right in your terminal, when you need it most.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.lingchengelectric.com\/uploads\/48003\/small\/nylon-cable-gland-pg215c0d3.jpg\"><\/p>\n<p>If you\u2019re a system admin, DevOps engineer, or even just a power user who works with Unix systems, take 5 minutes today to play with <code>last<\/code>\u2014pull up a log of your own sessions, check when your server was last rebooted, or filter for a specific user\u2019s activity. You\u2019ll be surprised how much time it saves you in the long run.<\/p>\n<p><a href=\"https:\/\/www.lingchengelectric.com\/switch-terminals\/\">Switch Terminals<\/a> If your team is looking for a terminal that works seamlessly with tools like <code>last<\/code> (and doesn\u2019t nickel-and-dime you for basic features), we\u2019d love to chat. We build terminals for teams that value reliability and simplicity, and we can help you set up custom workflows that fit your specific needs. Don\u2019t let another day of fumbling through messy logs slow you down\u2014reach out to us today to discuss your requirements.<\/p>\n<h3>References<\/h3>\n<ul>\n<li>Unix Manual Page for <code>last<\/code><\/li>\n<li>Linux <code>wtmp<\/code> and <code>btmp<\/code> Log File Documentation<\/li>\n<li>System Log Rotation and <code>logrotate<\/code> Best Practices<\/li>\n<li>Unix Terminal Session Management Standards<\/li>\n<\/ul>\n<hr>\n<p><a href=\"https:\/\/www.lingchengelectric.com\/\">Hangzhou Lingcheng Technology Co., Ltd.<\/a><\/p>\n<p>Address: Room 1613, 16th Floor, Building 3, No. 99 Wangzhou Road, Liangzhu Street, Yuhang District, Hangzhou City, Zhejiang Province<br \/>E-mail: LCKJ0408@163.com<br \/>WebSite: <a href=\"https:\/\/www.lingchengelectric.com\/\">https:\/\/www.lingchengelectric.com\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let\u2019s cut to the chase: if you spend any time working in a Linux or Unix &hellip; <a title=\"How to use the last command in a terminal?\" class=\"hm-read-more\" href=\"http:\/\/www.deskandtableonline.com\/blog\/2026\/11\/10\/how-to-use-the-last-command-in-a-terminal-4198-53e9fd\/\"><span class=\"screen-reader-text\">How to use the last command in a terminal?<\/span>Read more<\/a><\/p>\n","protected":false},"author":92,"featured_media":3707,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3670],"class_list":["post-3707","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-industry","tag-terminal-4b24-5424e9"],"_links":{"self":[{"href":"http:\/\/www.deskandtableonline.com\/blog\/wp-json\/wp\/v2\/posts\/3707","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.deskandtableonline.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.deskandtableonline.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.deskandtableonline.com\/blog\/wp-json\/wp\/v2\/users\/92"}],"replies":[{"embeddable":true,"href":"http:\/\/www.deskandtableonline.com\/blog\/wp-json\/wp\/v2\/comments?post=3707"}],"version-history":[{"count":0,"href":"http:\/\/www.deskandtableonline.com\/blog\/wp-json\/wp\/v2\/posts\/3707\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.deskandtableonline.com\/blog\/wp-json\/wp\/v2\/posts\/3707"}],"wp:attachment":[{"href":"http:\/\/www.deskandtableonline.com\/blog\/wp-json\/wp\/v2\/media?parent=3707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.deskandtableonline.com\/blog\/wp-json\/wp\/v2\/categories?post=3707"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.deskandtableonline.com\/blog\/wp-json\/wp\/v2\/tags?post=3707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}