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 find command.

Jack Wallen already covered the basics of find in an article published recently here on If you are completely unfamiliar with find, please read that article first to come to grips with the essentials.

Done? Good. Now, you need to know that find can be used to do much more than just for search for something, in fact you can use it to search for two or three things. For example:

 find path/to/some/directory/ -type f -iname '*.svg' -o -iname '*.pdf' 

This will cough up all the files with the extensions svg (or SVG) and pdf (or PDF) in the path/to/directory directory. You can add more things to search for using the -o over and over.

You 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:

 find $HOME /var /etc -size +500M 

This will return all the files bigger than 500 Megabytes (-size +500M) in your home directory, /var and /etc.

Additionally, find also lets you do stuff with the files it… er… finds. For example, you can use the -delete action to remove everything that comes up in a search. Now, be careful with this one. If you run

 # WARNING: DO NOT TRY THIS AT $HOME find . -iname "*" -delete 

find will erase everything in the current directory (. is shorthand for “the current directory“) and everything in the subdirectories under it, and then the subdirectories themselves, and then there will be nothing but emptiness and an unbearable feeling that something has gone terribly wrong.

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:

 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 find under your belt, you will discover all sorts of situations where it comes in handy. For example…

A 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 unzip and, gosh darn it, the person who made the zip file didn’t compress the directory itself, but the contents in the directory. Now all the images, text files and subdirectories from the zip are all mixed up with the original contents of you folder, that contains more images, text files, and subdirectories.

You 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 (ls -la *) won’t help either: the Zip program keeps the dates the files were originally created, not when they were zipped or unzipped. This means a “new” file from the zip could very well have a date prior to some of the files that were already in the folder when you did the unzipping.

You probably can guess what comes next: find to the rescue! Move into the directory (cd path/to/ClientX), make a new directory where you want the new stuff to go (mkdir NewStuff), and then try this:

 find . -cnewer -exec mv '{}' NewStuff \; 

Breaking that down:

  • The period (.) tells find to do its thing in the current directory.
  • -cnewer tells find to look for files that have been changed at the same time or after a certain file you give as reference. In this case the reference file is If you copied the file over at 12:00 and then unpacked it at 12:01, all the files that you unpacked will be tagged as changed at 12:01, that is, after and will match that criteria! And, as long as you didn’t change anything else, they will be the only files meeting that criteria.
  • The -exec part of the instruction simply tells find to move the files and directories to the NewStuff/ directory, thus cleaning up the mess.

If you are unsure of anything find may do, you can swap -exec for -ok. The -ok option forces find to check with you before it runs the command you have given it. Accept an action by typing y or reject it with n.

Next Time

We’ll be looking at environmental variables and a way to search even more deeply into files with the grep command.


People’s online social circles are becoming riskier, new Microsoft research shows

Bullying, unwanted contact and receiving unwelcome sexual images and messages were the most prominent risks in our latest digital civility research and, while strangers still pose the majority of online threats, data show a distinct rise in risk-exposure from people’s own social circles.

According to preliminary results from our latest study, 63 percent of online risks were sourced from strangers and people whom respondents knew only online – largely unchanged from the previous year. Meanwhile, 28 percent of online risks came from family and friends, up 11 points. In addition, findings revealed a relationship between risk-exposure and familiarity with the perpetrator: respondents who had met their abuser in real life were almost twice as likely to experience an online risk. More disheartening were indications that people were targeted because of their personal characteristics, namely gender, age and physical appearance.

These are some early findings from Microsoft’s latest study, “Civility, Safety and Interactions Online – 2018,” which measured attitudes and perceptions of teens and adults in 22 countries[1] about the online risks they face[2] and how their interactions impact their lives. As with previous years’ surveys, full and final results will be made available on international Safer Internet Day on Feb. 5. We chose to make these results available today in conjunction with World Kindness Day to emphasize the need for more civil and respectful interactions both online and off.

Examining the risk categories: Reputational, behavioral, sexual and personal/intrusive  

In 2017, results showed that people’s digital interactions and responses to online risks appeared to be improving, but what was surprising was that many of those targeted for abuse said their offenders came from their immediate families and social circles. We decided to take a closer look at some of these findings this year and we found that unsettling trend was continuing. Indeed, negative experiences from family, friends and acquaintances were up 4 percent, 7 percent and 2 percent, respectively, while a new classification of perpetrators – colleagues and coworkers – accounted for 9 percent of people’s unpleasant interactions online.

As for the nature of online risks across and within the four risk categories – reputational, behavioral, sexual and personal/intrusive – 40 percent of respondents experienced behavioral risks and unwanted contact (a personal and intrusive risk); just over one-third (34 percent) reported negative experiences of a sexual nature, and 28 percent said they fell victim to hoaxes, scams or fraud, another personal and intrusive risk. Interestingly, 60 percent of those who experienced a behavioral risk also experienced unwanted contact and, coincidentally, 60 percent of those who experienced unwanted contact also experienced a behavioral risk.

Perpetrators of risk graphBullying seemed to define the behavioral category. Nearly all respondents who reported experiencing a behavioral risk was a target of name-calling, purposeful embarrassment or some other form of bullying. Unwanted contact was characterized by repeated attempts to contact the target, with more than four in 10 respondents reporting at least one form of repeated unwanted contact. Receipt of unwelcome sexual imagery and messages dominated the sexual risk category, with another nearly four in 10 experiencing repeated attempts to start a romantic relationship. Finally, the commonly experienced hoaxes, scams and fraud risk was led by false and misleading information. Fake news and internet hoaxes were the most common type, far outpacing fake anti-virus scams. More detailed findings across all of these individual risks and risk categories will be released on Safer Internet Day 2019.

Get ready for Safer Internet Day 2019: Pledge to be more respectful online

On World Kindness Day and in gearing up for Safer Internet Day, we’re again encouraging global internet users to pledge to engage responsibly online. Follow the example of the 15 impressive teens that served on our inaugural Council for Digital Good, and take our Digital Civility Challenge:

  1. Live the Golden Rule by acting with empathy, compassion and kindness in every interaction, and treating everyone you connect with online with dignity and respect.
  2. Respect differences, honor diverse perspectives and when disagreements surface, engage thoughtfully, and avoid name-calling and personal attacks.
  3. Pause before replying to things you disagree with, and don’t post or send anything that could hurt someone, damage reputations or threaten someone’s safety.
  4. Stand up for yourself and others by supporting those who are targets of online abuse or cruelty, reporting threatening activity and preserving evidence of inappropriate or unsafe behavior.

Find more great advice from our council members here, and visit our website and resources page for help in handling almost any online safety situation. For more regular news and information, you can connect with us on Facebook and Twitter. However you choose to learn and get involved, make this World Kindness Day count when it comes to safer and healthier online interactions.

[1] Countries surveyed:  Argentina, Belgium, Brazil, Canada*, Chile, Colombia, France, Germany, Hungary, India, Ireland, Italy, Malaysia, Mexico, Peru, Russia, Singapore*, South Africa, Turkey, the United Kingdom, the United States and Vietnam. (* Indicates the first time this country has been included in this research.)

[2] In the latest study, the 21 risks break down as follows:

  • Reputational – “Doxing” and damage to personal or professional reputations
  • Behavioral – Being treated meanly; experiencing trolling, online harassment or bullying; encountering hate speech and microaggressions
  • Sexual – Sending or receiving unwanted “sext” messages and making sexual solicitations; receiving unwanted sexual attention – a new risk added in this latest research, and being a victim of sextortion or non-consensual pornography (aka “revenge porn”), and
  • Personal / Intrusive – Being the target of unwanted contact, experiencing discrimination, swatting, misogyny, exposure to extremist content/recruiting, or falling victim to hoaxes, scams or fraud.

Tags: , ,