Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [rm]

rm is the command to remove files

0
votes
3answers
29 views

How to escape parenthesis in bash rmdir?

I have a directory that has a name like 10.2 (14C92) i want to remove using rmdir -rf (to include their content). I am very new to the linux command line so i do know how to pass a space with \ but I ...
4
votes
0answers
39 views

Deleting non-empty directory without w permission while having w permission in parent directory

Here's the situation: dir1/dir2/file.txt permissions: drwxrwxrwx 4 me group 4.0K Jan 11 17:53 dir1 drwxr-xr-x 4 other_guy group 4.0K Jan 11 17:48 dir2 -rw-r--r-- 1 other_guy group 158 Jan 11 17:...
6
votes
5answers
640 views

How to delete all directories in a directory older than 2 weeks except the latest one that match a file pattern?

I have the following path: /dir1/dir2/ In this path I have the following directories containing various (not relevant) application detrius: follower1234 1-Dec-2018 follower3456 2-Dec-2018 ...
0
votes
2answers
50 views

how to delete files in folder with thousands of files [duplicate]

in the folder cd /var/log/hive I guess we have thundered of log files I say that because if I do under this folder ls -l then its stuck and only CNTRL C , will exit so I cant to vew all ...
0
votes
1answer
57 views

What are the differences between rm and '-delete' in find? [duplicate]

We want to delete the files under /tmp that are older than 100 minutes. What is the difference between: find /tmp -type f -mmin +100 -exec rm {} \; and: find /tmp -type f -mmin +100 -exec -delete ...
1
vote
1answer
30 views

Remove files in linux with different folder files to delete in a folder as particular folder

I want to remove multiple (all) files with different suffixes (.log,.bin) in a particular directory (/home/username) in a one-line command. How could I do that?
-1
votes
3answers
94 views

How to prevent “rm -rf ~” from being executed by mistake?

Is there any way to completely prevent this command from being executed, by mistake, in the terminal? I know that bash, for instance, has aliases. Is there a way to use them?
0
votes
1answer
35 views

What is the actual sequence of steps during rm -Rf on a very large folder?

Let's say I run rm -Rf on a very large folder with many files and folders of different size, user permissions etc. I would like to know, does the rm command first accumulate the list of files to ...
10
votes
1answer
768 views

Debian: cannot remove symlink in /sys/: operation not permitted

I ran some commands without completely understanding them while trying to get screen brightness working and now I'm stuck with a nasty symlink in '/sys/class/backlight/asus_laptop' that I am trying to ...
3
votes
1answer
110 views

rm to remove a dir, any symlinks, AND symlink destinations? [duplicate]

I have two directories: /all/origins/ & /all/links/. Everything in links/ points individually to something in origins/, but not everything in origins/ is linked in links/. (Squares, rectangles &...
-1
votes
0answers
49 views

What does rm do specifically? [duplicate]

Rationale: I have been looking into options for recovery of accidentally deleted files on linux systems without a GUI. During my research I realized that there are many posts explaining how to use rm, ...
1
vote
1answer
52 views

unlink delete files which are not links [duplicate]

I created a hard link $ ln hours.sh hours_link test it $ ls -l hours* -rw-r--r-- 2 me staff 653 Apr 12 2018 hours.sh -rw-r--r-- 2 me staff 653 Apr 12 2018 hours_link remove it with unlink $ ...
1
vote
4answers
137 views

double check remove on a wildcard

I accidentally removed a bunch of files I wasn't supposed to. I would like to implement some kind of safety net in the future to protect my files. I was hoping that any time I type rm * into the ...
0
votes
2answers
35 views

delete then rename: same filenames different extensions

I have a directory containing thousands of files, each file has a duplicate. An example: file1.txt file1.jpg.txt file2.txt file2.jpg.txt I want to delete all *.txt files, and leave the *.jpg.txt ...
1
vote
3answers
38 views

Remove files + files from subdirectories in Directory

I would like to remove all files from a directory /data which includes 8 other sub directories. Is there a command which will recursively clear all subdirectories but not remove the actual folders?
0
votes
1answer
50 views

Empty trash in ubuntu

I'm trying to empty my trash using the UI but it doesn't work. i tried to use this command rm -rf ~/.local/share/Trash/* but it does not success with messages like rm: cannot remove 'file.txt': Read-...
5
votes
3answers
757 views

Remove files that start with but don't contain

I'm trying to remove a lot of files at once but need to be specific as to not remove any of the files I actually need. I have a ton of corrupt files that start master- but there are valid files that ...
0
votes
2answers
35 views

Delete directories if they do not have newer files

I want to delete directories only if they have not changed in the last N days. And by changed I mean contain any files that are more recent than N. I constructed something similar / found this but ...
7
votes
5answers
767 views

Remove files which not named “today.md” [duplicate]

I have the a series of markdown files in the working directory: $ ls *.md csv_reader.md egrep.md find.md found_pdfs.md osPathSep_help.md readme.md smtplib_help.md today.md I want to remove ...
1
vote
0answers
37 views

removing directory [closed]

After motherboard replacement and system upgrade to Mojave my Mac was restored from backup including some macports codes in /opt . Since macports would not work properly I had to rename /opt/local to /...
0
votes
1answer
95 views

How to delete all directories inside a directory except for files, (safely)?

Environment System: Linux Mint 19 Cinnamon. Shell: Bash version 4.4.19(1). Problem Along with hundreds of testing scenarios, I must have created countless of temporary installation directories ...
2
votes
3answers
347 views

Delete identical files saved as output in a log

I have three files in two folders. The files are named, a.txt, b.txt and c.txt were located in A and B folders. I have used an app Full File Mini Comparer which compares the folder and saves to log to ...
0
votes
2answers
159 views

Using regular expression for rm and ls

QUESTION: What is happening here and how do I fix it? PROBLEM: When I do: $ls | grep -P "file[1-9]{3}.txt|file[1-9]{2}.txt" I get: file11.txt file12.txt file13.txt file14.txt file15.txt file16....
-4
votes
3answers
59 views

What does this command mean? (IO redirection question) [closed]

I am trying to figure out what this command is doing: rm OUTPUT/* >> log_${ENV} 2>&1
2
votes
2answers
54 views

Error in deleting files or directories older than 1 day

I am able to delete files or directories older than 1 day using below command find /u01/Release/* -mtime +1 -exec rm -r {} \; but why I am getting error in the output of this command: ls -lrt ...
-1
votes
1answer
44 views

Removing files containing, only, one row? [duplicate]

I have large number of csv files saved within a folder. I would like to, only, delete the csv files that contains one row, how can I do that?
1
vote
1answer
592 views

Is “find /var/log -type f -delete” safe on Debian 9?

I never view or care about files in /var/log/ and want to avoid logrotate wasting my system resources (CPU, RAM, I/O, etc.). Are any regular files in /var/log/ necessary for some core Debian program (...
0
votes
0answers
38 views

How to delete a git repo with submodule from NTFS partition and then git clone it with submodule initialized?

I tried setting my 2 TB hard drive partition into a NTFS file system, per an answer to an earlier question of mine. I moved a heap of my git repos onto it. Some of my repos have submodules, and ...
3
votes
2answers
459 views

How to delete files created between two times?

I have a folder where I backup my databases to and I want to delete all backups created between 11 am and 3 pm and it doesn't matter what day it is -- this is the catch! I found this command to be ...
2
votes
2answers
128 views

How to remove every file and folder recursively except for a few specific folders?

Having the Busybox ash shell at hand, I wish to cleanup the /opt folder. Cleanup means to remove every file and folder recursively except for a few exclusion paths that need to be left untouched. ...
0
votes
2answers
205 views

Why does my 'rm' command work fine in terminal on my mac but not from shell script?

I have a directory whose name contains spaces. I need to remove the contents of this particular directory. I am escaping spaces in the directory name with \ before removing the contents. The rm ...
1
vote
1answer
186 views

Yet another `rm: cannot remove 'file': Permission denied`

I want to remove the .html file from the /home/user1/html/ directory. I have tried nearly all of the solutions posted on a myriad of other web sites. Nothing is working. user1@comp1:~/html$ sudo rm ...
0
votes
1answer
149 views

How to remove parent directory without deleting sub folders?

For Example, I have 5 directories inside parent directory, I want to delete parent directory without deleting 5 subdirectories. As of now am doing with below code, mv parentFolder/* parentFolder/.....
3
votes
2answers
54 views

Delete .pdf files only if .xlsx files in directory have same filename?

I have folders with hundreds of pdf and xls(x) files that were mass exported from legal e-discovery systems. The filenames in these exports correspond to bates # such as ABCD_00000001.pdf, ...
0
votes
3answers
295 views

Delete the oldest files in folder if combined size of folder is more than 10G

The following syntax will remove the files under hive folder: /usr/bin/find /var/log/hive -type f -print -delete I am trying to do the following: Remove the oldest files under /var/log/hive only if ...
0
votes
3answers
704 views

how to remove all files exclude specific files [duplicate]

Under /var/log/hive we have a lot of log files we want to remove all files exclude the following that should be not removed hivemetastore.log hiveserver2-report.json.tmp hivemetastore-report.json....
0
votes
1answer
50 views

quote files matched by grep

grep's man page reads "grep -lZ outputs a zero byte after each file name instead of the usual newline" But in my case there are files in the output that still need quotes. In order for this to work: ...
0
votes
0answers
41 views

what are the chances of recovery from rm /* [duplicate]

I accidentally run $ rm -rf /* instead of $ rm -rf ./* Can I somehow recover home folder. Where does all my file goes. Could you tell me some of the softwares or tools to recover just the Home folder....
1
vote
1answer
45 views

Does Ctrl-C (SIGINT) prevent output to be shown even if there were processes trying to output it

I had a bash script which did the wrong thing. So I pressed Ctrl-C to stop it. Is now the output I currently see on my terminal all the output produced by the processes that have run. Are does Ctrl-...
44
votes
7answers
4k views

How can I harden bash scripts against causing harm when changed in the future?

So, I deleted my home folder (or, more precisely, all files I had write access to). What happened is that I had build="build" ... rm -rf "${build}/"* ... <do other things with $build> in a ...
1
vote
4answers
81 views

Is there a way to delete all files/directories created by program?

A program I installed splattered files and directories in different places. I'm having to manually remove these files and directories. I know you can delete files and directories created by a user ...
2
votes
4answers
1k views

delete all files ending with certain string

I have a directory containing around 15K images, with x number of sequences scene1_000000.png scene1_000001.png scene1_000002.png scene1_000003.png scene1_000004.png scene1_000005.png scene1_000006....
4
votes
2answers
1k views

Making alias of rm command [duplicate]

Making alias of rm command so that when rm command is executed it will first copy file to /tmp/recycle_bin and then remove the file. But I'm getting issue in the process. Steps performed by me: I ...
0
votes
2answers
236 views

Which file first get deleted first when deleting via rm -f with a glob pattern?

I've a folder with thousands of files with this pattern: YYYYMMDD_HH24MISS_4DIGITSEQUENCE. Example: 20180626_210123_0001. Now for example while I'm deleting via rm -f *20180626_1* command its ...
10
votes
1answer
3k views

alternative options to rm -f

I'd like to run a command line: cd ~/www/tmp/; rm -P 2* But I get an error if there are no files starting with 2. You would think I would want to use -f, however: -f Attempt to remove the ...
1
vote
1answer
55 views

Cannot rm corrupt directory

CentOS6 I am logged in as root. It is a virtual machine running on a Windows 10 host in virtualbox as a vagrant machine. I tried chmod -R 777 /home/thomas/WWW chown -R root:root /home/thomas/WWW ...
-1
votes
1answer
200 views

Linux Keeps Operating after rm -rf --no-preserve-root /

I have done my search but couldn't find any answer. After executing "rm --no-preserve-root -rf /", bash has told me things like: rm: cannot remove /proc/*: Operation not permitted ... rm: cannot ...
1
vote
1answer
47 views

Deleting old directory

I am trying to add a way to remove backups older than 3 days ago in my script. See below a stripped down simplified version, which just leaves the removal part. It was my understanding that ${...
3
votes
2answers
53 views

Remove all but latest version - no timestamp

I have a large collection of files that look like this: Some Name da-1234567-1.py Some Name da-1234567-2.py Some Name da-1234567-4.py Other Name di-5678912-3.py Other Name di-5678912-4.py Other Name ...
3
votes
2answers
50 views

Difference between rm my-symlink and rm my-symlink/

Just wanted to know why if I use rm -rf my-symlink it deletes the symbolic link only but rm -rf my-symlink/ deletes the files within the linked directory and leaves the symbolic link alone?