If the command finds content in one of the listed directories, it will skip it and move on to the next one.
#HOW TO RESTORE DELETED FILES IN LINUX HOW TO#
The basic syntax used for removing empty Linux folders/directories is: rmdir Īdditionally, you can delete multiple empty directories at once by typing: rmdir How to recover deleted files in linux Dear all, Accidently i have deleted the ram.conf file in the directory /opt and i want to recover the deleted file ram. If a specified directory is not empty, the output displays an error. Remember, the rmdir command is used only when deleting empty folders and directories in Linux. To remove a directory without confirmation: rm –rf directoryĪlso, you can delete more than one directory or folder at a time: rm –r dir_name1 dir_name2 dir_name3 Remove Directories in Linux with rmdir Command This will prompt you for confirmation before deleting. To remove a directory (and everything inside of it) use the –r option as in the command: rm –r dir_name rm command – removes a directory/folder along with all the files and sub-directories in itīy adding the -r (-R) option to the rm command, you can remove a directory along with all its contents.rmdir command – removes empty directories/folders.First, change directories to where the file was/is located - open a terminal (either on a linux desktop or ssh to one of login servers) and cd to that directory. To remove a directory in Linux , use one of the following two commands: These instructions describe how to restore a deleted or older copy of a file from your home directory on a Linux machine. To use sudo privileges for a file that says Access denied and delete it: sudo rm filename How to Delete a Directory in LinuxĪ linux directory (or folder) can be empty, or it can contain files. To force the removal of a file that’s write-protected, use the –f option: rm –f filename Or you can specify the file location in a single command directly: rm /tmp/filename To delete a file in a different directory, either switch to that directory first: cd /tmp rm filename The system will search the current directory for the file you want to remove. This will erase any file that has the word sample in the name. This method is also used to delete all files that contain a string of characters: rm *sample*.* The rm command can be used to delete more than one file at a time: rm filename_1 filename_2 filename_3įor example, to delete all files with the. To delete a single file, entering the following in the command line: rm filename The command unlinks the data from the file name, allowing the user to overwrite on that particular storage space. To learn how, visit our post How to Move Directories in Linux. Note: If you feel that a directory is misplaced and you do not want to remove it, try moving it to a different place.