Wednesday, May 1, 2024
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 651  / 2 Years ago, fri, september 2, 2022, 7:49:00

I've been using Ubuntu server at home for a while now, and I've noticed I've some holes in my knowledge of bash and in general several dangerous tools like rm.



It is first time in my life I used rm to delete something I didn't intend to...



pwd: /media/storage/vod

ls: css html series music movies



sudo rm *.QTFS
sudo rm -rf *.QTFS


What is the difference between these two above? I've filename specified. So will recursion look within all sub directories for *.QTFS or just inside current dir (vod)? I imagine later... so in this case recursion flag doesn't do anything, correct?



sudo rm -R *.QTFS series/*


This was my undoing command. Anyhow, so in this case I just gave rm two separate delete commands, correct?



first delete recursively *.QTFS, but this part only looks inside current dir (vod).
Second deletes recursively contents of series directory.



In essence I'm trying to understand if I deleted something beyond obvious damage.


More From » command-line

 Answers
0

Both -r and -R are aliases for --recursive, which the manpage describes as:




remove directories and their contents recursively




If you do rm -r file1 file2, the option is passed to both files. Since the recursion only applies to directories (you can't recursively act on a single level), this would do little more than delete both files.



If you do rm -r folder1 folder2, it will recursively delete everything within those folders and the folders themselves.



As far as how filename expansion aka globbing works, * means any number of characters, so *.QTFS means any file in $PWD ending with .QTFS and service/* means any file within the $PWD/service folder.



That being said, as long as that's what you wanted to delete, you should be fine.



Use -i or --interactive to force rm to ask for confirmation at every removal, or -I or --interactive=once to ask once if your command would remove four or more files, or would recursively remove files.



Use -f or --force to cause rm to silently ignore non-existent files, and to not prompt for confirmation before removing a read-only file or directory.



You might want to look into trash if you want an undelete command of sorts. It interacts with the trashcan, giving you the option to have a fallback if need be.


[#23387] Saturday, September 3, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
uffno

Total Points: 283
Total Questions: 93
Total Answers: 111

Location: Saint Vincent and the Grenadines
Member since Thu, Oct 15, 2020
4 Years ago
uffno questions
Thu, Sep 2, 21, 18:08, 3 Years ago
Sun, Apr 2, 23, 15:15, 1 Year ago
Sat, Jan 8, 22, 16:37, 2 Years ago
;