rw-r-r- 1 sk users 0 Mar 22 15:51 file9.docĪs you in the above output, I have four different type of files (pdf, txt, mp3, doc) in the test folder. Let us say our test folder contains three. pdf etc.? It's also easy to keep particular type of files in a folder and delete everything else. What would you do if the folder has different type of files like. ! -name file10.txt -deleteĪs you see in the above example, the test folder contains same type of files i.e. The following command will delete all files in the current folder (i.e test in our case) except file10.txt. You can also use find command to delete everything but specific one. The above command will delete all files in the test folder except file10.txt file. But these are the five commands that I am aware of.Īnd run the following command: $ rm -f !(file10.txt) Now, I want to delete everything in this folder except file10.txt. You can remove a directory with the rmdir command.Sample output: file10.txt file2.txt file4.txt file6.txt file8.txtįile1.txt file3.txt file5.txt file7.txt file9.txt You can’t just rm a directory by default, you’ll need to add the -r flag (recursive) to remove all the files and any subdirectories it may have. f or force option tells rm to remove all files, whether they are write protected or not, without prompting the user (as long as you have the appropriate permissions).Īdding the -i flag like many of the other commands, will give you a prompt on whether you want to actually remove the files or directories. Now if you don’t care about any of that, you can absolutely remove a bunch of files. If a directory is write-protected it will also not be easily removed. Write-protected files will prompt you for confirmation before deleting them. Once they are gone, they are gone for good, so be careful.įortunately there are some safety measures put into place, so the average joe can’t just remove a bunch of important files. Take caution when using rm, there is no magical trash can that you can fish out removed files. The rm (remove) command is used to delete files and directories. To remove files you can use the rm command. Now I think we have too many files, let’s remove some files.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |