Questions tagged [rm]
Questions relating to the Linux remove command (rm)
284
questions
4
votes
1
answer
3k
views
Difference between commands for removing empty directories
What is the difference between rm --dir <directory> and rmdir <directory> with respect to removing empty directories?
Also, if they are similar, is there any advantage of having an rmdir ...
4
votes
0
answers
2k
views
Recovering deleted files with rm -rf [duplicate]
I accidentally deleted a directory with
rm -rf /media/directory
When using
ls -lh /media
the space appears to be free, but when I use df or open the file manager nautilus or pantheon, it shows that ...
4
votes
2
answers
2k
views
How to prevent users from deleting files that are already in use?
Consider this scenario:
User is executing a command on a file. This file becomes 'in-use' now.
$ tail -f somefile.log
In another shell, user deletes the file.
$ rm somefile.log
Now, this file is '...
3
votes
4
answers
4k
views
What happens if we do rm -rf ../**? Can we restore the data?
I did something like:
$ cd /A/B/
$ rm -rf ./*
$ rm -rf ../**
Due to network issues my system disconnected from Ubuntu. When I came back there were no files or folders in the /A folder.
3
votes
2
answers
16k
views
Delete files older than 5 days as well as in all subfolders
I need to delete all files older than 5 days in all subfolders, but not the folders themselves. I know the command:
find /path/to/files* -mtime +5 -exec rm {} \;
But how can I tell Ubuntu to check ...
3
votes
5
answers
2k
views
Cannot delete Directory, doesn't exist?
Somehow this folder got created when i was logged in via sftp.
"Sep 19 18:50 "
I tried to delete it via sftp.
Tried to SSH in and delete with rm -rf as root
Error: rm /home/user/Downloads/manual/...
3
votes
4
answers
12k
views
How to delete all the files/folders from the folder except few folders?
Assume that I have a directory structure as follows:
application
│
├── config
│ ├── c1.conf
│ └── c2.conf
│
├── logs
│ ├── l1.txt
│ └── l2.txt
│
└── src
├── static
├── s1.py
└── ...
3
votes
3
answers
4k
views
Delete files within all directories in a directory
I recently needed to delete all the files within ~40 directories that were within a parent directory, without deleting the directories themselves. I ended up manually doing so, but is there a more ...
3
votes
1
answer
1k
views
How to delete only archives with a script
I would like to remove all of the archives (.tar, .zip, etc) on my system.
I know how to delete files using rm but I'm wondering if there is a command just for deleting the archives on my system (and ...
3
votes
3
answers
4k
views
trash: cannot trash regular file
I'm trying to avoid using rm so I don't delete anything permanently. I'm using the utility function trash, but it keeps telling me trash: cannot trash regular file. Why can't I delete these files? ...
3
votes
2
answers
754
views
rm if there's a file with same basename
Say I have the following files:
foo.coffee
foo.js
bar.js
Is there an easy way how to rm *.js if there's a corresponding .coffee file? In the example such a command would remove foo.js leaving:
foo....
3
votes
1
answer
1k
views
File wont delete from trash even after sudo rm -rf ~/.local/share/Trash/
I've tried using sudo rm -rf ~/.local/share/Trash/files/ and even going myself as root doing the same, and recreating the folder its still there, it was from a pendrive at one point and I deleted it ...
3
votes
3
answers
5k
views
remove pictures from folder
I want to remove all the photos from a folder and keep the remaining files.
I searched in the web and I found a tons of solutions like:
find . -type f -name "*.jpg" -delete
All the photos are jpeg, ...
3
votes
2
answers
5k
views
Is it safe to alias rm to safe-rm?
We are happy to use safe-rm as a replacement to rm, but is it considered safe to alias it?
e.g.
alias rm='safe-rm'
3
votes
1
answer
251
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 ...
3
votes
2
answers
4k
views
Accidentally removed /var folder
I did something real dumb. I was creating tarballs of files in my /var/ folder. The tarball i created was put into /tmp/test.tar
In the process of testing the extraction process, I meant to delete /...
3
votes
1
answer
62k
views
Restore Direcory/files after rm -rf [duplicate]
I've accidentally deleted a project directory from my Ubuntu with rm -rf.
is it possible to restore them somehow?
3
votes
2
answers
2k
views
How to remove a directory without a name?
ls -l output:
drwxr-xr-x 10 mnevile mnevile 4.0K Sep 9 15:45
drwxrwxr-x 18 mnevile mnevile 4.0K Jun 16 16:01 movies/
drwxrwxr-x 16 mnevile mnevile 4.0K Aug 19 10:52 music/
drwxrwxr-x 16 mnevile ...
3
votes
3
answers
1k
views
how do i make shell ask for confimation for rm -rf command (even sudo)?
I want to make the command shell to prompt me for confirmation before execution of certain commands like dd , rm -rf etc.
3
votes
2
answers
7k
views
Find folders of size lesser than x and delete them
I want to find all folders (within a folder) which are less than 100mb large and delete them. I actually don't want to use a bash script. But probably there is some neat one-line-loop possibility to ...
3
votes
3
answers
6k
views
How to wipe all contents from my user account?
I'm on 12.04 desktop and was wondering if the following command would remove all the data from my user home directory as well as my trash can:
rm -r /home/myUser/*
If so, can someone confirm that ...
3
votes
2
answers
6k
views
Cannot delete .Trash-503 directory, returns a $RECYCLE.BIN.trashinfo: Input/output error
I cannot delete .Trash-503 folder via GUI or terminal,
it returns a $RECYCLE.BIN.trashinfo: Input/output error
Not even sudo rm -r or even a simple ls works in that trash directory.
Check terminal ...
2
votes
3
answers
6k
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
|-...
2
votes
1
answer
2k
views
Remove except some files/directories in a script; need revision
I have the same problem as this question How to delete all the files/folders from the folder except few folders? several times.
This is the reason why I wanted to write myself a script for a command ...
2
votes
1
answer
2k
views
Home folder contents lost: wrong use of rm?
I am using Ubuntu-Mate 20.04 and I have lost most of the contents of my home folder. I think it could be due to using wrongly the “rm” command with sudo, but not sure if it might be something else.
I ...
2
votes
2
answers
17k
views
How to make a script delete a directory after checking for its existence?
How might one make a bash script which when run will check for the existence of a file/folder and if the file/folder is there remove it?
2
votes
2
answers
2k
views
Delete all files from within a directory that contain a specific word
I have navigated to a specific directory on the file system and wish to delete all files within the directory that contain 'sofa_' in their file name.
Can someone please suggest how this can be done?
2
votes
3
answers
6k
views
Giving cat output to rm
I have file names in a file which I need to delete in a different directory.
Let's say I have x and y files in dir a. How do I delete it using cat?
I tried,
rm -f a/{`cat a.txt`}
a.txt has ...
2
votes
4
answers
2k
views
Protection For rm
I sometimes work with my server over ssh. I don't want to lose anything because of an accidental rm. Is there a way of creating a trashbin for my server? I know it sounds stupid, but I just want to ...
2
votes
2
answers
1k
views
rm -i alias not working with sudo as root
I have noticed in all my Ubuntu servers the alias rm -i is ignored when you run sudo rm * as root. Is there something in sudo that is causing this behavior? I know you don't need to use sudo when you ...
2
votes
2
answers
2k
views
Terminal command to remove unknown file
What is the command to remove unknown file from terminal.
Edit after following answer: Example: I have two files يا مهدي- Times-يا محمد Events.html مهدي Events.html how do i only first file?
2
votes
1
answer
4k
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 ...
2
votes
1
answer
3k
views
Can a directory's mtime be older than that of file inside?
I have this very silly and very basic question but I thought better to ask before I start pruning my NAS.
I want to delete all directories in which all files are older than 30 days.
For files I ...
2
votes
2
answers
9k
views
"sudo rm" fails to delete files
My main account is called "u1204" and I have some files created with another account called "dad":
$ find . -user dad -print
./Documents/Zim Notes/.zim/state.conf
./Documents/Zim Notes (DAD)/.zim/...
2
votes
1
answer
96
views
I followed a solution procedure on AskUbuntu, logged out and now all my data is gone (no guest account)
I did the following to get Skype to recognise my headset microphone (which was not working), as shown as a solution on a question on this website:
rm -rf ~/.config/pulse/
Log out
Log back in
go to ...
2
votes
2
answers
496
views
Accidentally moved `/tmp` - replacements won't persist
I did sudo mv /tmp /var/lib/apt/lists not realizing that it would move the whole folder and not just the contents.
I since do (as suggested in Accidentally deleted tmp folder)
sudo mkdir -m 1777 /tmp
...
2
votes
2
answers
1k
views
glob expansion suddenly not working properly in loops
I am trying to run:
for i in *; do sudo rm $i; done
The problem is that there is something wrong with glob expansion and I get the error:
rm: cannot remove '*': No such file or directory
I get ...
2
votes
1
answer
15k
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: ...
2
votes
1
answer
2k
views
Folder recovery with rm command
I deleted /bin folder from computer in Ubuntu with rm command.
How can recover it ?
2
votes
2
answers
385
views
remove file with -h_some_file_name in shell [duplicate]
I have a problem when trying removing a file with name something like -h_some_file_name, this is because of generated script that I made and forget to check the prefix.
If I run the command rm '-...
2
votes
4
answers
2k
views
how to remove image files that are smaller than certain dimensions
I have already found an answer that lists pretty much everything. Except I cannot get it to work.
I use:
find . -iname "*.jpg" -type f | xargs -I{} identify -format '%w %h %i' {} | awk '$1<...
2
votes
2
answers
10k
views
How can I delete a corrupted directory? (`rm: cannot remove 'directory': Bad message`)
I am in a mounted VeraCrypt volume and have a corrupted directory that I wish to delete. When I attempt to rm the directory, I get a message like the following:
rm: cannot remove 'directory': Bad ...
2
votes
3
answers
154
views
how do delete file called \\.\pipe\FC_{6D57D5C3-9CEA-4497-BE57-9E544137A437}_1
I somehow got this file \.\pipe\FC_{6D57D5C3-9CEA-4497-BE57-9E544137A437}_1 on my home dir.
Tried deleting with rm and tab completion using the following prefixes:
./\
./\.
./\.\p
but it seems to ...
2
votes
1
answer
839
views
When moving a directory to another file system, and it runs out of space, are files removed?
Given /mnt/source/ and /mnt/target/ which are two different places / filesystems.
mv /mnt/source/dir /mnt/target/
It runs out of space part-way (and stops)
Imagining that /mnt/source/dir is full ...
2
votes
1
answer
271
views
dpkg is confused since I manually removed installation files for spotify with sudo rm recursive
So I was reading to learn on how packages and package installation works in Ubuntu in general and where do the files responsible for the existence of any application (installation files) reside in my ...
2
votes
1
answer
112
views
Remove list of files from different subfolders
I have a folder (call "folder"), composed of different subfolders ("subfolder1", "subfolder2",...). I would like to remove a list of files in all the subfolder of "folder", while some files are ...
2
votes
2
answers
2k
views
Find packages which files got deleted or missing after installation
I just accidentally did rm -r /var but luckily managed to ^C it before more damages were done. Is there way to find out all packages which files got deleted in the location so I can reinstall them?
% ...
2
votes
2
answers
1k
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 ...
2
votes
0
answers
862
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 ...
2
votes
0
answers
59
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.
...