Stack Exchange Network

Stack Exchange network consists of 175 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
2answers
68 views

I accidentally exited vim with :x!~ and now my ~ shows up in a different path

When exiting a file as root, I typed :x!~ and hit enter. Now I have the following: root@host:/etc/shinken/services$ ll total 64K -rw-r--r-- 1 0 0 515 Sep 1 18:24 ~ drwxr-xr-x 2 10003 ...
2
votes
4answers
1k views

Delete sub-directories with YYYYMMDD in name older than N days

I have a directory where daily subdirectories are created, literally named according to $date. How can I delete folders and their contents that are older than 7 days according to the YYYYMMDD in the ...
1
vote
1answer
686 views

How to remove all occurrences of .DS_Store in a folder

Think of it as going to the most high level folder, doing a Ctrl Find, and searching .DS_Store and deleting them all. I want them all deleted, from all subfolders and subfolders subfolders and so on. ...
0
votes
1answer
869 views

How to rescue files after $ rm -rd ./* on encrypted, external HDD?

I tried to delete all files named "Thumbs.db" with something like $ rm -rd /path/to/hdd/decrypted/folder/* --name Thumbs.db but it just started deleting in alphabetical order. Now, I have to recover ...
1
vote
2answers
1k views

How to remove duplicated directories that contain the same files?

I have multiple directories that contain text files. Some of these directories are named differently yet contain the same text files. How do I remove all duplicated directories?
2
votes
1answer
85 views

I've a list of files - resulted from find command, how can I use it to zip/tar the files and delete the original files

I have a list of files from the find command. How can I zip/tar the files and delete the original files? The results are from: find . -type f -exec egrep "mxprod|nlsoprdc" {} /dev/null \;; how can I ...
4
votes
2answers
7k views

rm wildcard not working

I want to delete all .swp files recursively. However: rm -r *.swp Gives: rm: cannot remove ‘*.swp’: No such file or directory Just to be sure, ls -all gives: total 628 drwxr--r--. 8 przecze ...
1
vote
2answers
800 views

Aliasing `rm` to create a CLI “recycle bin”

When we do mv /root/file /root/folder/ It moves /root/file to /root/folder I want to do the same thing, but I want to reverse the order of how mv perceives the arguments I want to declare an ...
0
votes
1answer
550 views

Debian - cannot delete /etc/group- — “Device or resource busy”

I can't remove /etc/group- -- why not? root@dom:/etc# whoami root root@dom:/etc# pwd /etc root@dom:/etc# rm -f /etc/group- rm: cannot remove ‘/etc/group-’: Device or resource busy root@dom:/etc# ...
4
votes
4answers
1k views

Unable to remove the $ sign named files using linux? [duplicate]

Here is my ls command, which shows the list of files in my current directory: rper: ls -l $commandoutput[0] file.txt I tried to remove $commandoutput[0] line by using rm -rf $commandoutput[0], ...
1
vote
2answers
67 views

Houskeep old files and dirs

I'm having a bit of trouble, I'm trying to do a script that will create a list of files and dirs older than 7 days and delete the ones that are not in the list tokeep.list. My first problem is that if ...
0
votes
3answers
479 views

How can i remove the unwanted files with tilde mark using linux command?

Here I want to remove all tilde files from my directories and subdirectories . How can I use the linux command here? Tree Structure: . |-- Block_Physical_design_checklist | |-- ...
1
vote
1answer
70 views

Black screen after i ran command

I wanted to completely remove pcsxr and i type -find / *pcsxr* -delete and now my screen gone completely black. I don't know what to do and what i did wrong. I reboot now and I'm in boot menu and i ...
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
2answers
2k views

rm -r inside Makefile not removing directory

I am trying to check a website with html-proofer with a Makefile rule and delete a temporal folder when it ends. To make this work I start a server in one console and in another one execute the ...
0
votes
1answer
354 views

Why the following error appears when using rm -rf * in my current location? [duplicate]

I have tried to remove all folders from my current directory using Linux command rm -rf *. But the following error occurs and the respected folder is also not deleted. rm: cannot remove ‘Xenon_R3_S/...
0
votes
2answers
59 views

Deleting files except if the name contains a substring

I am using following command for deleting files in a folder. But my command is deleting everything. ionice -c 3 find . -type f -print -delete I don't want to delete a file if have a _y suffix. So, ...
3
votes
1answer
191 views

Help with triage after running rm -rf /* as a non root user

So, in the process of debugging a build process for a software package I accidentally ran the command rm -rf build /* as a non-root user on my laptop. I stopped the command as soon as I saw permission ...
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 ...
2
votes
2answers
11k views

as root cannot remove file under /tmp operation not permitted

working on a server, operating system is SLES 11.4 x86-64. There are many files, and folders, under the /tmp directory. As root, I cannot remove anything under /tmp. Such as rm -f sort5BtEdh or rm /...
1
vote
1answer
126 views

Can I unlink in perl with a list from a unix find command?

Trying to delete thousands of files on multiple servers. rm will not work. Wrote a generic script to run from cron to delete on a regular basis: ... /bin/perl -e 'unlink ( <`find ${DIRECTORY} -...
-4
votes
1answer
4k views

rm: refusing to remove '.' or '..' directory: skipping '..'

Why when I try to delete .. from directory I receive error: rm: refusing to remove '.' or '..' directory: skipping '..' And before you ask why I want to do this. Just because
3
votes
2answers
2k views

Find missing file names between 2 directories in Linux

I am trying to compare 2 directories ( A / B ) in Linux and DELETE any files from B which DO NOT exist in A. For example, if file '1.jpg' exists in Directory B but does not exist in Directory A then ...
6
votes
3answers
1k views

tee -a does not recreate file

I am running the following command on a Raspberry Pi 3 Debian latest release: cat /dev/ttyUSB0 | tee -a /media/pi/KINGSTON/klima.out | grep -F $ | tee -a /media/pi/KINGSTON/log The command works ...
2
votes
0answers
155 views

Why find -name DIR -exec rm -rf {} + does not remove directories [duplicate]

I want to cleanup my cmake project and run this command find -name CMakeFiles -o -name CMakeCache.txt -exec rm -rf "{}" + It deletes files CMakeCache.txt but refuses to remove directories. So I have ...
0
votes
2answers
68 views

Using find to look for a directory and remove its subdirectories

Let's say I have a list of nested directories that looks like this: ./x1/mf/dir1 ./x1/mf/dir2 ./x1/mf/file1 ./x2/mf/dir3 ./x2/mf/file2 ... I want to remove all the subdirectories of every mf ...
0
votes
1answer
110 views

In a subdirectory, how do I delete all files that are 0 bytes in size? [duplicate]

I am used to listing and sorting the size of files as follows: $ for entry in $(ls); do du -s "$entry"; done | sort -n However, how does one delete all files of 0 bytes? My terrible attempt would ...
8
votes
2answers
1k views

Why doesn't find/rm -iname '*phpmyadmin' delete phpMyAdmin-Version-XYZ.zip?

I have this following code: find ./ -iname '*phpmyadmin' -exec rm -rf {} \; It deletes a dir called phpmyadmin, but it does not delete a file called phpMyAdmin-Version-XYZ.zip Even if I remove the -...
-2
votes
1answer
57 views

How can I remove a file named beginning with `#`? [duplicate]

I have a file named #%2Amerge%2A#4984jjK#. # starts a comment in bash. So how can I remove the file? Thanks.
0
votes
2answers
73 views

keep N files in subdirectories

I'm trying to do something that looks pretty simple but I haven't been able to solve. I have a directory with a bunch of subdirectories all of them with multiple files (jpg files). I want to execute ...
21
votes
2answers
1k views

macOS rm command '-W' option - undelete

I was looking at the man page for the rm command on my MacBook and I noticed the the following: -W Attempt to undelete the named files. Currently, this option can only be used to recover ...
1
vote
2answers
8k views

rm: cannot remove `/../…v': Permission denied

I want to delete directory 982899. It is located under directory big. When I first try to delete 982899, it shows many lines of messages like this: rm: cannot remove `982899/.../...v': Permission ...
0
votes
2answers
3k views

bash delete folder while running a script

I have a script running in a folder. If a command fails I want to delete the folder the containing the script. Is that possible? Edit: Based on comment, I took out what I tried.
5
votes
2answers
3k views

corrupted directories, problem in deleting them

There is a directory in my Linux system because of some software malfunction some directories with junk name as you can see below is created, I have problem in deleting them, $ ll total 1532 drwxr-xr-...
-2
votes
4answers
4k views

Is it a good practice to delete all variables at the end of a script?

Is it good to delete the variables used in a shell-script at the end of a script. rm -rf $abc rm -rf $def or unset $abc unset $def and so on. Is this actually a good practice?
1
vote
1answer
4k views

How do I exclude a directory when searching for the directories that take up the most space?

I'm using Ubuntu 14.04. I want to figure out what directories are taking up the most space, so I'm running this command sudo du -a / | sort -n -r | head -n 100 The problem is, most of the ...
5
votes
2answers
1k views

Command that deletes all old files, folders and sub-folders

I need a command that deletes all files, folders and sub-folders that were not updated longer than 31 days. I tried this one find . -mindepth 1 -mtime +31 -exec rm -rf "{}" \; But if I have ...
3
votes
1answer
203 views

provide read, write, execute permission but can't be deleted by others

Is it possible for a user to create a folder with read, write, execute permission for all users in the system, but the other users can't delete the folder?
-3
votes
3answers
93 views

Ensure I am a in specific folder before calling rm [closed]

in my bash script, I have some very danger lines like : rm -r * if it is mis-run in some folder, it would be very disastrous.Basically, I would need to add an if condition to make this does not ...
5
votes
3answers
421 views

I have a file I cannot delete after a file mv operation was interrupted

I was moving a file with mv but the operation got interrupted. Now I am left with a file I cannot delete on an external NTFS drive. I was moving it from an ext4. rm file.to.delete rm: cannot remove ...
1
vote
3answers
2k views

delete oldest file in directory

I have a downloader running (in perl) that tries to execute a mv system command. The output from the mv mv: cannot move `./PMC5318673/EXCLI-15-758.pdf' to `/directory/EXCLI-15-758.pdf': No space ...
2
votes
1answer
110 views

How do I delete symlinks that's pointing to files in a certain folder?

I think this is best explain with an example: lrwxrwxrwx 1 root root 21 Mar 31 08:44 awk -> /etc/alternatives/awk* -rwxr-xr-x 1 root root 45K Apr 8 2015 b43-fwcutter* lrwxrwxrwx 1 ...
0
votes
2answers
5k views

Remove all .class files from folders in bash [duplicate]

I'm making a bash file to remove all .class files that java generates inside the src folder and it's subfolders. The structure is: project src /utils utils.class /game ...
2
votes
1answer
54 views

How to let user A delete B's file on behalf of B?

A and B are both non-root users in a same group. Suppose there will be some B owned garbage files generated inside a directory(also generated and owned by B) after a regression run by B, but I need A ...
1
vote
1answer
718 views

Cannot rm file because it doesn't exist?

I've encountered a really weird problem on a NAS volume I'm accessing on OS X. I have a PNG file that I tried to delete, but something went wrong and it still appears when I run ls or view the ...
0
votes
1answer
2k views

Getting “No such file or directory” when deleting directories with find

I'm using Amazon Linux. I have this statement that is designed to remove files in a directory /bin/find $JBOSS_HOME/standalone/tmp/vfs -mindepth 1 -mmin +1441 -exec rm -rf {} \; But this results in ...
1
vote
3answers
88 views

Why am I still getting prompted for a password after adding an exception to my /etc/sudoers file?

How do I give a user permission to use the rm command, but only within a certain directory? I tried adding this to my /etc/sudoers file myuser ALL = NOPASSWD : /bin/rm ???? /usr/java/jboss/...
1
vote
2answers
182 views

Deleting LARGE number of files (exec, loops..) [duplicate]

I have a very large number of files to delete, which go by the following format: esymac_logEvents.log.5_2017-Feb-06_02-39-17.Z_2017-Feb-08_02-39-14.Z_2017-Feb-09_02-39-14.Z_2017-Feb-11_02-39-11....
2
votes
1answer
2k views

Cannot remove directory, operation not supported on NTFS

I have an old Windows directory that I have not been able to remove using Windows processes so I moved to Slax Linux to try and remove it. When removing the directory I receive Cannot remove [...
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 ...