Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

0 votes
1 answers
43 views
Alias for rm does not include file name with @$
I am trying to create an alias for the rm command in the /root/.bashrc file on a VirtualBox Redhat VM (running RHEL 9). I cannot get it to work properly. This is an excerpt of my .bashrc file: ``` alias rm='printf "rm: cannot remove %s: Permission denied\n" "$@" && w >> /tmp/logfile_20090204_001.log...
I am trying to create an alias for the rm command in the /root/.bashrc file on a VirtualBox Redhat VM (running RHEL 9). I cannot get it to work properly. This is an excerpt of my .bashrc file:
alias rm='printf "rm: cannot remove %s: Permission denied\n" "$@" &&  w >> /tmp/logfile_20090204_001.log'
sudo() {
	if [[ "$1" == "rm" ]]; then
		for file in "${@:2}"; do
			printf "rm: cannot remove %s: Permission denied\n" "$file"
		done
		w >> /tmp/logfile_20190204_002.log
	else
		command sudo "$@"
	fi
}
I reload it with . /root/.bashrc. The result I get when using rm is
: cannot remove : Permission denied
(no file name). I have tried replacing printf with echo, switching the single and double quotes and modifying the bash_aliases file instead of the .bashrc file, and nothing seems to work. How can I get this alias to print my file name (with and without sudo)? Thank you in advance for your help!
minionsaregreat (3 rep)
Jul 10, 2025, 12:42 PM • Last activity: Jul 10, 2025, 01:02 PM
1 votes
1 answers
2086 views
Using rm --one-file-system to only delete files on the local filesystem
I have a FUSE mount located in `/media/writable`, however, sometimes this FUSE mount disconnects, but some programs will still attempt to write to `/media/writable`. When I restart the FUSE mount service, it will fail to mount because the directory is non-empty. How can I use `rm`'s `--one-file-syst...
I have a FUSE mount located in /media/writable, however, sometimes this FUSE mount disconnects, but some programs will still attempt to write to /media/writable. When I restart the FUSE mount service, it will fail to mount because the directory is non-empty. How can I use rm's --one-file-system argument to ensure that when I rm /media/writable, it will only delete files located on the **local** filesystem, as opposed to the **fuse mounted** filesystem? There are other folders located in /media/ so I am unable to run rm in the parent folder. Am I better off moving the folder one layer down (eg. /media/writable/mount) so I can rm the parent folder, or is there a way of selecting which filesystem I wish to delete from? I'm running Ubuntu 18.04.1 LTS with coreutils 8.28. Edit: My current method is this, but I'd like to see if there's a better way to do it: ExecStartPre=-/bin/mountpoint /media/writable/ || /usr/bin/stat /media/writable/MOUNTED || /bin/rm/ --one-file-system -rf /media/writable/*
Connor Bell (23 rep)
Mar 9, 2019, 01:27 PM • Last activity: Jun 16, 2025, 06:02 PM
2 votes
2 answers
243 views
How to remove similar folder from multiple locations in terminal
I have a folder 'reg_standard' nested within 68 different folders that I want to remove. The path to this folder looks something like: /Volumes/.../sub-???/run_?.feat/reg_standard where `'?'` is a stand-in for all the different folders that start with 'sub' or 'run'. For example, I have sub-101, sub...
I have a folder 'reg_standard' nested within 68 different folders that I want to remove. The path to this folder looks something like: /Volumes/.../sub-???/run_?.feat/reg_standard where '?' is a stand-in for all the different folders that start with 'sub' or 'run'. For example, I have sub-101, sub-102, sub-162 (34 in total) and run_1 and run_2 folders nested within each sub-???, making a total of 68 folders in total where reg_standard exists. How can I remove this folder and all its contents efficiently? Do I use rm -r? or find ... - delete? I use MacOS. Thank you!
user556056 (23 rep)
Jan 9, 2023, 06:53 PM • Last activity: May 17, 2025, 09:07 AM
-3 votes
2 answers
125 views
"rm -f" e-mails me an error, how do I prevent that?
I have cron "clean up" some stuff overnight. A simple `rm -f thisandthat`. But if there is no file `thisandthat`, `rm -f` sends an e-mail to me at me@mycomputer.lan - `No such file or directory`. I thought the `-f` prevented such error reporting. How do I kill off that error reporting? (I'm using Ma...
I have cron "clean up" some stuff overnight. A simple rm -f thisandthat. But if there is no file thisandthat, rm -f sends an e-mail to me at me@mycomputer.lan - No such file or directory. I thought the -f prevented such error reporting. How do I kill off that error reporting? (I'm using Mac Sequoia.)
user637 (1 rep)
Apr 12, 2025, 08:33 PM • Last activity: Apr 13, 2025, 07:45 AM
0 votes
0 answers
1079 views
can't delete folders on samba share
I am dealing with a really weird issue I can't identify the cause of. I have a samba share mounted using autofs in Rocky 9.2 with the flags `-fstype=cifs,rw,nounix,file_mode=0700,dir_mode=0700,multiuser,sec=krb5,user=username,cruid=username,gid=primarygroup,_netdev`. It mounts fine and I can add and...
I am dealing with a really weird issue I can't identify the cause of. I have a samba share mounted using autofs in Rocky 9.2 with the flags -fstype=cifs,rw,nounix,file_mode=0700,dir_mode=0700,multiuser,sec=krb5,user=username,cruid=username,gid=primarygroup,_netdev. It mounts fine and I can add and delete files fine but folders are behaving very weirdly when I try to delete things. For example the following:
$ mkdir dir
$ mkdir dir/{a,b}
$ touch dir/{a,b}/f{1..5}
$ tree dir
dir
├── a
│   ├── f1
│   ├── f2
│   ├── f3
│   ├── f4
│   └── f5
└── b
    ├── f1
    ├── f2
    ├── f3
    ├── f4
    └── f5

2 directories, 10 files
$ rm --recursive --force --verbose dir
removed 'dir/b/f2'
removed 'dir/b/f4'
removed 'dir/b/f5'
removed 'dir/b/f1'
removed 'dir/b/f3'
removed directory 'dir/b'
removed 'dir/a/f2'
removed 'dir/a/f4'
removed 'dir/a/f5'
removed 'dir/a/f1'
removed 'dir/a/f3'
removed directory 'dir/a'
rm: cannot remove 'dir': Directory not empty
$ tree dir
dir
├── a
└── b

2 directories, 0 files
$ rm --recursive --force --verbose dir
rm: cannot remove 'dir': Directory not empty
$ ls --all --recursive dir # in the output note the lack of . and .. in dir/a and dir/b
dir:
.  ..  a  b

dir/a:

dir/b:
$ rmdir dir/a
rmdir: failed to remove 'dir/a': No such file or directory
$ rmdir dir/b
rmdir: failed to remove 'dir/b': No such file or directory
$ tree dir
dir
├── a
└── b

2 directories, 0 files
$ ls --all --recursive -l dir
dir:
total 0
drwx------. 2 username primarygroup 0 Jun  9 16:23 .
drwx------. 2 username primarygroup 0 Jun  9 16:23 ..
drwx------. 2 username primarygroup 0 Jun  9 16:23 a
drwx------. 2 username primarygroup 0 Jun  9 16:23 b

dir/a:
total 0

dir/b:
total 0
I've tried doing it as root, making the permissions 0777 for both files and directories, and mounting it manually rather than with autofs and I get the same behaviour. No relevant messages seem to be turning up in the logs (not discounting I may not be looking at the right log). Update 1: Switching off SELinux didn't help. Nor did turning off the firewall. Update 2: It seems like restarting autofs will clear them (usually requires a restart). But it won't consistently remove all of them. After 2 restarts and with no extra calls to rm or rmdir the folders had completely disappeared. But I can still recreate the problem. So I guess the SMB server must have the correct information but it's not being represented locally maybe...? Update 3: I turned on logging for cifs. I did this with echo 7 | sudo tee /proc/fs/cifs/cifsFYI. Then when I go through a simpler version of the steps again:
$ mkdir --parent h/a
at the same time in logs we get:
Jun 12 16:04:56 localhost kernel: CIFS: Status code returned 0xc0000034 STATUS_OBJECT_NAME_NOT_FOUND
$ rm --recursive h
Jun 12 16:05:12 localhost kernel: CIFS: Status code returned 0xc0000034 STATUS_OBJECT_NAME_NOT_FOUND
Jun 12 16:05:12 localhost kernel: CIFS: Status code returned 0xc0000034 STATUS_OBJECT_NAME_NOT_FOUND
Jun 12 16:05:12 localhost kernel: CIFS: Status code returned 0xc0000034 STATUS_OBJECT_NAME_NOT_FOUND
Jun 12 16:05:12 localhost kernel: CIFS: Status code returned 0xc0000034 STATUS_OBJECT_NAME_NOT_FOUND
Jun 12 16:05:12 localhost kernel: CIFS: Status code returned 0xc0000034 STATUS_OBJECT_NAME_NOT_FOUND
Jun 12 16:05:12 localhost kernel: CIFS: Status code returned 0x80000006 STATUS_NO_MORE_FILES
Jun 12 16:05:12 localhost kernel: CIFS: Status code returned 0xc0000034 STATUS_OBJECT_NAME_NOT_FOUND
Jun 12 16:05:12 localhost kernel: CIFS: Status code returned 0xc0000034 STATUS_OBJECT_NAME_NOT_FOUND
Jun 12 16:05:12 localhost kernel: CIFS: Status code returned 0xc0000034 STATUS_OBJECT_NAME_NOT_FOUND
Jun 12 16:05:12 localhost kernel: CIFS: Status code returned 0xc0000034 STATUS_OBJECT_NAME_NOT_FOUND
Jun 12 16:05:12 localhost kernel: CIFS: Status code returned 0x80000006 STATUS_NO_MORE_FILES
Jun 12 16:05:12 localhost kernel: CIFS: Status code returned 0xc0000034 STATUS_OBJECT_NAME_NOT_FOUND
Jun 12 16:05:12 localhost kernel: CIFS: Status code returned 0xc0000101 STATUS_DIRECTORY_NOT_EMPTY
$ rm --recursive h
Jun 12 16:05:27 localhost kernel: CIFS: Status code returned 0xc0000034 STATUS_OBJECT_NAME_NOT_FOUND
Jun 12 16:05:27 localhost kernel: CIFS: Status code returned 0xc0000034 STATUS_OBJECT_NAME_NOT_FOUND
Jun 12 16:05:27 localhost kernel: CIFS: Status code returned 0xc0000034 STATUS_OBJECT_NAME_NOT_FOUND
Jun 12 16:05:27 localhost kernel: CIFS: Status code returned 0xc0000034 STATUS_OBJECT_NAME_NOT_FOUND
Jun 12 16:05:27 localhost kernel: CIFS: Status code returned 0xc0000034 STATUS_OBJECT_NAME_NOT_FOUND
Jun 12 16:05:27 localhost kernel: CIFS: Status code returned 0x80000006 STATUS_NO_MORE_FILES
Jun 12 16:05:27 localhost kernel: CIFS: Status code returned 0xc0000034 STATUS_OBJECT_NAME_NOT_FOUND
Jun 12 16:05:27 localhost kernel: CIFS: Status code returned 0xc0000056 STATUS_DELETE_PENDING
Jun 12 16:05:27 localhost kernel: CIFS: Status code returned 0xc0000056 STATUS_DELETE_PENDING
Jun 12 16:05:27 localhost kernel: CIFS: Status code returned 0xc0000056 STATUS_DELETE_PENDING
$ tree h
h
└── a

1 directory, 0 files
Jun 12 16:07:28 localhost kernel: CIFS: Status code returned 0xc0000034 STATUS_OBJECT_NAME_NOT_FOUND
Jun 12 16:07:28 localhost kernel: CIFS: Status code returned 0xc0000034 STATUS_OBJECT_NAME_NOT_FOUND
Jun 12 16:07:28 localhost kernel: CIFS: Status code returned 0xc0000034 STATUS_OBJECT_NAME_NOT_FOUND
Jun 12 16:07:28 localhost kernel: CIFS: Status code returned 0x80000006 STATUS_NO_MORE_FILES
Jun 12 16:07:28 localhost kernel: CIFS: Status code returned 0xc0000034 STATUS_OBJECT_NAME_NOT_FOUND
Jun 12 16:07:28 localhost kernel: CIFS: Status code returned 0xc0000056 STATUS_DELETE_PENDING
Jun 12 16:07:28 localhost kernel: CIFS: Status code returned 0xc0000056 STATUS_DELETE_PENDING
BumpySiren (11 rep)
Jun 9, 2023, 04:30 AM • Last activity: Mar 19, 2025, 11:41 AM
0 votes
1 answers
52 views
Strange "Directory not empty" for `rm -rf ...`command for %clean in rpmbuild of SLES15
After upgrading from SLES12 SP5 to SLES15 SP6 I noticed that the %clean phase of some RPM spec files fail for some strange reason when using `rpmbuild -ba`. The RPMs (SRPM, RPMs) are written correctly, but when cleaning up I see errors like this: ~~~lang-text Executing(%clean): /bin/sh -e /var/tmp/r...
After upgrading from SLES12 SP5 to SLES15 SP6 I noticed that the %clean phase of some RPM spec files fail for some strange reason when using rpmbuild -ba. The RPMs (SRPM, RPMs) are written correctly, but when cleaning up I see errors like this: ~~~lang-text Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.IXMkuS + umask 022 + cd /home/windl/rpmbuild/BUILD + cd iredir-0.5.1n + for d in "/home/windl/rpmbuild/BUILDROOT/iredir-0.5.1n-0.0.x86_64" + '[' -n /home/windl/rpmbuild/BUILDROOT/iredir-0.5.1n-0.0.x86_64 -a /home/windl/rpmbuild/BUILDROOT/iredir-0.5.1n-0.0.x86_64 '!=' / ']' + ls -l /home/windl/rpmbuild/BUILDROOT/iredir-0.5.1n-0.0.x86_64 total 12 drwxr-xr-x 6 windl dvmed 4096 Mar 10 10:40 etc drwxr-xr-x 6 windl dvmed 4096 Mar 10 10:40 usr drwxr-xr-x 5 windl dvmed 4096 Mar 10 10:40 var + rm -rf /home/windl/rpmbuild/BUILDROOT/iredir-0.5.1n-0.0.x86_64 rm: cannot remove '/home/windl/rpmbuild/BUILDROOT/iredir-0.5.1n-0.0.x86_64/usr/lib/ocf/resource.d/xola': Directory not empty rm: cannot remove '/home/windl/rpmbuild/BUILDROOT/iredir-0.5.1n-0.0.x86_64/usr/lib/iredir': Directory not empty rm: cannot remove '/home/windl/rpmbuild/BUILDROOT/iredir-0.5.1n-0.0.x86_64/etc/ocf/xola/isredir': Directory not empty rm: cannot remove '/home/windl/rpmbuild/BUILDROOT/iredir-0.5.1n-0.0.x86_64/etc/ocf/xola/idredir': Directory not empty rm: cannot remove '/home/windl/rpmbuild/BUILDROOT/iredir-0.5.1n-0.0.x86_64/etc/init.d': Directory not empty error: Bad exit status from /var/tmp/rpm-tmp.IXMkuS (%clean) ~~~ This is very strange as rm -rf is supposed to remove non-empty directories. I added the ls command after having experienced the issue: ~~~lang-rpm %clean # called for %install for d in "%{buildroot}" do [ -n "$d" -a "$d" != / ] && ls -l "$d" && rm -rf "$d" done ~~~ What might cause this? It seems like some asynchronous effect tto me. ~ is on NFS (also hosted by SLES15 (but SP5) (nfs-kernel-server-2.1.1-150500.22.3.1.x86_64, kernel 5.14.21-150500.55.83-default)). /usr/bin/rm is from coreutils-8.32-150400.9.6.1.x86_64. More Details ------------ I changed the RPM spec file to recursively list the whole directory, also adding -v to the rm command. When I see is that a directory contains four (normal) files that are deleted just before rm complains the directory isn't empty. More tests ---------- The effect is strange: When I created a test script that creates a directory, adds four files, and then removed that directory, it always works, while the rpmbuild -ba always fails for the same directory. Well, the total length of the paths for the rpmbuild is somewhat longer, but still smaller than say 120 characters. So I ran the whole thing under strace -f -s64with these results: ~~~lang-strace 1079 newfstatat(7, "xola", {st_mode=S_IFDIR|0755, st_size=4096, ...}, AT_SYMLINK_NOFOLLOW) = 0 1079 openat(7, "xola", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_NOFOLLOW|O_DIRECTORY) = 3 1079 fstat(3, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 1079 fcntl(3, F_GETFL) = 0x38800 (flags O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_NOFOLLOW|O_DIRECTORY) 1079 fcntl(3, F_SETFD, FD_CLOEXEC) = 0 1079 getdents64(3, 0x55d729e27910 /* 6 entries */, 1048576) = 176 1079 close(3) = 0 1079 openat(7, "xola", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_NOFOLLOW|O_CLOEXEC|O_DIRECTORY) = 3 1079 fstat(3, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 1079 fcntl(3, F_GETFL) = 0x38800 (flags O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_NOFOLLOW|O_DIRECTORY) 1079 fcntl(3, F_SETFD, FD_CLOEXEC) = 0 1079 fcntl(3, F_DUPFD_CLOEXEC, 3) = 8 1079 getdents64(3, 0x55d729e27910 /* 6 entries */, 1048576) = 176 1079 getdents64(3, 0x55d729e27910 /* 0 entries */, 1048576) = 0 1079 close(3) = 0 1079 unlinkat(8, "isredir", 0) = 0 1079 write(1, "removed '/home/windl/rpmbuild/BUILDROOT/iredir-0.5.3n-0.0.x86_64"..., 102) = 102 1079 unlinkat(8, "idredir.xml", 0) = 0 1079 write(1, "removed '/home/windl/rpmbuild/BUILDROOT/iredir-0.5.3n-0.0.x86_64"..., 106) = 106 1079 unlinkat(8, "isredir.xml", 0) = 0 1079 write(1, "removed '/home/windl/rpmbuild/BUILDROOT/iredir-0.5.3n-0.0.x86_64"..., 106) = 106 1079 unlinkat(8, "idredir", 0) = 0 1079 write(1, "removed '/home/windl/rpmbuild/BUILDROOT/iredir-0.5.3n-0.0.x86_64"..., 102) = 102 1079 close(8) = 0 1079 unlinkat(7, "xola", AT_REMOVEDIR) = -1 ENOTEMPTY (Directory not empty) 1079 write(2, "rm: ", 4) = 4 1079 write(2, "cannot remove '/home/windl/rpmbuild/BUILDROOT/iredir-0.5.3n-0.0."..., 99) = 99 1079 write(2, ": Directory not empty", 21) = 21 1079 write(2, "\n", 1) = 1 1079 close(7) = 0 1079 close(6) = 0 ~~~ So in my interpretation the xolasubdirectory has four files (with . and .. that are six directory entries). Before ls -lR showed ~~~lang-text /home/windl/rpmbuild/BUILDROOT/iredir-0.5.3n-0.0.x86_64/usr/lib/ocf/resource.d/xola: total 56 drwxr-xr-x 2 windl dvmed 4096 Mar 12 08:03 . drwxr-xr-x 3 windl dvmed 4096 Mar 12 08:03 .. -r-xr-xr-x 1 windl dvmed 13228 Oct 21 2019 idredir -r--r--r-- 1 windl dvmed 5543 Oct 10 2019 idredir.xml -r-xr-xr-x 1 windl dvmed 13507 Oct 21 2019 isredir -r--r--r-- 1 windl dvmed 5774 Oct 10 2019 isredir.xml ~~~ The four files were deleted successfully (rm -vrf being used), but then the directory could not be deleted. Somewhow I suspect the NFS attribute cache on either the client or on the server to cause this.
U. Windl (1715 rep)
Mar 10, 2025, 10:00 AM • Last activity: Mar 12, 2025, 07:19 AM
3 votes
4 answers
11783 views
Skip certain directories with rm -rf
I would like to know if and how it is possible to skip certain directories during an `rm -rf` operation. So for example, this location contains the following subfolders (not really this is just for example): ``` foo bar elf qrs ``` During my script which executes `rm -rf *` in this directory, I woul...
I would like to know if and how it is possible to skip certain directories during an rm -rf operation. So for example, this location contains the following subfolders (not really this is just for example):
foo
bar
elf
qrs
During my script which executes rm -rf * in this directory, I would like to know if it is possible to (for example) skip deletion of elf. Normally, I could just pass each directory to the command with rm -rf foo bar qrs, however my scenario is, since this is in a script for many different systems, every system will have different folders. For example, system 1 may contain these:
foo
bar
elf
qrs
While system2 may contain these:
ubt
dbn
arc
elf
gnt
I would like the rm -rf command to be the same for both; deleting everything apart from elf. Is this in any way possible? Thank you in advance.
Daniel M. (327 rep)
Jun 7, 2020, 05:27 PM • Last activity: Feb 18, 2025, 12:52 PM
2 votes
3 answers
33936 views
How to remove many files of similar names?
I have many txt files, named like ```file1.txt file2.txt file3.txt ... file1000.txt``` How can I delete all these files? I am new to unix and concerned about accidentally deleting other files in my directory. I've looked at other questions but I'm unsure, could I do something like ``` rm -v !("diffe...
I have many txt files, named like
.txt file2.txt file3.txt ... file1000.txt
How can I delete all these files? I am new to unix and concerned about accidentally deleting other files in my directory. I've looked at other questions but I'm unsure, could I do something like
rm -v !("differentfile"|"anotherfile"|"otherfile"|"finalfile")
and therefore delete all my files with the same name and just different numbers and keep the few I want? And this line should only delete files in my working directory/folder correct? Is there a way to use rm but only specific the files I want to delete all at once?
DN1 (237 rep)
Mar 12, 2020, 07:18 PM • Last activity: Jan 27, 2025, 03:58 PM
0 votes
1 answers
128 views
Inadvertently deleted a directory using FileZilla. How can I get it back?
I was using FileZilla to try to transfer some files. I made one mouse-click in the wrong place and wound up deleting a directory with over 14,000 files that I very much did not want deleted. I'm sure FileZilla is doing something like rm -rf and not moving the directory to "trash". I have a backup us...
I was using FileZilla to try to transfer some files. I made one mouse-click in the wrong place and wound up deleting a directory with over 14,000 files that I very much did not want deleted. I'm sure FileZilla is doing something like rm -rf and not moving the directory to "trash". I have a backup using IDrive, but their restore function is also failing. I have a call into them, so there is hope in that direction, but is there anything I can do to restore it locally? **UPDATE (1 day later):** Never mind. The files weren't deleted. The mouse click in FileZilla moved the directory under the one above it in the list. I thought I had checked this with the find command but I must have done it wrong. At least we've re-established the fact that there's nothing we can do if we really did delete the folder. And also that there's no point in using FileZilla anymore unless you're managing lots of servers. Just the plain Ubuntu Files app can handle my needs though it's a bit hidden. Someone suggested I use it but it's not necessary.
Steve Cohen (519 rep)
Jan 4, 2025, 03:27 AM • Last activity: Jan 6, 2025, 12:41 AM
141 votes
4 answers
92285 views
How do you do a dry run of rm to see what files will be deleted?
I want to see what files will be deleted when performing an `rm` in linux. Most commands seem to have a dry run option to show just such information, but I can't seem to find such an option for `rm`. Is this even possible?
I want to see what files will be deleted when performing an rm in linux. Most commands seem to have a dry run option to show just such information, but I can't seem to find such an option for rm. Is this even possible?
Cory Klein (19341 rep)
Feb 7, 2011, 08:09 PM • Last activity: Jan 1, 2025, 01:51 PM
7 votes
1 answers
1772 views
Did I accidentally delete files? How can I recover them?
I’m a new PhD student and I’m dealing with a serious issue. I tried to map a directory from Server A (/home/lab/Desktop) to Server B (/home/usr/labDesktop) because Server B has better computing power. While working, all the data in the directory on Server A disappeared. Here’s a part of the sequence...
I’m a new PhD student and I’m dealing with a serious issue. I tried to map a directory from Server A (/home/lab/Desktop) to Server B (/home/usr/labDesktop) because Server B has better computing power. While working, all the data in the directory on Server A disappeared. Here’s a part of the sequence of commands I ran, which might have caused the problem: $ sudo sshfs lab@ipaddress:/home/lab/Desktop /home/usr/labDesktop [sudo] password for usr: The authenticity of host 'ipaddress (ipaddress)' can't be established. XXX key fingerprint is XXX. This key is not known by any other names Are you sure you want to continue connecting (yes/no/[fingerprint])? yes lab@ipaddress's password: $ ls labDesktop  examples.desktop $ cd labDesktop -sh: 44: cd: can't cd to labDesktop $ ls labDesktop  examples.desktop $ sudo sshfs lab@ipaddress:/home/lab/Desktop /home/usr/labDesktop lab@ipaddress's password: read: Interrupted system call $ fusermount -u /home/usr/labDesktop fusermount: entry for /home/usr/labDesktop not found in /etc/mtab $ ls labDesktop  examples.desktop $ cd labDesktop -sh: 49: cd: can't cd to labDesktop $ rm -r labDesktop rm: cannot remove 'labDesktop': Permission denied $ sudo rm -r labDesktop                           rm: cannot remove 'labDesktop': Device or resource busy $ mount | grep /home/usr/labDesktop lab@ipaddress:/home/lab/Desktop on /home/usr/labDesktop type fuse.sshfs (rw,nosuid,nodev,relatime,user_id=0,group_id=0) $ fusermount -u /home/usr/labDesktop fusermount: entry for /home/usr/labDesktop not found in /etc/mtab $ fusermount -uz /home/usr/labDesktop fusermount: entry for /home/usr/labDesktop not found in /etc/mtab $ sudo umount /home/usr/labDesktop $ mount | grep /home/usr/labDesktop $ rm -r /home/usr/labDesktop $ ls examples.desktop As you can see, "sudo rm -r" threw an error message, "rm: cannot remove". So I don't believe this actually deleted the data. Moreover, I tried to unmount using "fusermount -u" before running "sudo rm -r". If "fusermount -u" failed with an error message, shouldn’t "sudo rm -r" have also failed with an error message? 1. Could this sequence of commands have caused the files on Server A to be deleted? Or is it likely something else caused the data loss? 2. How to recover them?
Andy Junghyun Kim (81 rep)
Dec 28, 2024, 12:58 PM • Last activity: Dec 31, 2024, 06:06 AM
176 votes
5 answers
41829 views
I deleted /bin/rm. How do I recover it?
Just for fun, I thought I would use this command on my Raspberry Pi running Raspbian: sudo rm -f /bin/rm I thought I could just reinstall `coreutils`: I was wrong! `apt-get install --reinstall coreutils` gives an error from `dpkg`, saying it couldn't remove the package. Compiling from source doesn't...
Just for fun, I thought I would use this command on my Raspberry Pi running Raspbian: sudo rm -f /bin/rm I thought I could just reinstall coreutils: I was wrong! apt-get install --reinstall coreutils gives an error from dpkg, saying it couldn't remove the package. Compiling from source doesn't work because the Makefile uses rm. How can I get a working rm back?
user60684 (1763 rep)
Feb 18, 2014, 04:14 PM • Last activity: Dec 29, 2024, 05:12 PM
11 votes
1 answers
3833 views
What are the .Trash-500 and .Trash-1000 directories?
I have a DNS-321 NAS drive which apparently runs Linux, so I logged in via ssh and I see `.Trash-500` and `.Trash-1000` directories. I realize that they're for trash, but why do I need two? Inside of them I see `expunged`, `files`, and `info` directories -- what are those for?
I have a DNS-321 NAS drive which apparently runs Linux, so I logged in via ssh and I see .Trash-500 and .Trash-1000 directories. I realize that they're for trash, but why do I need two? Inside of them I see expunged, files, and info directories -- what are those for?
Stann (2209 rep)
Dec 3, 2011, 05:28 PM • Last activity: Dec 26, 2024, 03:47 PM
0 votes
1 answers
110 views
Recursively delete empty files and then empty directories
The following script non-recursively deletes regular empty files, not including the dot ones, and then non-recursively deletes empty directories, not including the dot ones, and ignoring the presence of `.DS_Store` files (that is, if the directory contains only a `.DS_Store` file, that directory wil...
The following script non-recursively deletes regular empty files, not including the dot ones, and then non-recursively deletes empty directories, not including the dot ones, and ignoring the presence of .DS_Store files (that is, if the directory contains only a .DS_Store file, that directory will be nevertheless deleted).
rm -f -- *(.L0)

setopt extended_glob
has_files_other_than_DS_Store() [[ -n $REPLY/^(#i).ds_store(#qNDY1) ]]
remove_empty_macos_dirs() {
  local dir ret=0
  for dir do
    rm -f -- $dir/.(#i)ds_store(N.) && rmdir -- $dir || ret=$?
  done
  return $ret
}
remove_empty_macos_dirs *(/^+has_files_other_than_DS_Store)
Could somebody show how to make it work recursively? That is, the first step is to recursively delete all the empty regular files. And then recursively delete empty directories. I would try it myself, but to be honest I simply afraid to experiment with the rm command.
jsx97 (1347 rep)
Dec 20, 2024, 11:34 AM • Last activity: Dec 20, 2024, 02:04 PM
1 votes
2 answers
2017 views
How to safely delete a regular directory that contains several btrfs snapshots inside it?
I have a regular directory than contains directly underneath it several btrfs snapshots. Is it safe to do an `rm -rf` on the parent directory, or do I need to first do a `btrfs subvolume delete SUBVOL` on each of the snapshots before removing the parent directory?
I have a regular directory than contains directly underneath it several btrfs snapshots. Is it safe to do an rm -rf on the parent directory, or do I need to first do a btrfs subvolume delete SUBVOL on each of the snapshots before removing the parent directory?
user779159 (421 rep)
Jan 29, 2016, 12:47 PM • Last activity: Dec 12, 2024, 10:49 PM
97 votes
8 answers
111420 views
Recovering accidentally deleted files
I accidentally deleted a file from my laptop. I'm using Fedora. Is it possible to recover the file?
I accidentally deleted a file from my laptop. I'm using Fedora. Is it possible to recover the file?
C.S. (1833 rep)
Oct 3, 2010, 07:46 PM • Last activity: Nov 8, 2024, 08:44 PM
0 votes
1 answers
69 views
I deleted my /etc/alternatives/ by accident
I'm on ubuntu 22.04. I was there removing the files related to libcudnn. However, I thought i was CDing inside, but an enter later, I realized that I was on sudo rm -rfing there. So, I ended up deleting the entire folder. Now, I'm wondering if can I still work on ubuntu like nothing happened? Or sho...
I'm on ubuntu 22.04. I was there removing the files related to libcudnn. However, I thought i was CDing inside, but an enter later, I realized that I was on sudo rm -rfing there. So, I ended up deleting the entire folder. Now, I'm wondering if can I still work on ubuntu like nothing happened? Or should i reinstall it? How important are those alternative links? And as an alternative solution, (no puns intended) can I just ignore it if i start working in virtual envs?
fandn (1 rep)
Nov 7, 2024, 12:45 AM • Last activity: Nov 7, 2024, 06:17 AM
92 votes
1 answers
12045 views
Why does the following bash script delete itself?
If you create an executable file with the following contents, and run it, it will delete itself. How does this work? #!/bin/rm
If you create an executable file with the following contents, and run it, it will delete itself. How does this work? #!/bin/rm
Stack Exchange Broke The Law (2294 rep)
May 3, 2016, 11:38 AM • Last activity: Oct 2, 2024, 10:22 AM
221 votes
9 answers
114590 views
How to remove all empty directories in a subtree?
How can I remove all empty directories in a subtree? I used something like find . -type d -exec rmdir {} 2>/dev/null \; but I needs to be run multiple times in order to remove directories containing empty directories only. Moreover, it's quite slow, especially under cygwin.
How can I remove all empty directories in a subtree? I used something like find . -type d -exec rmdir {} 2>/dev/null \; but I needs to be run multiple times in order to remove directories containing empty directories only. Moreover, it's quite slow, especially under cygwin.
maaartinus (5219 rep)
Mar 1, 2011, 09:48 PM • Last activity: Sep 12, 2024, 09:06 AM
1 votes
3 answers
214 views
How to remove files which confirm to a certain number pattern
How to remove files which confirm to a certain number pattern I remove like this right now in MacOS, rm */sections.json.* */sections.json0* */sections.json1* all the way till 9
How to remove files which confirm to a certain number pattern I remove like this right now in MacOS, rm */sections.json.* */sections.json0* */sections.json1* all the way till 9
user352290 (121 rep)
Aug 22, 2024, 08:56 AM • Last activity: Aug 23, 2024, 10:24 AM
Showing page 1 of 20 total questions