Questions tagged [delete]

262 questions
50
votes
6 answers

Delete all folders inside a folder except one with specific name

I need to delete all folders inside a folder using a daily script. The folder for that day needs to be left. Folder 'myfolder' has 3 sub folder: 'test1', 'test2' and 'test3' I need to delete all except 'test2'. I am trying to match exact name…
Riju Mahna
  • 633
  • 1
  • 5
  • 6
27
votes
1 answer

Get list of files deleted by `find -delete`

This command lists all the files match the provided name: find . -iname .DS_Store But when I use -delete parameter with it, I can't see the list of deleted files. They just get deleted. Preferably without making it complicated with | xarg .. or…
Emadpres
  • 372
  • 1
  • 3
  • 7
25
votes
1 answer

Unable to delete this file as root

I'm unable to delete a file with rm -rf /home/wordpress/testDomain.com from my Linux machine. Instead of the file being deleted, I get an Operation not permitted error. How can I fix this? $ cd…
manuel
  • 471
  • 5
  • 9
16
votes
4 answers

Delete a file called '.env'$'\r'

I have no idea what created this file - I guess a terrible shell script. It is called '.env'$'\r' I have tried various versions of rm, and the technique of opening the direcory with vim ./, selecting the file, and Shift-D to delete. This didn't…
10
votes
2 answers

How delete BILLIONS of files efficiently on linux?

A storage system had collected 1.7 billion files from revision backups over a couple of years and was getting a bit full. So I started to delete all files older than five years. Which I assume are around 1.7 billion (!!!) files with around 90 TByte…
9
votes
4 answers

How do I delete a directory that contains only '.' and '..', but rm says is not empty?

These two files are artefacts of Office 2011 that are preventing removal the 'Contents' directory. How do I delete these? sh-3.2# ls -l -a total 21496 drwx------+ 15 Beef staff 480 Jan 14 23:32 . drwxr-xr-x+ 19 Beef staff 608 Jan 14…
nightanimal
  • 171
  • 1
  • 1
  • 4
9
votes
1 answer

rsync with delete option, but preserve what's deleted

I want to rsync with the delete option so that the folders remain identical copies, also after I have deleted files and folders from the source. The problem is there might be something on the destination folder that isn't meant to be deleted. In…
john-jones
  • 1,698
  • 4
  • 24
  • 38
8
votes
6 answers

Delete all files within a directory, without deleting the directory

I have a directory called outer. outer contains a directory named inner (which contains lots of files of same extension) I cd to outer. How can I delete all the files within inner but leave the directory inner remaining (but empty)?
user997112
  • 985
  • 5
  • 14
  • 23
7
votes
3 answers

Delete files with names that appear to begin with '?' in command line

I am running under Debian stable, Cinnamon DE and I have some files that I would like to delete with a command line (for now I delete these files with Nemo). For example, these .txt files begin with '?' in the shell and in Nemo this '?' is replaced…
Smilia
  • 300
  • 3
  • 14
7
votes
2 answers

How to delete all except for some specific folder under parent-folder

So here's content under my /html folder. [root@ip-10-0-7-121 html]# ls a wp-activate.php wp-content wp-mail.php b wp-admin wp-cron.php wp-settings.php healthy.html wp-blog-header.php …
The One
  • 4,662
  • 11
  • 29
  • 35
7
votes
1 answer

What does mt -f /dev/st0 erase do exactly on a tape drive?

What does mt -f /dev/st0 erase do exactly with a (LTO-6) tape drive at /dev/st0? It takes hours and seems to write many times. Does it write random data on the tape several times to delete the contents in a secure way? Will it delete the magnetic…
Jonas Stein
  • 3,898
  • 4
  • 34
  • 55
6
votes
3 answers

Delete huge directory that causes all commands to hang

How do I delete this large directory? stat session/ File: ‘session/’ Size: 321540096 Blocks: 628040 IO Block: 4096 directory Device: 903h/2307d Inode: 11149319 Links: 2 Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid:…
Bojan Hrnkas
  • 201
  • 1
  • 6
6
votes
3 answers

sed/awk to remove double quotes " that are inside of curly braces {}

I have a csv file with data similar to this: "1b579a5e-9701-40eb-bd36-2bc65169da99","week14_Friday-019","6907eaad-1aff-4d26-9088-ba20374b67c0","2181-019","f20af5bb-c716-42e0-9b9d-cbolf5bfecea","15-BIO-2001","COLLEGE Bio…
6
votes
2 answers

How to delete a file with corrupt filename?

Somehow a program created a file with a broken filename which cannot be deleted anymore. Any attempt to delete the file results in "No such file or directory" as if the file isn't there. The problem seems to be a control character ASCII 2 in the…
theHacker
  • 181
  • 1
  • 5
5
votes
3 answers

Remove all files with particular name but different extensions at once

I have a directory where I have the following set of files:…
ecjb
  • 379
  • 3
  • 12
1
2 3
17 18