![]() |
|
Beyond Finding Stuff with the Linux find Command - Printable Version +- Sick Gaming (https://sickgaming.net) +-- Forum: Computers (https://sickgaming.net/forum-86.html) +--- Forum: Linux, BSD & Unix (https://sickgaming.net/forum-88.html) +--- Thread: Beyond Finding Stuff with the Linux find Command (/thread-87303.html) |
Beyond Finding Stuff with the Linux find Command - xSicKxBot - 11-13-2018 Beyond Finding Stuff with the Linux find Command Continuing the quest to become a command-line power user, in this installment, we will be taking on the Code: findJack Wallen already covered the basics of Code: findCode: findDone? Good. Now, you need to know that Code: findCode: find path/to/some/directory/ -type f -iname '*.svg' -o -iname '*.pdf'This will cough up all the files with the extensions Code: svgCode: SVGCode: pdfCode: PDFCode: -oYou can also search in more than one directory simultaneously just be adding them to the route bit of the command. Say you want to see what is eating up all the space on your hard drive: Code: find $HOME /var /etc -size +500MThis will return all the files bigger than 500 Megabytes ( Code: -size +500MAdditionally, Code: findCode: -deleteCode: # WARNING: DO NOT TRY THIS AT $HOME find . -iname "*" -deleteCode: findCode: .Please do not put it to the test. Instead, let’s look at some more constructive examples… Moving Stuff Around Let’s say you have bunch of pictures of Tux the penguin in several formats and spread out over dozens of directories, all under your Documents/ folder. You want to bring them all together into one directory (Tux/) to create a gallery you can revel in: Code: find $HOME/Documents/ \( -iname "*tux*png" -o -iname "*tux*jpg" -o -iname "*tux*svg" \) -exec cp -v '{}' $HOME/Tux/ \;Let’s break this down: Once you have the basics of modifying files using Code: findA Terrible Mish-Mash Client X has sent you a zip file with important documents and images for the new website you are working on for them. You copy the zip into your ClientX folder (which already contains dozens of files and directories) and uncompress it with Code: unzip newwebmedia.zipYou could try and remember what the original files were and then move or delete the ones that came from the zip archive. But with dozens of entries of all kinds, you are bound to get mixed up at some point and forget to move a file, or, worse, delete one of your original files. Looking at the files’ dates ( Code: ls -la *You probably can guess what comes next: Code: findCode: cd path/to/ClientXCode: mkdir NewStuffCode: find . -cnewer newwebmedia.zip -exec mv '{}' NewStuff \;Breaking that down:
If you are unsure of anything Code: findCode: -execCode: -okCode: -okCode: findNext Time We’ll be looking at environmental variables and a way to search even more deeply into files with the Code: grep |