Questions tagged [rm]

rm is the command to remove files

0
votes
1answer
28 views

Cannot delete a file in a group

I'm trying to clean some garbage shared memory files left behind by a service after crashing. The service is run as a system user and a specific group. I'm a member of that group, but can't delete ...
3
votes
1answer
1k views

rm -fr fails to remove directory due to “Is a directory” error

Recently noticed that one of my CentOS NFS clients have a directory which looks somewhat corrupted: CentOS release 6.3 (Final) [root@LG-B8A-LNX ~]# ls -lathr / ls: cannot access /zebra: No such file ...
0
votes
1answer
60 views

Is it safe to delete a binary in /usr/bin?

I installed the precompiled binary of a command line program in /usr/bin, now I want to install the same program using my package manager. In order to avoid conflict between the package manager dnf ...
-2
votes
0answers
34 views

Accidently deleted my wifi name in linux mint [on hold]

I was trying to prevent xfinitywifi from automatically connecting (I have Google Fiber). And followed the advice found here: https://www.linuxquestions.org/questions/linux-newbie-8/how-to-prevent-...
2
votes
2answers
34 views

authorize wheel group to rm in specific folder

I would like to authorize wheel group to rm in a specific folder (in this case my folder is "CT"). I've tried to add this line in visudo: %wheel All=(ALL) /bin/rm /CT/ I have a test files "test1" ...
1
vote
2answers
44 views

How can I find the latest log for multiple jobs in AIX and delete the latest one

I am new to unix. I am trying to find the latest log of multiple jobs and delete the latest one. Can I write a shell script for it? I have tried with basic commands, but there it is selecting a ...
4
votes
1answer
842 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 &...
51
votes
5answers
102k views

How do I remove all sub-directories from within a directory?

This question is kind of a phase II to the first question I posted at here I have a directory that contains a bunch of sub-directories, .zip files, and other random files not contained within a sub-...
243
votes
3answers
304k views

find - exec rm vs -delete

I'm trying to understand the difference between these two commands: sudo find / -name .DS_Store -delete and sudo find / -name ".DS_Store" -exec rm {} \; I noticed that the execmethod is preferred....
0
votes
0answers
24 views

How to remove duplicate files in a directory [closed]

I have a directory with over 400 duplicate files, the only difference is an extra space before .extension, e.g. xxxx.ext & xxxx .ext
0
votes
2answers
54 views

How do I not delete files in only the directory I am in?

I want to delete files older than 30 days in a directory, but not in directories below the one I am in.
1
vote
1answer
28 views

Speed up random sort and delete (rm) for multiple directories

Running MacOS in a terminal which is essentially BSD, hence posting my question here instead of askdifferent. I want to trim my image dataset down in subsequent steps, by deleting files randomly. Some ...
1
vote
2answers
54 views

Why does `find -type d -exec rmdir {} \;` command produce “No such file or directory message”

For testing purposes, I created the following directories. user@linux:~$ mkdir dir0{1..3} user@linux:~$ ls -l total 12K drwxr-xr-x 2 user user 4.0K Mei 31 10:45 dir01 drwxr-xr-x 2 user user 4.0K ...
1
vote
1answer
27 views

Safely remove a symlink or hardlink

Does using rm on a symlink or a hard-link remove the source in addition to the link? Is there a good way to delete a hard-link or a symlink without deleting the source? And if there is a good way ...
14
votes
4answers
66k views

delete subfolders without deleting parent folder

For this type of dir structure : /config/filegroups/filegroupA/files/fileA1.txt /config/filegroups/filegroupA/files/fileA2.txt /config/filegroups/filegroupB/files/fileB1.txt /config/filegroups/...
-1
votes
0answers
19 views

Ext4 error when deleting files in a folder

I am using a BeagleBone board with Linux. In a script I use the following command in order to completely remove the content from a mounted encrypted partition called /app rm -rf /app/* I receive ...
0
votes
1answer
58 views

Moving files to a bin [closed]

I am having issues with my code below: #!/bin/bash #Removing Files into the Recycle Bin(Deleted Directory) filemove=$1 #Saving the first argument as "filemove" mkdir -p ~/deleted #Create the deleted ...
51
votes
7answers
26k views

Make `rm` move to trash

Is there a Linux script / application which, instead of deleting files, moves them to a special “trash” location? I’d like this as a replacement for rm (maybe even aliasing the latter; there are pros ...
2
votes
2answers
90 views

How do I delete files except some specific files passed as parameters?

The task is to write a shell script with n+1 arguments where the first one is the directory and the rest is the specified files and will delete all but specified files. E.g. calling rmexcept . '*....
43
votes
7answers
72k views

How do I recursively shred an entire directory tree?

I have a directory tree that I would like to shred with the Linux 'shred' utility. Unfortunately, shred has no -R option for recursive shredding. How can I shred an entire directory tree ...
1
vote
1answer
52 views

Deleted /lib/modules/<kernel version> by mistake. How to recover?

I accidentally deleted my /lib/modules/<kernel version directory>. Here's the full output of sudo rm -rfv /lib/modules/4.14.98+ : pastebin Is there a way to restore the modules keeping the ...
3
votes
3answers
286 views

Remove everything except csv file Bash Script

I would like to delete everything from a folder except csv files I am trying with a bash script and I am getting this error: syntax error near unexpected token `(' This is my script : PATH=/tmp/ ...
41
votes
5answers
51k views

How can I remove all symbolic links with a special target?

With the command: ls -la * I can list all my symbolic links. How can I remove all symbolic links which are linked to a special folder? For example: In my directory usr/local/bin I have the ...
0
votes
3answers
79 views

Delete files same name but different file extension

I have a mess in my photo libary. I have files like these: image-1.jpg image-1.jpeg image-2.jpg Now I want to delete all photos with the extension .jpeg when there is a file with the same name but ...
0
votes
1answer
3k views

How to manage “device or resource busy” in a script?

I have a little script that have to remove some files. How can I manage the device or resource busy error of rm? Can I catch it? Like a try/catch? So that if I catch it I, for example, sleep 3 seconds ...
0
votes
3answers
108 views

Safe way of running an equivalent to rm -rf * [closed]

I have a task which contain a series of manual steps. One of the steps is to execute rm -rf *. Everything in the folder does need to be deleted but this seems a little dangerous for example. if the ...
3
votes
2answers
215 views

Deleting files older than 30 days based on filename as date

If I have a folder of files with their filenames as the date they were created: 2019_04_30.txt 2019_04_15.txt 2019_04_10.txt 2019_02_20.txt 2019_01_05.txt How would I compare the files names against ...
1
vote
4answers
69 views

Delete files - Keep newest based on filename pattern

I have a directory with a lot of files. Each file have the same pattern <id>_data_<date>.csv. What i want to do is to delete all files but to keep the newest per <id>. Example ...
0
votes
1answer
57 views

Command to Delete Millions of Files From Directory

I have directory which contains millions of files of small size (output from a big data program). I need to delete those directories but when I type the standard rm * I get: zsh: sure you want to ...
2
votes
0answers
1k views

Unable to remove folder, even with `--force`, sudo not needed

Trying to remove a folder: $ rm -r folder rm: cannot remove 'folder/subfolder/cifscaf6': No such file or directory Doesn't work. Let's try with -f: $ rm -rf folder rm: cannot remove 'folder/...
1
vote
0answers
49 views

Color rm -i prompt messages

I'm looking for a way to apply custom colors to messages emitted by the rm -i command: ~ $ rm -i file.txt rm: remove regular empty file 'file.txt'? I understand that I need to redirect the stderr as ...
2
votes
2answers
130 views

How to delete files if a numerical part of their name is greater than a given number?

I've got files like this: cap_20151023T122915_791033959.png cap_20151023T122918_946392456.png cap_20151023T122920_227637228.png cap_20151023T122920_875467456.png and I would like to use the find ...
0
votes
1answer
721 views

How do I delete directory and file, if .picasa.ini is the only file in the directory?

I want to start from a root directory and recurse through the tree. I want to delete the directory and file if there is only one file in the directory called .picasa.ini It seems like the "find" ...
0
votes
1answer
199 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-...
3
votes
2answers
641 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 ...
153
votes
16answers
223k views

Efficiently delete large directory containing thousands of files

We have an issue with a folder becoming unwieldy with hundreds of thousands of tiny files. There are so many files that performing rm -rf returns an error and instead what we need to do is something ...
2
votes
3answers
173 views

How can I make rm -rf ask for confirmation just once at the directory level?

If I use rm -rfi, this asks me every time each file is deleted. If I have a list of rm -rf commands, how can I make it so that the machine asks me for confirmation just once (when trying to delete the ...
50
votes
5answers
129k views

How to avoid the need to issue “y” several times when removing protected file

I'm looking for a solution to be used as a response to "rm: remove write-protected regular file [x] ?" I was thinking of issuing a character followed by carriage return for several amount of times, ...
1
vote
2answers
110 views

Sudo rm -rf does not remove a non-empty folder

I have a mounted an external hard disk on /media/pcmagas/Backup disk containing a folder dimitrios. When I try to remove it with the following comand: /media/pcmagas/Backup disk sudo rm -rf ./...
0
votes
1answer
67 views

I deleted my files with git rm, but i also commited them, how to get them back?

I ran git rm on some files thinking that they will be removed from the bitbucket repository, and i also commited them, after that i checked that they disapeared from the bitbucket repo, but they were ...
1
vote
4answers
111 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
1answer
72 views

using rm -rf in the scripts [duplicate]

sometimes using rm -rf in script could be catastrophic example rm -rf $TMP/$folder when TMP and $folder are without any value , it will actually removing all under "/" so I am asking how to use ...
3
votes
1answer
853 views

find all directories (except `encoded`) in the working dir then delete all of them

I am trying to test this scenario, I have these files /encoded encode <~~~ a bash script /dir1 /dir2 .../dir2-sub test.meta what I wish is, for find to search for all directories in our current (...
0
votes
2answers
2k views

Deleting many files except one type [duplicate]

Possible Duplicate: Deleting all files in a folder except files X, Y, and Z I am writing a script to compile many .tex files. After that, many auxiliaries files were created. So, I would like ...
1
vote
4answers
2k views

Configure rm command

I want to configure rm command. When one types rm to delete a file, then instead of deleting it right away, the file has to be transferred to the .trash of home folder. Can someone help me ?
4
votes
4answers
2k views

Remove all files except for last file of each month

Consider a directory with MySQL backup files with timestamps as part of the filename: -rw-rw-r-- 1 ubuntu ubuntu 35856184 Nov 16 16:00 db_2013-11-16_1600.sql -rw-rw-r-- 1 ubuntu ubuntu 35856915 Nov ...
12
votes
4answers
3k views

removed a vagrant file and now I see .nfs0000000000b869e300000001?

I rm'd a file and now I see: $ l total 64 -rw-rw-r-- 1 502 17229 Sep 17 16:42 page_object_methods.rb drwxrwxr-x 7 502 238 Sep 18 18:41 ../ -rw-rw-r-- 1 502 18437 Sep 18 18:41 ...
7
votes
2answers
4k views

Difference between rmdir and rm -r

I usually delete directories by using rm: rm -r myDir However I am aware of another command, rmdir, which seems to do the job just as well: rmdir myDir What is the difference between these two ...
0
votes
1answer
98 views

rm is not working with []

I have files like: ls CONFIG2 DOS DOSCAR KPOINTS PCDAT WAVECAR submit_vasp_beskow.sh CHG EIGENVAL OSZICAR POSCAR XDATCAR vasprun.xml CHGCAR IBZKPT OUT ...
0
votes
1answer
968 views

dd script with timings

Trying to figure out the best approach to a script that will do the following: Create a loop script that creates a 10GB file using dd where, upon completion, removes the file, then repeats 25 times ...