Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Ki Bum Kim1,520 Points
What is the difference btw 'rm' and 'rm -r'?
I was following the video and got an curious about rm -r command. I tried to look for answers on online and found "-r' Reverse the order of the commands listed (with -l) or edited (with neither -l nor -s)." But I still didn't get it.
Chris Shaw26,663 Points
Hi Ki Bum Kim,
rm command which you would have learned stands for remove, by default if we just pass a file name to it we get asked if we're sure we want to delete it, however the same can't be said with folders as you can't delete an entire folder if it contains things inside of it.
This is were the
-r flag comes in, the
-r flag standard for recursive which means that when used in conjunction with
rm it removes all files and folders to the deepest level, however. This flag has one drawback and that is it still causes
rm to behave in the same manner as deleting one single file which means if you have 10 sub folders and 10 PDF's in each for example you'll be asked to remove them one-by-one.
Never fear though, if you know you won't need anything in the folder you're wishing to delete we can welcome in a second flag which is
-f, this stands for force which tells
rm not to invoke any CLI prompts asking before a file can be deleted. You will need to be careful when using
-f but if you feel comfortable with it you can use it like in the below example.
rm -rf FolderName
NOTE: When using unix commands chaining flags is optional, so instead of having
-f joined together you can space separate them but remember they need their own hyphens.
If you ever need more information about at this or other commands you can use the below for example which will look up details about the said command and return the manual data.
To exit the manual simply press q on your keyboard.
Hope that helps.