Need description for a command to remove the contents of a folder without using ls or cd [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash 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 or cd?

  • why did the command I ran remove everything?






share|improve this 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 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














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 or cd?

  • why did the command I ran remove everything?






share|improve this 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 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












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 or cd?

  • why did the command I ran remove everything?






share|improve this question














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 or cd?

  • why did the command I ran remove everything?








share|improve this question













share|improve this question




share|improve this question








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 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












  • 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







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










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/*





share|improve this answer






















  • *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 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

















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/*





share|improve this answer






















  • *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 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














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/*





share|improve this answer






















  • *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 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












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/*





share|improve this answer














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/*






share|improve this answer














share|improve this answer



share|improve this answer








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 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
















  • *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 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















*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


Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay