DEV Community

Cover image for Be Carefull With rm!
GiorgiKeburia
GiorgiKeburia

Posted on

Be Carefull With rm!

πŸ“£ The world is amazing ,but Not so ideal as we think!πŸ€”

πŸ’‘ Unix-like operating systems such as Linux do not have an undelete command.

When we delete something with rm , it's gone.Linux assumes we're smart and we know what we're doing.

Giff

One of the big problem can cause wildcards. so be particularly with them.

For Example : if we want to delete just the JS files in directory we type:
rm *.js
Of course this is correct , but if we accidentally place a space between the * and the .js like so:
rm * .js
what happens? πŸ€”πŸ§
the rm command will delete al the files in the directory and only then complain that there is no file called .js

There is many ways to avoid this problem, here is 2 useful tip:
1 - use -i (interactive) option, which prompt the user for confirmation ,before deleting an existing file.

rm i *.js
asks -> rm: remove regular empty file 'mk.js'?
2 - whenever we use wildcards with rm, test the wildcard first with ls. This will let we see the files that will be deleted. Then we can press the up arrow ☝️ to recall the command and replace ls with rm.

Top comments (0)