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! While you're at it, check out some resources Treehouse students have shared here.
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 trialKi Bum Kim
1,520 PointsWhat 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.
1 Answer
Chris Shaw
26,676 PointsHi Ki Bum Kim,
The 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 -r
and -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.
man rm
To exit the manual simply press q on your keyboard.
Hope that helps.
brevans26
15,198 Pointsbrevans26
15,198 PointsPerfect!
Thanks!