Home Blog Page 306

How to Search for Files from the Linux Command Line

Learn how to use the find command in this tutorial from our archives.

It goes without saying that every good Linux desktop environment offers the ability to search your file system for files and folders. If your default desktop doesn’t — because this is Linux — you can always install an app to make searching your directory hierarchy a breeze.

But what about the command line? If you happen to frequently work in the command line or you administer GUI-less Linux servers, where do you turn when you need to locate a file? Fortunately, Linux has exactly what you need to locate the files in question, built right into the system.

The command in question is find. To make the understanding of this command even more enticing, once you know it, you can start working it into your Bash scripts. That’s not only convenience, that’s power.

Let’s get up to speed with the find command so you can take control of locating files on your Linux servers and desktops, without the need of a GUI.

How to use the find command

When I first glimpsed Linux, back in 1997, I didn’t quite understand how the find command worked; therefore, it never seemed to function as I expected. It seemed simple; issue the command find FILENAME (where FILENAME is the name of the file) and the command was supposed to locate the file and report back. Little did I know there was more to the command than that. Much more.

If you issue the command man find, you’ll see the syntax of the find command is:

find [-H] [-L] [-P] [-D debugopts] [-Olevel] [starting-point...] [expression]

Naturally, if you’re unfamiliar with how man works, you might be confused about or overwhelmed by that syntax. For ease of understanding, let’s simplify that. The most basic syntax of a basic find command would look like this:

find /path option filename

Now we’ll see it at work.

Find by name

Let’s break down that basic command to make it as clear as possible. The most simplistic  structure of the find command should include a path for the file, an option, and the filename itself. You may be thinking, “If I know the path to the file, I’d already know where to find it!”. Well, the path for the file could be the root of your drive; so / would be a legitimate path. Entering that as your path would take find longer to process — because it has to start from scratch — but if you have no idea where the file is, you can start from there. In the name of efficiency, it is always best to have at least an idea where to start searching.

The next bit of the command is the option. As with most Linux commands, you have a number of available options. However, we are starting from the beginning, so let’s make it easy. Because we are attempting to find a file by name, we’ll use one of two options:

  • name – case sensitive

  • iname – case insensitive

Remember, Linux is very particular about case, so if you’re looking for a file named Linux.odt, the following command will return no results.

find / -name linux.odt

If, however, you were to alter the command by using the -iname option, the find command would locate your file, regardless of case. So the new command looks like:

find / -iname linux.odt

Find by type

What if you’re not so concerned with locating a file by name but would rather locate all files of a certain type? Some of the more common file descriptors are:

  • f – regular file

  • d – directory

  • l – symbolic link

  • c – character devices

  • b – block devices

Now, suppose you want to locate all block devices (a file that refers to a device) on your system. With the help of the -type option, we can do that like so:

find / -type c

The above command would result in quite a lot of output (much of it indicating permission denied), but would include output similar to:

/dev/hidraw6
/dev/hidraw5
/dev/vboxnetctl
/dev/vboxdrvu
/dev/vboxdrv
/dev/dmmidi2
/dev/midi2
/dev/kvm

Voilà! Block devices.

We can use the same option to help us look for configuration files. Say, for instance, you want to locate all regular files that end in the .conf extension. This command would look something like:

find / -type f -name "*.conf"

The above command would traverse the entire directory structure to locate all regular files ending in .conf. If you know most of your configuration files are housed in /etc, you could specify that like so:

find /etc -type f -name “*.conf”

The above command would list all of your .conf files from /etc (Figure 1).

Figure 1: Locating all of your configuration files in /etc.

Outputting results to a file

One really handy trick is to output the results of the search into a file. When you know the output might be extensive, or if you want to comb through the results later, this can be incredibly helpful. For this, we’ll use the same example as above and pipe the results into a file called conf_search. This new command would look like: ​

find /etc -type f -name “*.conf” > conf_search

You will now have a file (conf_search) that contains all of the results from the find command issued.

Finding files by size

Now we get to a moment where the find command becomes incredibly helpful. I’ve had instances where desktops or servers have found their drives mysteriously filled. To quickly make space (or help locate the problem), you can use the find command to locate files of a certain size. Say, for instance, you want to go large and locate files that are over 1000MB. The find command can be issued, with the help of the -size option, like so:

find / -size +1000MB

You might be surprised at how many files turn up. With the output from the command, you can comb through the directory structure and free up space or troubleshoot to find out what is mysteriously filling up your drive.

You can search with the following size descriptions:

  • c – bytes

  • k – Kilobytes

  • M – Megabytes

  • G – Gigabytes

  • b – 512-byte blocks

Keep learning

We’ve only scratched the surface of the find command, but you now have a fundamental understanding of how to locate files on your Linux systems. Make sure to issue the command man find to get a deeper, more complete, knowledge of how to make this powerful tool work for you.

Learn more about Linux through the free “Introduction to Linux” course from The Linux Foundation and edX.

New Keynote Speakers Announced for Hyperledger Global Forum

With over 75 sessions, keynotes, hands-on technical workshops, social activities, evening events, and more, Hyperledger Global Forum gives you a unique opportunity to collaborate with the Hyperledger community, make new connections, learn about the latest production deployments, and further advance your blockchain skills. In addition to previously announced keynote speakers, new keynote speakers include:

  • Frank Yiannas, Vice President of Food Safety, Walmart
  • David Treat, Managing Director, Accenture

Session Highlights Include:

Technical Track:

  • Approaches to Consortia Governance and Access Control in Hyperledger Fabric Applications – Mark Rakhmilevich, Oracle
  • Chaincode Best Practices – Sheehan Anderson, State Street
  • Lessons Learned Creating a Usable, Real-world Web Application using Fabric/Composer – Waleed El Sayed & Markus Stauffiger, 4eyes GmbH

Secure your spot now and save up to $150 with the current registration rate, available through November 25. Register now >>

Read more at The Linux Foundation

An Introduction to Ansible Operators in Kubernetes

For years, Ansible has been a go-to choice for infrastructure automation. As Kubernetes adoption has skyrocketed, Ansible has continued to shine in the emerging container orchestration ecosystem.

Ansible fits naturally into a Kubernetes workflow, using YAML to describe the desired state of the world. Multiple projects, including the Automation Broker, are adapting Ansible for use behind specific APIs. This article will focus on a new technique, created through a joint effort by the Ansible core team and the developers of Automation Broker, that uses Ansible to create Operators with minimal effort.

An Operator is a Kubernetes controller that deploys and manages a service or application in a cluster. It automates human operation knowledge and best practices to keep services running and healthy.

Read more at OpenSource.com

Serverless Roadmap: Hosted and Installable Platforms

The survey conducted for our “Guide to Serverless Technologies” asked a series of questions about the vendors and technologies that we will be using in the next 18 months to drive our coverage at The New Stack.

The first half of the roadmap dealt with the platforms and frameworks on which serverless architecture is deployed. The leading hosted platforms are the big three cloud providers’ FaaS offerings. AWS Lambda has twice as many users as Azure Functions and more than three times as many as Google Cloud Functions. Although on-premises deployments are not widespread, they are widely being considered. In fact, the percentage planning to use KubelessOpenFaaS, and Apache OpenWhisk rivals those looking at AWS, Microsoft and Google. In other words, the battle for the next wave of serverless adoption is alive and well.

Read more at The New Stack

Facebook Open-Sources New Suite of Linux Kernel Components and Tools

Today, we are announcing a suite of open source Linux kernel components and related tools that address critical fleet management issues. These include resource control, resource utilization, workload isolation, load balancing, measuring, monitoring, and much more.

Kernel and kernel application developers at Facebook partner with various internal teams to develop technologies that resolve issues and concerns in Facebook’s data centers — the same challenges that many throughout the industry share. The following products are now in production on a massive scale throughout all of Facebook’s infrastructure, as well as at many other organizations.

BPF

BPF is a highly flexible, efficient code execution engine in the Linux kernel that allows bytecode to run at various hook points, enabling safe and easy modifications of kernel behaviors with custom code. Although it’s been widely used for packet filtering, BPF’s instruction set is generic and flexible enough to support and allow for a wide variety of use cases beyond networking such as tracing and security (e.g., sandboxing).

Read more at Facebook blog

Catch Up on October Events with Videos from OS Summit, Linux Security Summit, and Open FinTech Forum

October was big month for events at The Linux Foundation. Seriously, just this month, the LF-affiliated events included:

Following this flurry of activity, we want to share some of the highlights with you. At Open Source Summit Europe & ELC + OpenIoT Summit Europe, more than 90 sessions were recorded, and you can browse the list of presentations here.  A few of the featured keynotes include:

There are 21 videos available online for Linux Security Summit Europe, several of which provide an overview of recent developments in the Linux kernel, including the following:

The Open FinTech Forum is a brand-new event, which took place in New York City earlier this month and focused on the intersection of financial services and open source. It covered cutting-edge open source technologies including AI, blockchain, and Kubernetes, and there are 9 keynote videos available online, including:

We invite you to check out these presentations, see all the upcoming Linux Foundation events, and mark your calendar to join us.

Set Better Career Goals: A Step-by-Step Guide

In my previous article, I explained the benefits of setting your professional goals in the opencollaboratively and transparently, so others could enrich the process. And earlier in the year, I provided my perspective on performing your professional self-assessments the same way. Now I’d like to offer my preferred process for making all this work.

Whatever goal setting methodology you choose (be it SMART, OKRs, or something else), approach the process as its own project in a transparent and collaborative way. In other words, treat the goal setting process as its own project, just like you would the work toward the goals themselves.

Start with where you are

Before stating your wild goals for the future, first build an understanding of where you are now. This way you’ll be able to chart a clear path from here to your ideal future state—that is, once you’ve identified your goals.

Read more at OpenSource.com

Ubuntu Fan Aims to Simplify Container Networking

Most people will think of Ubuntu as primarily a Linux server and cloud technology effort. Ubuntu also has some networking capabilities that it develops on its own including the Fan container networking project.

There are multiple open source SDN efforts in the market today that more well known than Fan, including the Tungsten Fabric and OVN, among others. Fan however, takes a different approach than other SDN models.

“Fan is a zero configuration SDN,” Mark Shuttleworth CEO of Canonical Inc and Founder of Ubuntu, said. “What you trade is the ability to live migrate an IP address for simplicity.”

Read more at EnterpriseNetworkingPlanet

39 No Frills Keyboard Shortcuts Every Developer Should Follow

What used to be 27 is now 39 – Due to all the great comments, I’ve amended the list to add a few more suggestions, thanks to all that contributed.

Shortcuts are the most productive thing that a developer can add to their repertoire that will aid them through their entire career. Learning how to use your system and tools will improve your productivity and in general make traversing all your windows and apps a breeze. The mouse is a great, tool, but if you can do it quicker, more effectively without your hands leaving your keyboard then you should!

Here’s a list of my most used shortcuts, you’ll probably know or use quite a few of these already, hopefully there is one here you don’t!

Read more at Dev.to

55 Percent of Cloud Developers Contribute to Open Source, Says Survey

In presenting the results of its survey of 4,300 cloud developers, DigitalOcean seemed surprised that only 55 percent of respondents contribute to open source projects. Yet to tech outsiders — or old-timers — it may be more surprising that more than half of developers do contribute. There are relatively few professions in which companies and their employers regularly offer pro bono services for the greater good of the industry.

DigitalOcean, which provides cloud infrastructure software and services, has timed its “Currents” survey release in conjunction with the conclusion of its fifth annual Hacktoberfest program. Co-hosted with GitHub and twilio, Hacktoberfest invites developers to collaborate during the month of October on a smorgasbord of open source projects.

Corporate leaders appear to be sending mixed messages to their developers about open source. Although 71 percent of respondents to the DigitalOcean survey said that their employers “expect them to use open source software as part of their day-to-day development work,” employers are less supportive of their developers contributing to software that doesn’t directly benefit the company. Only 34 percent of respondents said they were given time to work on open source projects not related to work.

Younger developers more willing to contribute

The report reveals some encouraging signs, as well. Some 37 percent of the developers said they would contribute more to open source if their companies gave them the time to do so. In addition, despite some 44 percent of respondents saying they don’t contribute because they feel they lack the right skills and 45 percent saying they don’t know how to get started, the less experienced, and presumably younger, developers appear more open to contributing. A total of 60 percent of developers with five or fewer years of experience contribute to open source, while the number is “significantly less” for developers with more experience, says DigitalOcean. This bodes well for future contribution levels.

Developers in India were more likely to contribute to open source projects (68 percent) than any other nationality. Although DigitalOcean did not speculate, this may be due in part to the younger average age of Indian developers.

Motivations to contribute include the opportunity to improve coding skills, learn new technologies, and advance one’s career. Also noted was the less tangible benefit of being part of a community.

Among the many other findings in the survey, the leading programming language for open source projects was JavaScript (62 percent) followed by Python at 52 percent. The only other languages over 20 percent were PHP (29 percent), Java (28 percent), and CSS (25 percent). When asked which open source projects have “excited you the most” over the last three years, the React.js JavaScript library for building UIs took the top spot with 468 mentions, followed by Kubernetes (335), Docker (252), Linux (240), and Tensorflow (226).

Companies are failing to lead the open source charge by example. Only 18 percent of employees said their companies actively participated in open source organizations such as the listed examples: Apache Foundation, Node.js Foundation, and Cloud Native Computing Foundation. Three out of four respondents said their companies have donated $1,000 or less to such organizations over the last year.

Not surprisingly, high cost was the leading reason (38 percent) why companies skimp on open source donations and labor contributions. This was followed by a preference for in-house development (33 percent) and lack of knowledge of the listed organizations (27 percent). More promisingly, 29 percent said their companies plan to contribute to such organizations in the future.

When asked which of the five leading tech companies were doing the most to support open source, 53 percent listed Google, and Microsoft came in second at 23 percent. Next came Facebook (10%), Amazon (4%), and Apple (1%). Although IBM does not appear on this list, its $34 billion acquisition of Red Hat this weekend — the second largest software acquisition in history — should boost its already extensive open source contributions in cloud software.

For more survey results, check out ActiveState’s survey of 1,407 open source developers, which focuses on open source runtimes, and the open source programs survey from The New Stack and The Linux Foundation, which looks at the role of open source programs within organizations.