Questions tagged [rm]

rm is the command to remove files

Filter by
Sorted by
Tagged with
1
vote
1answer
777 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
89 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
191 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....
3
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
2k 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 ...
8
votes
1answer
7k views

How to force creation of a symbolic link?

I have a particular directory full of other directories organized (named) by date. For ease of reference, I have a symlink called current pointing to the latest one. In the script that creates new ...
1
vote
2answers
133 views

Delete file if symlink is gone

I have tvheadend running on my RPi, and although it stores recordings locally, when the disk gets to 80% full it moves them over to an SSHfs filestore and symlinks to the new location. I'm looking ...
1
vote
1answer
372 views

What methods for overwrite protection and accidental removing are there?

Apart of unix perms are there other protection for don't remove or overwrite files? By example: Restringing dirs than rm can delete. Overwrite protection when I made cat >file instead of cat >>file ...
0
votes
1answer
175 views

find and rm -rf, why it prints errors? [duplicate]

I'm definitely doing something wrong but can't figure this one out. When I run rm -rf on directories through find I get a No such file or directory but it does not happen when I do it manually. ...
8
votes
1answer
4k views

Can not delete file due to “Invalid argument”

I got this weird error when I try to delete some file. And the filename doesn't contain any specific characters. Does anyone know why ? It is centos [root@sandbox ~]# rm -rf /var/log/zookeeper rm: ...
1
vote
4answers
85 views

Is it possible to delete a directory in constant time?

I usually remove an entire directory at once with rm -rf. I noticed just now that this takes longer the larger the directory is (reckoned recursively). Do unix-like systems expose an alternative way ...
0
votes
3answers
85 views

Delete large amount of directories under a top level

I have a directory full of several other directories with the same structure, so it looks like this top/A/Output/platform/.. top/B/Output/platform/.. top/C/Output/platform/.. and so on. I want to, ...
6
votes
5answers
6k views

How to remove a file without using rm? [closed]

The third party scheduling application our enterprise uses doesn't execute rm commands as expected. By this, I mean I expect the rm -f $filetoremove to complete and then continue to the next line of ...
2
votes
1answer
86 views

Why is the command rm called when the system starts up

My PC is Mac pro. I removed x for rm in case of delete files by accident: sudo chmod o-x /bin/rm However, when I reboot my PC, I got one message on the terminal: -bash: /bin/rm: Permission denied ...
3
votes
1answer
5k views

How to delete a file named --help? [duplicate]

By mistake I created a file named --help trying to get help about the command > > --help If i try to delete the file like this: rm --help the help about the command rm is shown.
1
vote
0answers
1k views

Delete oldest file with a shell script on FTP server

I would like to create a cron job for deleting the oldest file in a directory which is on FTP server. I have created my first shell script #!/bin/sh # connect to backup FTP server... lftp -u (...
0
votes
3answers
1k views

How to Delete All the Files in the Current Directory Except the Last Two [duplicate]

Let's say there are 10 files in this current directory /home/usr. They are numbered 1-10. If I wanted to delete all the files except 9 and 10, how would I go about it? I can select the bottom two ...
2
votes
1answer
515 views

How to remove files and folders underneath a specific folder

As we know, to remove files we can use this safe option find /path/to/directory/ -mindepth 1 -mtime +5 -delete What if we want to remove both folders and files under /path/to/directory/ folder; ...
3
votes
1answer
140 views

mac terminal - how to make a directory require SUDO access to delete it?

I have a directory called "development" and I want to set its permissions I guess, in a way that if someone where to run rm -rf development it would prompt for sudo access or just deny the command, ...
3
votes
3answers
642 views

How to ignore empty directories when using `rm` with wildcards for multiple directories in zsh?

When I try to delete all files from two or more subdirectories in zsh, and a directory is already empty, the following directories are ignored, and files remain. Example: $ mkdir dir1 $ mkdir dir2 $ ...
0
votes
1answer
272 views

Cleaning out mail folders with cron task

SpamAssassin has a feature to "learn" spam. Each user has a .spam folder in their mail folder and they will be instructed to move any spam into that folder. (Users are using IMAP.) I have set up a ...
14
votes
3answers
14k views

How to exclude some files from filename expansion mechanism in bash?

I have ubuntu file system directories in the root directory and I accidentally copied hundreds of files into root directory. I intuitively tried to remove copied files by excluding file system like ...
0
votes
2answers
3k views

I deleted my home directory… can I recover it? [duplicate]

So I wanted to clean a directory and subdirectories from non .doc|.docx files and I ran the following command: rm -rf /home/user/dir/dir1/dir11/ !(*.doc|*.docx) and I just deleted my home directory (...
20
votes
5answers
61k views

Cannot remove file: “Structure needs cleaning”

I have an external hard drive which is encrypted via LUKS. It contains an ext4 fs. I just got an error from rsync for a file which is located on this drive: rsync: readlink_stat("/home/some/dir/...
1
vote
1answer
1k 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 ...
4
votes
2answers
3k views

Two files in same folder with same name - need to delete one but not both

We appear to have two files in the /var/spool/lp/logs folder named "requests". One is owned by lp, the other by root. We need to remove the requests file owned by root - how do we reference it? ...
0
votes
2answers
463 views

Does “rm -rf $dir” ever return false?

I've written the following line of code to delete the contents of a directory. rm -rf $dir && mkdir -p $dir However, this will not work if the first statement failed. Does it ever return 1?
0
votes
1answer
1k views

find + delete files that contain “.”

I need to remove all the files under /tmp that contain the "." or dot character so I created the following find /tmp -name "*.*" -delete please advice if this is the best approach to remove the ...
0
votes
1answer
56 views

Cleanup tar command

I did via SSH: tar xvfz t10k-images-idx3-ubyte.gz instead of gunzip. And now: gsamaras:~/Desktop/Data$ ls $_?????) ???= Klein siftsmall Sphere ??? gist MNIST ...
36
votes
6answers
14k views

Deleting billions of files from a directory while seeing the progress as well

I have a directory of 30 TB having billions of files in it which are formally all JPEG files. I am deleting each folder of files like this: sudo rm -rf bolands-mills-mhcptz This command just runs ...
0
votes
4answers
498 views

How do I delete files on my USB stick and dismount it?

I was trying to make a bootable Ubuntu stick. However, even though the stick could easily handle the ISO size, in the writing the size of the 2GB stick was exceeded. Now I want to clear off the ...
4
votes
3answers
15k views

rm command in bash script does not work with variable

I am doing a bash script to create a back-up of my mysql databases. Actually, I would like to delete the old ones. So, I create my script with variable for maintability. The whole script is actually ...
1
vote
3answers
59 views

How to remove directories in the correct order so that empty ones are removed?

I have a list of files & directories in a file in some order, and I want to write a script that removes them. Directories are only supposed to be removed if all of their descendents will also be ...
1
vote
1answer
655 views

How can you move a file as a background job and delete all other files and the directory before waiting for the job to finish?

I downloaded a directory of files, directory.1 containing the files file.1 file.2 file.3 I move file.2 by mv file.2 ../another.directory & My problem is I want to get rid of directory.1 and ...
22
votes
5answers
1k views

Why doesn't find . -delete delete current directory?

I would expect find . -delete to delete the current directory, but it doesn't. Why not?
0
votes
2answers
38 views

Weird entry on my home dir

I'm on Debian 8, and for some reason, when I do ls on my home dir, the following line appears: -rw-r--r-- 1 elade develop5 0 Nov 10 12:28 ?0?@@X?@8?@!???@@@@@?????????@?@?????@@???? I can't seem ...
0
votes
1answer
390 views

Remove a lot of cache files [duplicate]

There are over 1m+ cache files in one directory on a server. I would need to remove them, but of course rm first lists file and then starts to remove them. That cause a high spike in a server CPU load ...
-1
votes
2answers
120 views

bash: Deleting directories not containing given strings

How can I delete directories using the bash that do not contain directories named wav or mp3? I use macOS Sierra. find . -type d \! -exec test -e '{}/wav' \; -print finds the directories not ...
0
votes
1answer
765 views

How to touch, rm and touch in Unix? [duplicate]

I want to empty current file so I do: touch it, remove it and touch because I do not want to remove non-existing file; example touch "$filenameTarget" rm "$filenameTarget" ...
1
vote
0answers
179 views

Find directory containing file; execute command in that dir; then delete files

I want to find all directories (recursively) which contain .cue files, execute a command in that directory, then delete all files in that directory with the same prefix as the .cue file. find . -name ...
0
votes
2answers
2k views

Delete multiple patterns of files using one command (find)

I am trying to find and delete files in current directory and subdirectories (recursively) which match different patterns and print the matching files to stdout to know which ones are deleted. For ...
3
votes
1answer
596 views

Effect of killing a long running rm command

Today I deleted a 50gb file stored on an ext3 filesystem using the rm command. It took rm almost 40 minutes of intense I/Os to release all the blocks. From what I see from other sources, that's the ...
1
vote
0answers
45 views

Find files inside sub-directories with different names (to remove them with mtime)

I have a set of client folders on a server. Each client has backups inside a "backup" directory like so; ~/backups/<CLIENT_NAME>/{daily, weekly, monthly}/{databases, directories, logs} I'd ...
1
vote
1answer
137 views

Remove a file named '

I accidentally created a file named '. Is there a simple way to delete this in bash? Unfortunately, there is already default behavior for rm '.
-3
votes
1answer
5k views

Delete folder if it exists [closed]

I need to delete folder, subfolders and files if it exists. I am trying to do the following: if [ ! -d folder ]; then rm -rf folder; fi However it doen't work. How can I accomplish this?
0
votes
1answer
214 views

Sys files removed (rm -rf /*) help

Today I made a mistake by running: rm -rf /* 0200:00/power/control': Operation not permitted rm: cannot remove /sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A03:00/device:01/PNP0200:00/power/...
1
vote
5answers
154 views

Deleting some of the largest files in a directory

I would like to delete a certain number of the largest files in a directory. I can get the filenames of the first ten with: ls -S | head (or a richer albeit more complex to parse ls -lS | head) How ...
-2
votes
1answer
440 views

delete recursive subfolders with find

I need to delete recursive subfolders in a single line For one subfolder: find folder -name "subfolder" -exec rm -r "{}" \; or find folder -name "subfolder" -type d -exec rm -r "{}" \; But in the ...
29
votes
4answers
3k views

How to unlink (remove) the special hardlink “.” created for a folder?

On Linux, when you a create folder, it automatically creates two hard links to the corresponding inode. One which is the folder you asked to create, the other being the . special folder this folder. ...