Need description for a command to remove the contents of a folder without using ls or cd [closed]
Clash Royale CLAN TAG#URR8PPP
up vote
-1
down vote
favorite
So, I have lost 70GB worth of data on my PC. I was trying to remove the contents of a folder named "Music". What I did was rm -rf ~/Music
and it removed everything including "Music" of course.
My questions are-
- what is the right way to remove the contents of a folder without using
ls
orcd
? - why did the command I ran remove everything?
fedora
closed as unclear what you're asking by Ulrich Schwarz, Romeo Ninov, G-Man, Fox, Anthony Geoghegan Dec 23 '17 at 17:02
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |Â
up vote
-1
down vote
favorite
So, I have lost 70GB worth of data on my PC. I was trying to remove the contents of a folder named "Music". What I did was rm -rf ~/Music
and it removed everything including "Music" of course.
My questions are-
- what is the right way to remove the contents of a folder without using
ls
orcd
? - why did the command I ran remove everything?
fedora
closed as unclear what you're asking by Ulrich Schwarz, Romeo Ninov, G-Man, Fox, Anthony Geoghegan Dec 23 '17 at 17:02
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
6
This question is unclear. You ranrm -rf
to remove yourMusic
; you want to know a better way to remove the contents of some folder, but at the same time you didn't intend to lose the (70 GB) of content in that folder. ??
â user4556274
Dec 23 '17 at 14:06
add a comment |Â
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
So, I have lost 70GB worth of data on my PC. I was trying to remove the contents of a folder named "Music". What I did was rm -rf ~/Music
and it removed everything including "Music" of course.
My questions are-
- what is the right way to remove the contents of a folder without using
ls
orcd
? - why did the command I ran remove everything?
fedora
So, I have lost 70GB worth of data on my PC. I was trying to remove the contents of a folder named "Music". What I did was rm -rf ~/Music
and it removed everything including "Music" of course.
My questions are-
- what is the right way to remove the contents of a folder without using
ls
orcd
? - why did the command I ran remove everything?
fedora
edited Dec 23 '17 at 15:09
roaima
39.8k545108
39.8k545108
asked Dec 23 '17 at 13:52
user512499
11
11
closed as unclear what you're asking by Ulrich Schwarz, Romeo Ninov, G-Man, Fox, Anthony Geoghegan Dec 23 '17 at 17:02
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by Ulrich Schwarz, Romeo Ninov, G-Man, Fox, Anthony Geoghegan Dec 23 '17 at 17:02
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
6
This question is unclear. You ranrm -rf
to remove yourMusic
; you want to know a better way to remove the contents of some folder, but at the same time you didn't intend to lose the (70 GB) of content in that folder. ??
â user4556274
Dec 23 '17 at 14:06
add a comment |Â
6
This question is unclear. You ranrm -rf
to remove yourMusic
; you want to know a better way to remove the contents of some folder, but at the same time you didn't intend to lose the (70 GB) of content in that folder. ??
â user4556274
Dec 23 '17 at 14:06
6
6
This question is unclear. You ran
rm -rf
to remove your Music
; you want to know a better way to remove the contents of some folder, but at the same time you didn't intend to lose the (70 GB) of content in that folder. ??â user4556274
Dec 23 '17 at 14:06
This question is unclear. You ran
rm -rf
to remove your Music
; you want to know a better way to remove the contents of some folder, but at the same time you didn't intend to lose the (70 GB) of content in that folder. ??â user4556274
Dec 23 '17 at 14:06
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
When you ran:
rm -rf ~/Music
you told rm
to -f
forcibly remove the Music directory and -r
recursively remove any directories within it.
If you want to just remove the contents of ~/Music
but leave the directory itself intact, you should run:
rm -r -- ~/Music/*
The ~/Music/*
will expand to all of the files and directories inside ~/Music
without including the Music directory itself.
If you also want to leave the subdirectories of ~/Music
alone, you should drop the -r
switch so:
rm -- ~/Music/*
*Note: This will still remove all your Music, but it will preserve the(now empty) Folder~/Music
.
â rudib
Dec 23 '17 at 14:01
@rudib, that is what OP asked for right?
â Jesse_b
Dec 23 '17 at 14:04
1
Yes it is, I just thought I might clarify, as he mentioned a significant dataloss (that would still occur when running this command).
â rudib
Dec 23 '17 at 14:06
1
Just a side note; don't use-f
unless you absolutely have to. It's like dropping a bomb on a spider. The collateral damage potential is very high.
â Mioriin
Dec 25 '17 at 19:31
1
@multithr3at3d, it's probably unnecessary in this command since a path is specified but I think it's good habit whenever usingrm
or many other commands with switches that can be destructive. It says that no more switches can follow. If you had files in a folder named-r
for example and then didrm *
(I don't know why people do this) in it, it would actually executerm -r *
.rm -- *
will prevent that.
â Jesse_b
Dec 25 '17 at 23:07
 |Â
show 2 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
When you ran:
rm -rf ~/Music
you told rm
to -f
forcibly remove the Music directory and -r
recursively remove any directories within it.
If you want to just remove the contents of ~/Music
but leave the directory itself intact, you should run:
rm -r -- ~/Music/*
The ~/Music/*
will expand to all of the files and directories inside ~/Music
without including the Music directory itself.
If you also want to leave the subdirectories of ~/Music
alone, you should drop the -r
switch so:
rm -- ~/Music/*
*Note: This will still remove all your Music, but it will preserve the(now empty) Folder~/Music
.
â rudib
Dec 23 '17 at 14:01
@rudib, that is what OP asked for right?
â Jesse_b
Dec 23 '17 at 14:04
1
Yes it is, I just thought I might clarify, as he mentioned a significant dataloss (that would still occur when running this command).
â rudib
Dec 23 '17 at 14:06
1
Just a side note; don't use-f
unless you absolutely have to. It's like dropping a bomb on a spider. The collateral damage potential is very high.
â Mioriin
Dec 25 '17 at 19:31
1
@multithr3at3d, it's probably unnecessary in this command since a path is specified but I think it's good habit whenever usingrm
or many other commands with switches that can be destructive. It says that no more switches can follow. If you had files in a folder named-r
for example and then didrm *
(I don't know why people do this) in it, it would actually executerm -r *
.rm -- *
will prevent that.
â Jesse_b
Dec 25 '17 at 23:07
 |Â
show 2 more comments
up vote
1
down vote
accepted
When you ran:
rm -rf ~/Music
you told rm
to -f
forcibly remove the Music directory and -r
recursively remove any directories within it.
If you want to just remove the contents of ~/Music
but leave the directory itself intact, you should run:
rm -r -- ~/Music/*
The ~/Music/*
will expand to all of the files and directories inside ~/Music
without including the Music directory itself.
If you also want to leave the subdirectories of ~/Music
alone, you should drop the -r
switch so:
rm -- ~/Music/*
*Note: This will still remove all your Music, but it will preserve the(now empty) Folder~/Music
.
â rudib
Dec 23 '17 at 14:01
@rudib, that is what OP asked for right?
â Jesse_b
Dec 23 '17 at 14:04
1
Yes it is, I just thought I might clarify, as he mentioned a significant dataloss (that would still occur when running this command).
â rudib
Dec 23 '17 at 14:06
1
Just a side note; don't use-f
unless you absolutely have to. It's like dropping a bomb on a spider. The collateral damage potential is very high.
â Mioriin
Dec 25 '17 at 19:31
1
@multithr3at3d, it's probably unnecessary in this command since a path is specified but I think it's good habit whenever usingrm
or many other commands with switches that can be destructive. It says that no more switches can follow. If you had files in a folder named-r
for example and then didrm *
(I don't know why people do this) in it, it would actually executerm -r *
.rm -- *
will prevent that.
â Jesse_b
Dec 25 '17 at 23:07
 |Â
show 2 more comments
up vote
1
down vote
accepted
up vote
1
down vote
accepted
When you ran:
rm -rf ~/Music
you told rm
to -f
forcibly remove the Music directory and -r
recursively remove any directories within it.
If you want to just remove the contents of ~/Music
but leave the directory itself intact, you should run:
rm -r -- ~/Music/*
The ~/Music/*
will expand to all of the files and directories inside ~/Music
without including the Music directory itself.
If you also want to leave the subdirectories of ~/Music
alone, you should drop the -r
switch so:
rm -- ~/Music/*
When you ran:
rm -rf ~/Music
you told rm
to -f
forcibly remove the Music directory and -r
recursively remove any directories within it.
If you want to just remove the contents of ~/Music
but leave the directory itself intact, you should run:
rm -r -- ~/Music/*
The ~/Music/*
will expand to all of the files and directories inside ~/Music
without including the Music directory itself.
If you also want to leave the subdirectories of ~/Music
alone, you should drop the -r
switch so:
rm -- ~/Music/*
edited Dec 25 '17 at 20:08
answered Dec 23 '17 at 14:00
Jesse_b
10.5k22659
10.5k22659
*Note: This will still remove all your Music, but it will preserve the(now empty) Folder~/Music
.
â rudib
Dec 23 '17 at 14:01
@rudib, that is what OP asked for right?
â Jesse_b
Dec 23 '17 at 14:04
1
Yes it is, I just thought I might clarify, as he mentioned a significant dataloss (that would still occur when running this command).
â rudib
Dec 23 '17 at 14:06
1
Just a side note; don't use-f
unless you absolutely have to. It's like dropping a bomb on a spider. The collateral damage potential is very high.
â Mioriin
Dec 25 '17 at 19:31
1
@multithr3at3d, it's probably unnecessary in this command since a path is specified but I think it's good habit whenever usingrm
or many other commands with switches that can be destructive. It says that no more switches can follow. If you had files in a folder named-r
for example and then didrm *
(I don't know why people do this) in it, it would actually executerm -r *
.rm -- *
will prevent that.
â Jesse_b
Dec 25 '17 at 23:07
 |Â
show 2 more comments
*Note: This will still remove all your Music, but it will preserve the(now empty) Folder~/Music
.
â rudib
Dec 23 '17 at 14:01
@rudib, that is what OP asked for right?
â Jesse_b
Dec 23 '17 at 14:04
1
Yes it is, I just thought I might clarify, as he mentioned a significant dataloss (that would still occur when running this command).
â rudib
Dec 23 '17 at 14:06
1
Just a side note; don't use-f
unless you absolutely have to. It's like dropping a bomb on a spider. The collateral damage potential is very high.
â Mioriin
Dec 25 '17 at 19:31
1
@multithr3at3d, it's probably unnecessary in this command since a path is specified but I think it's good habit whenever usingrm
or many other commands with switches that can be destructive. It says that no more switches can follow. If you had files in a folder named-r
for example and then didrm *
(I don't know why people do this) in it, it would actually executerm -r *
.rm -- *
will prevent that.
â Jesse_b
Dec 25 '17 at 23:07
*Note: This will still remove all your Music, but it will preserve the(now empty) Folder
~/Music
.â rudib
Dec 23 '17 at 14:01
*Note: This will still remove all your Music, but it will preserve the(now empty) Folder
~/Music
.â rudib
Dec 23 '17 at 14:01
@rudib, that is what OP asked for right?
â Jesse_b
Dec 23 '17 at 14:04
@rudib, that is what OP asked for right?
â Jesse_b
Dec 23 '17 at 14:04
1
1
Yes it is, I just thought I might clarify, as he mentioned a significant dataloss (that would still occur when running this command).
â rudib
Dec 23 '17 at 14:06
Yes it is, I just thought I might clarify, as he mentioned a significant dataloss (that would still occur when running this command).
â rudib
Dec 23 '17 at 14:06
1
1
Just a side note; don't use
-f
unless you absolutely have to. It's like dropping a bomb on a spider. The collateral damage potential is very high.â Mioriin
Dec 25 '17 at 19:31
Just a side note; don't use
-f
unless you absolutely have to. It's like dropping a bomb on a spider. The collateral damage potential is very high.â Mioriin
Dec 25 '17 at 19:31
1
1
@multithr3at3d, it's probably unnecessary in this command since a path is specified but I think it's good habit whenever using
rm
or many other commands with switches that can be destructive. It says that no more switches can follow. If you had files in a folder named -r
for example and then did rm *
(I don't know why people do this) in it, it would actually execute rm -r *
. rm -- *
will prevent that.â Jesse_b
Dec 25 '17 at 23:07
@multithr3at3d, it's probably unnecessary in this command since a path is specified but I think it's good habit whenever using
rm
or many other commands with switches that can be destructive. It says that no more switches can follow. If you had files in a folder named -r
for example and then did rm *
(I don't know why people do this) in it, it would actually execute rm -r *
. rm -- *
will prevent that.â Jesse_b
Dec 25 '17 at 23:07
 |Â
show 2 more comments
6
This question is unclear. You ran
rm -rf
to remove yourMusic
; you want to know a better way to remove the contents of some folder, but at the same time you didn't intend to lose the (70 GB) of content in that folder. ??â user4556274
Dec 23 '17 at 14:06