From owner-freebsd-questions@freebsd.org Sun Feb 23 18:24:26 2020 Return-Path: Delivered-To: freebsd-questions@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C620C24424F for ; Sun, 23 Feb 2020 18:24:26 +0000 (UTC) (envelope-from 4250.10.freebsd-questions=freebsd.org@email-od.com) Received: from s1-b0c6.socketlabs.email-od.com (s1-b0c6.socketlabs.email-od.com [142.0.176.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 48QYWF6NMtz4Km4 for ; Sun, 23 Feb 2020 18:24:25 +0000 (UTC) (envelope-from 4250.10.freebsd-questions=freebsd.org@email-od.com) DKIM-Signature: v=1; a=rsa-sha256; d=email-od.com;i=@email-od.com;s=dkim; c=relaxed/relaxed; q=dns/txt; t=1582482266; x=1585074266; h=content-transfer-encoding:content-type:mime-version:references:in-reply-to:message-id:subject:cc:to:from:date:x-thread-info; bh=gvKxF6EHrvYLjRUw497cGjs3nq2wfBiU32Y4Prdhock=; b=sCjWiOJc2qvEsf0tWPfyqoRrIb3cB6958Kf0sE44sueO3mMDALkykmdfavrD9fKW5JWRTQnHdGOnYNsKpDrbiSR87oquxPJXbTS3rgQB/0qjnVpUHr2DVcjW3b7Z0LXqwsAAovBNHna4trv2FwWl9cyrB9A/C5Yaiwd5K5g8KF8= X-Thread-Info: NDI1MC4xMi43NDAwMDAwMTIwZTNlOS5mcmVlYnNkLXF1ZXN0aW9ucz1mcmVlYnNkLm9yZw== Received: from r1.us-east-2.aws.in.socketlabs.com (r1.us-east-2.aws.in.socketlabs.com [142.0.189.1]) by mxsg2.email-od.com with ESMTP(version=Tls12 cipher=Aes256 bits=256); Sun, 23 Feb 2020 13:24:14 -0500 Received: from smtp.lan.sohara.org (EMTPY [185.202.17.215]) by r1.us-east-2.aws.in.socketlabs.com with ESMTP(version=Tls12 cipher=Aes256 bits=256); Sun, 23 Feb 2020 13:24:13 -0500 Received: from [192.168.63.1] (helo=steve.lan.sohara.org) by smtp.lan.sohara.org with smtp (Exim 4.92.3 (FreeBSD)) (envelope-from ) id 1j5vvH-000DEt-Q2; Sun, 23 Feb 2020 18:24:11 +0000 Date: Sun, 23 Feb 2020 18:24:11 +0000 From: Steve O'Hara-Smith To: freebsd-questions@freebsd.org Cc: Polytropon Subject: Re: rm | Cleaning up recycle bin Message-Id: <20200223182411.81a22ce74509b8778a39d8d3@sohara.org> In-Reply-To: <20200223184908.b35d656a.freebsd@edvax.de> References: <20200223184908.b35d656a.freebsd@edvax.de> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; amd64-portbld-freebsd12.0) X-Clacks-Overhead: "GNU Terry Pratchett" Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 48QYWF6NMtz4Km4 X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=pass header.d=email-od.com header.s=dkim header.b=sCjWiOJc; dmarc=none; spf=pass (mx1.freebsd.org: domain of 4250.10.freebsd-questions=freebsd.org@email-od.com designates 142.0.176.198 as permitted sender) smtp.mailfrom=4250.10.freebsd-questions=freebsd.org@email-od.com X-Spamd-Result: default: False [-1.89 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-0.98)[-0.984,0]; R_DKIM_ALLOW(-0.20)[email-od.com:s=dkim]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:142.0.176.0/20]; MV_CASE(0.50)[]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[sohara.org]; FORGED_SENDER_VERP_SRS(0.00)[]; NEURAL_HAM_LONG(-1.00)[-0.999,0]; RCVD_COUNT_THREE(0.00)[4]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[email-od.com:+]; RCPT_COUNT_TWO(0.00)[2]; RCVD_IN_DNSWL_NONE(0.00)[198.176.0.142.list.dnswl.org : 127.0.15.0]; ENVFROM_VERP(0.00)[]; IP_SCORE(0.09)[ip: (-0.25), ipnet: 142.0.176.0/22(0.52), asn: 7381(0.26), country: US(-0.05)]; FORGED_SENDER(0.00)[steve@sohara.org,4250.10.freebsd-questions=freebsd.org@email-od.com]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:7381, ipnet:142.0.176.0/22, country:US]; FROM_NEQ_ENVFROM(0.00)[steve@sohara.org,4250.10.freebsd-questions=freebsd.org@email-od.com]; MID_RHS_MATCH_FROM(0.00)[] X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Feb 2020 18:24:26 -0000 On Sun, 23 Feb 2020 18:49:08 +0100 Polytropon wrote: > So if you use rm, and no process holds the file open, the disk > space occupied by the file will be freed immediately; if some > process still uses the file, its name will be removed (so you > cannot address it by that name anymore), but the disk space > will be freed when the process closes the file. Somebody needs to mention hard links here - so I'll chime in with the complicated version. The directory entry for a file is just a name pointing to the actual file defined by an inode (the data structure that holds everything there is about the file except the name). There can be many directory entries pointing to the same file (known as hard links) each one counts as a reference to the file as does every file handle held open by one or more processes. The inode and the data hanging off it becomes free and available for reuse as soon as there are no references (directory entries or open file handles) to it. Multiple entries for the same file are quite common for binaries, for example /bin/csh and /bin/tcsh are links to the same file, or for that matter nearly everything in /rescue is a link to the same file. When there are multiple links to a file none of them are special, they're all just links. The rm command, and the underlying unlink system call simply remove directory entries which reduces the reference count in the inode which is the actual file. When that count hits zero the file is freed - ie. the blocks in it and the inode are made available for use. How long it takes for freed space to get reused depends on a lot of things, not least being the amount of free space available but from the moment the last reference is gone it takes forensic effort to recover a file. -- Steve O'Hara-Smith