Questions tagged [rm]

rm is the command to remove files

Filter by
Sorted by
Tagged with
0 votes
0 answers
40 views

Simple way to delete files absolutely [duplicate]

I want to actually delete files in linux, as opposed to just erasing the representation of a file, with the command rm, for example, actually deleting the file literally, and as a basic good security ...
user avatar
16 votes
4 answers
2k views

Delete a file called '.env'$'\r'

I have no idea what created this file - I guess a terrible shell script. It is called '.env'$'\r' I have tried various versions of rm, and the technique of opening the direcory with vim ./, selecting ...
user avatar
0 votes
2 answers
29 views

Erasing the boot disk on an external hard drive

I recently had my original computer stolen so I bought a second hand one and created a boot disk for Bullseye using dd in a linux VM on the original windows OS. This worked perfectly fine and bullseye ...
user avatar
0 votes
3 answers
70 views

How to display a prompt and prevent execution against basic but dangerous commands like mv or rm

Objective Whenever I use mv (or commands of similar nature) I want my shell to prompt me something like "Hey, you used mv. Sorry but do it again using mv -i". I'd like to know the reasonable ...
user avatar
  • 391
0 votes
1 answer
19 views

Deleting Files in a Directory that contain a single quote (') character

I Have files as such: "contrail's", hello , "larch's"...etc How could I delete files that contain a single quote (') character(ex: "kibosh's" ). I was thinking in using ...
user avatar
  • 53
0 votes
0 answers
17 views

Deleting A List Of Files Using Grep [duplicate]

I want to delete files in a given directory (/home/cs12/derf/files) which only contain the single word "Delete" in its file contents. Any file that does not have the expected content should ...
user avatar
  • 53
1 vote
0 answers
89 views

Recovering deleted directory with rm -rf /* (no sudo)

I am (was) running a Minecraft server in my second computer (Debian). I was deleting some files in the server and i did rm -rf /* instead of rm -rf *, which deleted everything that did not require ...
user avatar
1 vote
2 answers
200 views

why rmdir can work well when delete cgroup directory but rm -rf can not?

Here is a cgroup tree. Root node is demo and it has only one child demo/ ├── cgroup.clone_children ├── cgroup.procs ├── cgroup.sane_behavior ├── child │   ├── cgroup.clone_children │   ├── cgroup....
user avatar
18 votes
2 answers
2k views

I've copied a directory with `cp -as` and now I'm terrified to `rm -rf` the created directory as it might delete the original

I've copied a directory with cp -as /media/user/dir symlinks and now I'm terrified to rm -rf symlinks as it might delete files in /media/user/dir What is the safe way to only delete the directory ...
user avatar
  • 299
0 votes
1 answer
151 views

change rm alias to mv

Reference: how to change `rm` to as a command like `mv ~/ .trash` I would like to implement recycle bin utility in UNIX since UNIX not has one. In .bashrc file I change alias rm='move.sh" as per ...
user avatar
  • 3
1 vote
1 answer
51 views

How to rm files starting with a digit

I have following files starting with a digit. $ echo [0-9]* 1001tracklistsIcon.svelte 1passwordIcon.svelte 3mIcon.svelte 42Icon.svelte 4chanIcon.svelte 4dIcon.svelte 500pxIcon.svelte And I'd like to ...
user avatar
  • 603
0 votes
1 answer
123 views

sudo rm -rf directory/* does not work with certain permission settings [duplicate]

I have a directory /var/opt/gitlab/backups with the following permissions: [user@localhost ~]$ sudo ls -la /var/opt/gitlab/backups total 1316296 drwx------. 2 git root 63 1月 21 21:44 . ...
user avatar
  • 105
-1 votes
1 answer
516 views

Correct usage of "rm" to remove files matching a pattern

If I want to use the rm command to remove all files with the .log extension from a directory, how can I do that? I tried - rm * .log , but I don't know if it works.
user avatar
  • 15
3 votes
2 answers
145 views

how to delete files from list.txt and use a wildcard?

Trying to delete files using a list of the headers and a wildcard. The headers for the files are the same but the endings are different. Not sure how to get the wildcard in there. I was trying to ...
user avatar
  • 33
7 votes
1 answer
458 views

Why does "find -delete" imply "-depth"?

The man page for GNU find clearly warns that using -delete implies -depth. However, I cannot find any explanation for this requirement: -delete Delete files; true if removal succeeded. If the ...
user avatar
  • 90.3k
1 vote
1 answer
1k views

Cron job to delete all files older than 7 days: -exec rm -f {} \; vs -delete [duplicate]

I want to run a cron job which deletes .txt files older than 7 days. I have two commands. The first command: /usr/bin/find /var/www/example.com/wp-content/targetdir -name "*.txt" -type f -...
user avatar
0 votes
0 answers
100 views

Delete all files in directories tomcat_*/temp on each application restart

We do have an operation script to stop, restart and start tomcat services. I am asked to make changes in the operation script so when starting tomcat with operation_script.sh, All files in directories ...
user avatar
-1 votes
1 answer
106 views

How to remove a full directory via Debian commandline? [duplicate]

I am trying to make a bash install script. One of the tasks it has to do is to remove a certain full directory if it is present. I tried rmdir [location of directory] but it gives an error saying ...
user avatar
17 votes
2 answers
3k views

Why doesn't rmdir work recursively?

rmdir deletes only an empty directory. To delete recursively, rm -rf is used. Why doesn't rmdir have a recursive option? Logically, when I am deleting a directory, I want to use rmdir. Given that rm ...
user avatar
0 votes
1 answer
95 views

Prevent rm -r of btrfs snapshots

I would like to use btrfs snapshots as a safety measure in case of accidental sudo rm -rf /* or similar but unfortunately you can delete readonly snapshots with rm -r. Can I disable this "feature&...
user avatar
  • 335
0 votes
1 answer
58 views

How to remove only links, but not actual files?

I have a folder full of .svg files, some of which are actual files and others are merely links to files. They both have the .svg file extension, however the actual files are labeled "SVG Image&...
user avatar
  • 113
0 votes
1 answer
56 views

Delete directory tree that contains read-only directories

If you run rm -rf dir and dir contains read-only directories then it will fail to remove any files in that directory. Is there any way to make rm recognise that and chmod the directory to be writable ...
user avatar
  • 434
3 votes
2 answers
305 views

Permission denied on trying to "rm -rf" my own directory on macOS command line

I have noticed rm -rf has a strange behavior in my macOS BigSur. I created a directory for a font installation: ~/code ❯ ls -la 10:06:54 total ...
user avatar
  • 151
0 votes
0 answers
132 views

Accidentally ran "rm -rf /" on macOS

A friend mentioned to me that he couldn't believe that the command to delete everything on a unix system was only eight characters long. I told him that you actually needed to use "--no-preserve-...
user avatar
  • 3
-1 votes
1 answer
106 views

Cannot delete directory

I am trying to delete a directory. rm -rf bla rm: cannot remove ‘bla’: Directory not empty It looks empty. I have also tried rmdir. The ownership and groups looks fine. In fact, the directory was ...
user avatar
0 votes
1 answer
98 views

Can not delete files

I copied some files from a DVD using the 'cp -a' command. Now, I can't delete any of the copied files. I set selinux to "permissive" to remove that as source of the problem. Here is what ...
user avatar
  • 309
2 votes
3 answers
480 views

How to avoid use of rm -rf in bash scripts?

I had once a dangerous experience with the use of rm -rf, due to a unset variable. Since then, I have been extremely cautious in composing a script that involves rm -rf. Cross checking the spell ...
user avatar
  • 703
-2 votes
1 answer
2k views

How to recover files deleted by rm -vr?

When looking up a way to uninstall minecraft using console commands, the very first result on google told me to use the command: rm -vr ~/ .minecraft/*. I thought, oh well, I'm specifying the ...
user avatar
0 votes
0 answers
87 views

What is a good way to redefine rm so to prevent accidental home deletion? [duplicate]

So it already happened to me once, I was trying to run rm -r ~/.emacs.d But accidentally hit enter at just the wrong moment. rm -r ~ Luckily I run into protected files before deleting everything, ...
user avatar
2 votes
1 answer
37 views

Ensuring no files were deleted from directory at a certain time

I accidentally started an rm -rf on a large directory that I was working in. The directory contains, among other things, a data directory containing a number of subdirectories that each contain ...
user avatar
2 votes
4 answers
176 views

rm -rf : is there an all or nothing (atomic) approach?

Let's say I have the following structure : $ mkdir d1 $ mkdir d1/d2 $ touch d1/f1 $ touch d1/d2/f2 $ chmod u-w d1/d2 If I try to remove d1, I can't because I don't have write permissions on d1/d2. ...
user avatar
  • 1,030
23 votes
9 answers
8k views

Is `yes | rm -r` safer than `rm -rf`?

I have heard many times that issuing rm -rf is dangerous since users can accidentally remove the entire system. But sometimes I want to remove a directory recursively without being asked every time. I ...
user avatar
0 votes
1 answer
84 views

Delete all folders in specified path that do not have word "edit" in them?

I'm trying to set up a simple script that would clean up my working folder. The working folder is structured like that: Project 1 Project 1 [edited] Project 2 Project 2 [edited] Project 3 Project 3 [...
user avatar
  • 3
0 votes
1 answer
57 views

Oracle Linux 6.7 - Nohup: Argument list too long

There are 1 million directories and some files in directories (.pdf, .csv etc.) under the path I have specified below: /data/upl/repo/exp/ I want all files and folders older than 1 year to be deleted,...
user avatar
-3 votes
1 answer
70 views

Is it OK if I add a duplicated option when calling an alias for rm?

I have alias rm='rm -i' in .bashrc. Now, if I use rm -i by mistake, it will become rm -i -i. Would anything go wrong because of two same options?
user avatar
0 votes
1 answer
72 views

Find all *.xml.err files with certain content in certain directory and need to move the *.xml files to its parent directory and remove *.xml.err files

I am trying to compose a Linux shell command but stuck here. Here is the background: The system will generate .xml and .xml.error correspondingly under /tmp/A/processed,/tmp/A/not_processed,/tmp/B/...
user avatar
0 votes
0 answers
79 views

Why this script doesn't work from cron while it works when invoke from my shell?

The following code does work when invoked from my shell: #!/usr/bin/bash how_many=$(find /home/jerzy/pCloudDrive -type d -iname "CS202*"|wc -l) #/usr/bin/echo ${how_many} >>/home/...
user avatar
-1 votes
1 answer
767 views

I ran “sudo rm -rf /*” and now my PC won't boot

I ran sudo rm -rf /* on Zorin OS because my friend dared me to and now I can't even boot to my motherboard BIOS. How should I go about fixing this? Or am I hopelessly doomed? I have tried power ...
user avatar
1 vote
1 answer
91 views

how to globally unalias rm cp mv in RHEL 7

from a clean instal of RHEL 7.9 x86_64, all users (including root) have a bash shell. And the commands mv and cp and rm are aliased to have the i option to them. Which I do not like; how does one ...
user avatar
  • 4,221
0 votes
0 answers
51 views

I accidentally typed sudo rm /* resulting in loss of "ls" and possibly other commands [duplicate]

I am a beginner and for deleting the files in the directory tried to use sudo rm / after which I said that it couldn't delete /home, etc. On seeing the files I realized that I just passed in the ...
user avatar
0 votes
0 answers
79 views

scp / ssh: deleting a big file (1 TB+) WHILE it is being transferred

EDIT — To clarify/summarize, the scenario is the following: - Context: Large file (1 TB+) on server A, virtually no disk space left on server A, disk utilization on A keeps growing rapidly and that ...
user avatar
  • 1,425
1 vote
0 answers
39 views

How to safely remove directory tree in script with path defined by a variable

This is a very basic question, and surely has been asked before, but I am having trouble finding the answer or guidance. There are e.g. these but they don't quite hit the mark: How to safely remove ...
user avatar
-3 votes
1 answer
180 views

How rm command free up disk space?

I'm trying to understand how rm command works and get this one: The rm command removes the entry of specified file from indexing. Since file is removed, Linux marks the block where the file was ...
user avatar
  • 105
2 votes
1 answer
203 views

How to use the shred command the right way?

I got to know about shred yesterday. I want to know the proper way of removing files with it. Should I first shred the file and then use rm to remove it? $shred <file> $rm <file> Or ...
user avatar
1 vote
2 answers
69 views

Can't delete multiple files with spaces on name with rm

I'm working on a deploy script for my dotfiles, they are stored on a Git bare repository, from which i git checkout it's files into my home directory, in order to seamlessy do it without thousands of ...
user avatar
0 votes
2 answers
80 views

Does the speed of operations on a file (copy, move, remove) depend on permissions of that file?

Does the speed of operations on a file (copy, move, remove) depend on permissions of that file? If so, then how? Reason: need to constantly perform mentioned operations on many files. Will these ...
user avatar
  • 397
2 votes
1 answer
398 views

Why is deleting files in Ubuntu slow?

I read on a stackoveflow post that on Linux, when we delete a file, it is not actually deleted, only the link from the inode table is removed to that file. If that is the case, then why isn't delete a ...
user avatar
0 votes
1 answer
209 views

How to safely remove all files (including hidden files) from current directory (after cding to that directory)?

How to safely remove all files (including hidden files) from current directory (after cding to that directory)? As far as I know, cd RELEVANT_DIR && rm * won't remove hidden files. I would ...
user avatar
33 votes
3 answers
4k views

I just deleted everything in my home directory. How? And why are some files still there?

Never thought this would happen to me, but there you go. ¯\_(ツ)_/¯ I ran a build script from a repository inside the wrong directory without looking at the source first. Here's the script Scripts/...
user avatar
-3 votes
1 answer
58 views

find + delete folders with extension when using variable

we have linux rhel machine 7.2 with the following folders under /kafka/topics drwxr-xr-x 2 root kafka 141 May 11 17:19 bgol.ase.fgt.dad3-1 drwxr-xr-x 2 root kafka 141 May 11 17:19 bgol.ase.fgt....
user avatar
  • 11.1k

1
2 3 4 5
16