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
1answer
56 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 ...
1
vote
1answer
42 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
274 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/ ...
0
votes
3answers
54 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 ...
3
votes
2answers
176 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 ...
0
votes
3answers
102 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 ...
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 ...
-1
votes
0answers
28 views

yum + is it safe to delete the _db files before yum update on Linux machines?

Sometimes we get yum errors because the _db* under /var/lib/rpm ls -ltr /var/lib/rpm/__db* -rw-r--r-- 1 root root 1318912 Apr 29 07:56 /var/lib/rpm/__db.003 -rw-r--r-- 1 root root 106496 Apr 29 07:...
2
votes
2answers
86 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 . '*....
0
votes
1answer
53 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 ...
1
vote
0answers
48 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
3answers
114 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 ...
1
vote
2answers
95 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
52 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 ...
2
votes
1answer
70 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 ...
0
votes
1answer
67 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 ...
2
votes
1answer
63 views

Stop systemd from cleaning my /tmp

Before the advent of systemd, my /tmp was cleaned when and only when I rebooted my machine. I was happy. Now systemd has changed this decades-old default so that my /tmp is cleaned every 24 hours, ...
2
votes
2answers
245 views

Why am I getting “Directory not empty” with “rm -rf”?

I'm using macOS with rm tool from GNU coreutils (not macOS’s own rm). So I have a script where I clean up some directory like this: if [ -d "${cleanup_repo_clone_root}" ]; then echo "Cleaning up ...
7
votes
2answers
537 views

Can't remove a file with file mode bits a+rw

I have a file with the following file mode bits (a+rw): [0] mypc<johndoe>:~>sudo touch /tmp/test [0] mypc<johndoe>:~>sudo chmod a+rw /tmp/test [0] mypc<johndoe>:~>ls -l ...
0
votes
0answers
38 views

cannot permanently delete Xcode.app in trash, not even if with “sudo rm -rf” because directory is not empty?

I run on osx 10.14, and I was trying to delete and reinstall xcode. I have also tried the following in safe mode but have the exact same problems. I moved xcode.app to trash, right clicked and chose ...
0
votes
0answers
32 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,...
2
votes
2answers
151 views

Is App: /bin/rm a Friend or Foe in OSX?

Bitdefender Antivirus for Mac keeps notifying me that it has blocked App:/bin/rm with the following message: An app you previously chose to block attempted to access your protected files again. We ...
3
votes
0answers
55 views

I can see but cannot delete a file [closed]

I am running Linux Mint.I tried to copy a file with the file manager. It looked like it hung. I can see the file in the directory with ls -l: -rwxr-xr-x 1 mike domain^users 20 Mar 1 08:57 'output (...
1
vote
1answer
32 views

remove files under specific folder

What is the diff between the following two approach ? find /calc -type f -delete find /calc -type f -exec rm -f {} + my target is to remove any jar file/s under calc folder any prefered of one of ...
1
vote
1answer
145 views

How to remove a file or folder from within the grub terminal?

I'm encountering problem with my dual-boot installation. I already experienced grub problems in the past, at that time I just deleted a folder (resulting from a faulty distrib install) in my EFI ...
12
votes
3answers
2k views

Why is “rm -r” unable to delete this folder?

I have a folder with -wx permissions called folder1 and another folder inside it called folder2 with rwx permissions. I tried to delete folder1 using this command: rm -r folder1 But I got the ...
0
votes
2answers
29 views

delete folder for all users on Mac

I'm using below command to delete folder rm -rf /Users/*/Library/Group\ Containers/UBF8T346G9.Office/User\ Content.localized/Templates.localized/ The command is working only for single user. I want ...
0
votes
0answers
38 views

remove program from local terminal

I tried to remove gfortran program from the local terminal windows by: rm -rf /usr/local/bin/gfortran but always I am facing the following : override rwxrwxr-x root/wheel for gfortran? I ...
1
vote
2answers
125 views

How to delete corrupted directory on Linux

I have a machine which has a directory that seems corrupt. The output of ls -lah is something like: ??????????? ? ? ? ? ? dir_name This used to be a valid directory in a ...
0
votes
3answers
146 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 do know how to pass a space with \ but I got the result: -bash: syntax error near ...
4
votes
0answers
53 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
720 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
67 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
301 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
37 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
120 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
48 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
967 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
712 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
vote
1answer
317 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
350 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
49 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
63 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
173 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-...
6
votes
3answers
797 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
37 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
800 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
39 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
173 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
361 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 ...