Removing Files & Directories
Shell·3 min read·Jan 1, 2025
⚠️ USAGE WARNING ⚠️
Unlike when using the graphical user interface, the action of removing files and directories from the command-line interface will not place the files you want to remove into the trash folder, but will immediately and irrevocably erase them from your system.
You should therefore use the following commands with extreme caution as there is no undelete command or other tricks to get your files back.
Once again, when deleting files and directories using the rm command, they are gone forever!
Removing regular files
To remove one or more regular files, you can use the rm command — which stands for remove — as follows:
$ rm file ...Where file ... are the paths to the files you want to remove.
Note: Upon successful removal, the
rmcommand doesn't produce any output to the terminal window.
Example
This command will remove the index.js file located in the current directory:
$ rm index.jsRemoving empty directories
To remove empty directories, you can use the rm command with the -d flag (short for directory) as follows:
$ rm -d directory ...Unlock the CLI & Scripting with Bash module
Learn how to gain advanced control over the OS and automate complex routine tasks prone to manual errors with the CLI and Bash scripting.
You get immediate access to:
- 34 focused lessons across the CLI and Bash
- 4 real-world projects with commented solutions
- Ongoing updates to this bundle
- Lifetime access to this bundle