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]

Questions relating to the Linux remove command (rm)

0
votes
0answers
16 views

rm: cannot remove 'IRdata.tar.gz': Read-only file system

I tried to backup IRdata.tar.gz file from server lnxIR to virtual server lnx01/data2/ (both Linux OS). But the file was bigger than size on server lnx01/data2 and backup stopped and paused server. Now ...
22
votes
7answers
6k views

Why is it possible to delete your entire file system? [closed]

After committing the infamous mistake of deleting my entire file system via sudo rm -rf /*, recovering from the horrendous damage that I had done and coping with the fact that I just lost 6 years off ...
0
votes
1answer
39 views

Can I use a list of file names that I saved to file to have each file on the list copied/moved/deleted?

How can I use cp rm or mv commands to manipulate files saved to a list, for example one made like so: ls Downloads/ | grep example > example.tmp The point is to be able to view/edit the file list ...
2
votes
2answers
64 views

How to delete /dev folder that is accidentaly copied to external hdd?

I have accidentally copied the entire contents of root to my external hard drive because of using wrong syntax of cp. I have deleted the rest leaving /dev folder. Using rm results to "device busy" and ...
1
vote
0answers
23 views

Delete file with a likely name [duplicate]

I have a folder which contain .srt and .txt files inside /var/www/myvideo folder with filename like this: /var/www/myvideo/course1/module1/dasa22.en.srt /var/www/myvideo/course1/module1/dasa22.en....
1
vote
2answers
723 views

rm -rf does not work: 'Device or resource busy'

I'm using OpenVZ to create containers and it creates a folder for each container to store its files. I stopped the creation of a container before it gets completed, so it created a folder for that ...
0
votes
1answer
54 views

Bash delete file with two variable path not working

I have a bash script containing this code: path=/apps/files/ ext=*.csv rm -f $path$ext This is not working. When I set -o to echo each command I see this in the output... rm -f '*.csv' So it's ...
0
votes
2answers
45 views

delete all sub-directories recursively except several ones [duplicate]

The main_directory includes 0001 0102 0203 ... sub-directories. The sub-directories include lots of directories. I need to delete all sub-directories except several ones whose names are "abc", "bcd" ...
33
votes
10answers
5k views

Will ls always list the files that rm will remove?

Something I feel I ought to know for sure: if I ls <something>, will rm <something> remove exactly the same files that ls displayed? Are there any circumstances where rm could remove files ...
10
votes
2answers
468 views

Is quoting filenames enough security for running `xargs sudo rm -rf`?

I wrote a script that deletes all except the last two files in a folder: #!/bin/bash ls -1 --quoting-style=shell-always /path/to/some/folder \ | head -n -2 \ | xargs printf -- "'/path/to/some/...
0
votes
1answer
463 views

Unable to delete files and folders

I am trying to delete some regular files in my machine (external hard-disk). It will throw the below errors, rm: cannot remove 'Personal/Mobile': Input/output error rm: cannot remove 'Personal/...
1
vote
2answers
129 views

Delete directory

Sometimes I want to bang my head when it concerns understanding file permissions. I want to delete a dir called Test_Dir. andy is the owner. andy is in group. No files in directory have immutable ...
6
votes
3answers
1k views

How can I recursively find a directory by name and delete its contents (including all sub-directories and files) while keeping the directory itself?

Given: I have a tree structure with folders EmptyMe on different levels EmptyMe directories contain sub-directories and files Required: Empty contents of EmptyMe directories (inlcuding their sub-...
6
votes
2answers
271 views

How do I delete files of certain extension that don't have a given string in their filename?

I have a directory with files of many extensions in it. I would like to recursively delete *.srt files (and *.srt files only) which don't end with -en.srt (where srt is an extension). I've come up ...
0
votes
0answers
29 views

Automate Deletion of File from terminal

I want to write a Python script that will automate my commands without waiting for user input. My python script will delete the least played video. When I execute the command: rm video_123.mp4 it ...
0
votes
2answers
42 views

Delete 3 oldest files based on filename

I want to delete the 3 oldest files based on their filename. Here is an example of what is in my backup directory. There will be multiple copies with different times. Ubuntu_Scripts.zip_2018-08-09-...
-1
votes
1answer
33 views

Recovering the relative path option

Managed to delete the relative path option in linux by typing in rm .*, now I can't change or add files to any directory. How can these be recovered? Running a ls -a and the standard . and .. ...
3
votes
1answer
114 views

Is it possible to exclude some files from rm -rf? [duplicate]

I have a directory that I is filled by another user, and I'm tasked with maintaining it. I want to delete all its content except a 2 files with a specific name. Is it possible with rm or should I do ...
1
vote
1answer
1k views

Cannot delete .git directory

I try to run sudo rm -rf .git/ but the terminal return the following message: rm: cannot remove ‘.git/objects/pack/pack-3818f69fa7bd64ef22c94c0bf630c18333cd5da9.idx’: Operation not permitted rm: ...
1
vote
2answers
4k views

Deleting many files results in “argument list too long” [duplicate]

I have 280 thousand photos to delete in a folder, but some videos to keep. In the folder, I gave the command: #rm *.jpg, but I get "argument list too long". When I create an argument to delete some of ...
-3
votes
1answer
60 views

how to re-create the .Trash file in ubuntu server

I recently deleted the .Trash file in Ubuntu server using the command alias rm="mv -t ~/.Trash" and now I am unable to delete any file using rm command, and when I use it I get: mv: accessing `/...
5
votes
1answer
49 views

How to remove bad entry in home directory

My home directory looks like this: # ls -lt total 417656 drwxrwxr-x 2 ljohnson ljohnson 427577344 May 9 08:48 2z9TnVLzmf drwxr-xr-x 4 ljohnson ljohnson 4096 May 9 07:42 transmission drwxr-xr-x ...
2
votes
1answer
696 views

Folder recovery with rm command

I deleted /bin folder from computer in Ubuntu with rm command. How can recover it ?
1
vote
1answer
483 views

How to remove only files created before a specific date and time

l would like to remove from my directory files which have been created before 04/29/2018 at 4:00 pm. Thank you
3
votes
2answers
3k views

How do I set Cron to send emails?

I have the following cron job command running once daily on my NAS device: find /nfs/rpiggott/complete -mtime +45 -exec rm {} \; I am wondering if there is a way to pipe a list that will result in ...
0
votes
3answers
811 views

recursively delete subdirectories and files [duplicate]

I have the following files and directories configuration: -Parent_dir |-delme_dir |-delme_file |-aFile |-sub_dir |-delme_dir |-delme_file |-aFile |-...
6
votes
0answers
333 views

Why did an rm command executed from a pwd NOT / remove directories from it?

OK, so I've been doing different levels of sysadmin for almost a decade and yet I fell victim to an age old mistake; though I do not understand why it happened. I was in my server sorting through ...
0
votes
1answer
15 views

RM on an LUKS installation?

I am just wondering what will happen if you do sudo rm -rf / --no-preserve-root on an LUKS installation... Will the LUKS information be corrupted, rendering it useless (impossible to recover files) or ...
0
votes
0answers
128 views

When is it safe to delete the contents of /tmp and /var/tmp?

I'm trying to make a locked down, auto-restoring system that will restore itself once every week. I'm wondering if /tmp and /var/tmp can be safely removed if the system is booted on a different ...
1
vote
0answers
1k views

Hi guys, could you help me to solve my camera problem? [closed]

Basically I was trying to make my usb cam the default one and I followed this advice, and now I deleted my cam. Is there any way to restore it? I just used the first command, which was enough to make ...
1
vote
1answer
1k views

How to remove file/directory that “doesn't exist”? [duplicate]

I recently saw that I had two strangely named directories in my home folder. I tried to remove them but was unsuccessful. Here is a look at what I tried: theo@locker:~$ lh ls: cannot access ',...
0
votes
1answer
10k views

beleive it or not, I typed sudo rm -r * in / by mistake! anyway to undo [duplicate]

lol is there anything more to ask about it?! when I try "sudo bla bla bla" it asks me who are you? :)) I wanted to do it IN a folder in root, but I did it in only ne upper level which is, GOD, the ...
0
votes
0answers
38 views

Delete all but newest -img directory [duplicate]

I need help with a script that deletes all but the newest -img directories. Contents of /media/andy/MAXTOR_SDB2/ 01-16-18-img 2018-01-26-11-img Clonezilla_Images Family_Movies_AND_PICS lost+...
0
votes
1answer
539 views

hidden file removal on ubuntu

I have PDF files in a hierarchical directory stucture to 4 levels on my webserver. The files were uploaded from an OSX machine to a Windows Machine to my server. I now have many (dot) .filenames.pdf ...
0
votes
2answers
392 views

Started to delete /usr/share by mistake: what to do now?

In Ubuntu 16.04, I ran by mistake sudo rm -rf /usr/share. I know how stupid that is (I wanted to remove /usr/share/somefolder that had been installed as root and got distracted). I interrupted it ...
0
votes
0answers
2k views

sudo rm -r /usr/local and dash home causes the computer to freeze.

I did this mistake and now every time I click on unity dash I have a computer freeze. Help me, please. Thank you!
11
votes
2answers
368 views

Excluding certain files and directories when deleting files

My top-level directory is data. data includes several directories and these directories have sub-directories. I need to remove all files and directories inside data/ except several files in some ...
8
votes
1answer
1k views

“rm” command defaults “--preserve-root” option?

They say rm command defaults to the option --preserve-root. Is that right? Otherwise I should put the line alias rm='rm --preserve-root'` in ~/.bashrc to make that option happen without typing it ...
3
votes
1answer
84 views

Why does the SSH session not die after rm -rf /?

Just for fun, on a VPS I was about to terminate anyway, I ran sudo rm -rf / --no-preserve-root and after that all commands, including /bin/bash returned command not found, which makes sense as ...
0
votes
1answer
1k views

How do I erase the LUKS headers in terminal?

I am wondering if erasing the LUKS headers (primarily the one on the active booted partition/disk) is as simple as doing a sudo rm -rf / --no-preserve-root or if I'd need to do a different command. ...
0
votes
0answers
30 views

How to make the system display an image after RM on root?

Is there possibly a way to cause the system to display an image (from another partition, so that the image isn't deleted upon sudo rm -rf / --no-preserve-root) when the operating system can't be found?...
0
votes
0answers
311 views

How to trigger a terminal command when incorrect password entered…?

I am trying to make a line of secure operating systems with Ubuntu as the base OS, and I want to have an automated function that will erase the disk if certain triggers are met. Here is what I need (...
0
votes
1answer
751 views

How to remove a File from /usr/share/applications on Ubuntu 16.04 LTS

I tried to remove a file named "JDownloader 2 Update & Rescue" from /usr/share/applications directory but couldn't delete. This terminal command didn't work: sudo rm /usr/share/applications/...
3
votes
0answers
51 views

rm -r /media/externalHD --> can't boot without external HD anymore

My external HD was mounted in /media/user/TRANSFER. By mistake I typed sudo rm -r /media/theo/TRANSFER There was an error because the device was occupied and fortunately, I haven't lost my data. ...
2
votes
0answers
100 views

File appears in ls, but cannot be moved, opened, or deleted

I have a few files in a certain directory that appear in ls, but any attempts to delete, move, or open them direction (via terminal or GUI) are met with a "No such file or directory" error. Trying ...
2
votes
1answer
2k views

Removing folders older than 5 days

I have a backup folder than uses a calendar like folder structure to organise files. I want to delete these every 5 days but I end up deleting the full backup because the main folder is older than 5 ...
1
vote
3answers
216 views

Recursively remove same files found with locate

It seems this question has been asked in a number of ways. But I would like to use rm instead of find. I followed a number of explanations as to how to use find, but I'm having an issue with ...
4
votes
1answer
82 views

How do I recursively create a Textures directory in every existing directory in Bash and then delete them?

Lets say that I have the following structure: ./ ├── Dir1 ├── Dir2 │   ├── SubDir1 │   │   └── SubSubDir1 │   └── SubDir2 └── Dir3 └── SubDir1 Use this to make the test structure: mkdir -p ...
5
votes
2answers
1k views

rm -r versus rm -d?

I see a lot of resources on rm -r but almost nothing on rm -d even though the d flag is apparently all about deleting directories. What is the difference between the two exactly? Is rm -d the same as ...
0
votes
1answer
4k views

How do I delete folders found in /opt/? [duplicate]

I tried deleting a folder in my /opt/ file that I had created but got the message rm: cannot remove '/opt/*': Is a directory I created this folder, so why am I getting that message? Thanks again ...