Count The Files In A Directory

I think I’ve covered this before with the ls command but this time we’ll count the files in a directory with the find command. This being Linux, you can usually count on there being multiple ways to accomplish something.

There are lots of tools out there that let you visualize disk usage. I’ve covered a bunch of them over the years. You can also count the files in a directory to see if there’s something abnormal going on. You may also have some sort of file limitations that mean you’re limited to a certain number of inodes and thus you need to react accordingly.

This is just one way to count the files in a directory. There are surely a variety of ways and we’re only going to cover counting the files with the ‘find’ command. 

In this case, you won’t need to install anything. The find command is a part of the GNU ‘findutils’ and will be included by default in any desktop (or server) you’ll interact with. You’ll also be using the wc command, again something we’ve used in the past, and that too will be installed by default because it is a part of the coreutils.

The find Command:

As I said, you won’t need to install anything to use the find command. You won’t need to install anything at all for this article. You can verify that you have the find command available with this command:

We’ll search for files (with the -type f flag) and then count them with the wc command. If you check the man page for find (with man find) you’ll see that find is a good tool for the job.

find – search for files in a directory hierarchy

We will pipe the output from the find command to the wc command to count files in a directory. You’ll see…

The wc Command:

The output from the find command would be a long list of files. Rather than view that list or anything like that, we’ll simply pipe that command to the wc command. You won’t need to install anything and you can verify that the wc command exists with this command:

You can tell right away that this is a fine tool for counting things. Just check the man page (with man wc) and you’ll see this:

wc – print newline, word, and byte counts for each file

So, you can tell right away that this is a great tool for counting things. In our case, we’ll be counting new lines because the output from the find command would be one file per line. See? It just makes sense!

Let’s get to it!

Count The Files In A Directory:

If the above information wasn’t much of a clue, this is something done in the terminal. Regular readers should be expecting this because we do a lot in the terminal. Open up a terminal (you can usually just CTRL + ALT + T) and we’ll get started.

The syntax is pretty simple…

You’re using the “-type f” flag. That outputs a new file on a new line. Try it with this command, if you’d like to see:

Then, pipe that to the wc command and use the -l flag. The -l flag counts lines, of course. So, each file is on a new line and the wc command counts those new lines instead of displaying them in the terminal.

I do have this in my notes…

If you were to run this against the root “ /” drive, you’d get permission errors. Try this command for example:

Well, you can redirect the output to /dev/null using 2>, like so:

I am not sure why that’s in my notes but it is. It strips out the permission-denied responses and that’s about it. You might want to see those so that you know what wasn’t necessarily counted. Of course, you can also run this command with elevated permission via sudo. So, don’t forget that.

Closure:

There you have it… If you want to count the files in a directory you can do that with the find and wc commands. That makes it relatively simple because you won’t need to install anything. This should just work for any Linux system you’re using. That makes it pretty universal and worth remembering.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Get System Information With The ‘uname’ Command In Linux

Today we’ll be learning about a basic Linux command that’s known as ‘uname’ and it will be available in every Linux you are likely to touch. The uname command is one way to show some important system information in the Linux terminal.

You won’t even need to install anything. That’ll keep things easy and short!

The uname command stands for ‘Unix Name’ and is a part of ‘coreutils’, meaning it’s a default application included with Linux. If you’re using Linux, you almost certainly have the uname command available to you. I suppose someone might have stripped it out of an embedded system somewhere, but even that’s unlikely.

The uname command is used for displaying system information. It’s a bit limited in scope, but it still has useful information and the command is one you’ll see referenced often enough.

As I said, it’s a core utility in Linux. That means that uname is included with a bunch of other core utilities. If you want, you can easily check the man page with this command:

If you do that, you’ll see this:

uname – print system information

So, this command can and will show system information. That’d be what I told you it did in the first paragraph. I do my best to not steer you wrong and that’s exactly what we’ll do with this article.

So, let’s learn how to use the uname command in Linux:

Use The uname Command:

As mentioned above, you use the uname command in the terminal. That means you’ll need an open terminal. You can usually press CTRL + ALT + T to open your terminal. So, do that…

With your terminal open, you can just run uname in the terminal and it will tell you what sort of system you’re running. Try it…

It’ll happily spit out that you’re using Linux – if you are indeed using Linux.

It’ll also happily tell you the kernel name with the -s flag.

It should again spit out “Linux”, as that’s the kernel’s name.

If you want to know the kernel release information, use the -r flag.

Do you want to know if it’s 32 or 64-bit (or if it’s ARM? Try this command:

If you want to know the specific kernel version:

Then, you can learn the machine’s name with the -m flag.

You may just remember ‘mrs’ as that’s commonly  asked for in some support circles (and worth remembering):

There’s more to it but all you need to know is how to get all the information at once. That’s all you need to know. That’s just using the -a flag, like so:

You’ll get an output similar to this:

Which is quite a bit of system information and makes the uname command a useful command in and of itself. It’s an easy-to-remember command and one available in any Linux you’re likely to touch.

Closure:

I was a bit surprised that I’d never covered the uname command before. It’s a pretty basic command and so I’m surprised that I overlooked it. No worries. I’ve covered it now. There’s more to it but you’ll be fine with just the flags I mentioned.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Short: Show The Groups You Belong To

Today’s article, as was indicated in the title, is a short article where we learn how to show the groups you belong to. It’s just a simple command, so we’ll toss in some extra knowledge. But, this is just a short article. You won’t have much to do in this article.

The latest article explained groups and can be read by clicking this link:

List All The Groups In Linux

The last article explained how to list all the available groups in Linux. This one will explain all the groups your user account belongs to. If you want to know the groups you belong to, it’s simple enough.

If you didn’t read the article, Linux is a multi-user operating system. There are also groups. A user can belong to multiple groups and have permissions matching those groups. The example I gave in the previous article was the sudoers group. You (probably) belong to that group, giving you access to the sudo command. That is how you have elevated permissions for your account, which is quite different than using the root account.

Even if you don’t know this, you’re almost certainly a member of multiple groups. In the previous article, we learned how to show those groups and today we’ll learn how to show the groups you belong to.

Show The Groups You Belong To:

If you want to show the groups you belong to, you’ll need to have an open terminal. Just press CTRL + ALT + T and your default terminal should open. Otherwise, open a terminal from your application menu.

With your terminal open, you can show the groups you belong to with this command:

Your output will be different but here’s an example:

This also works with other users. Here’s the syntax:

That will show the groups that the user belongs to. It’s a pretty simple thing to learn and a pretty handy thing to learn. It’s so simple and easy that this is an intentionally short article.

Closure:

There you have it… It’s a short article but showing the groups you belong to isn’t a complicated affair. This is something anyone can do and there’s no reason to make the article longer than it already is. While I could make it longer, it’d be wasting my time and your time. It’s just that easy.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

List All The Groups In Linux

This is going to be a simple enough article where we list all the groups in Linux – specifically your Linux. (Your list of groups may not be the same as my list of groups, of course.) This isn’t complicated but might be important to some of you, so we might as well write about it.

I’ve often mentioned that Linux is a true multi-user operating system. That is, you have many users, each with assigned tasks and permissions. You have users for everything from root to printing.

Well, along those same lines, Linux also uses groups. You can not only set permissions on a per-user basis, you can set permissions on a per-group basis. Any member belonging to that group will have the same permissions as that group.

A good example is ‘sudo‘. That’s a group you likely belong to. Because you belong to the sudo group you have access to the sudo command. This lets you have elevated permissions to perform various operations on your system. Make sense?

We’ll be using a new tool for this…

getent:

The getent command is used to read various databases. This is fine because ‘groups’ is one of the databases that getent can read. You won’t need to install anything to run this command.

You can check the man page with this command:

From there, you’ll see that getent is described like so:

getent – get entries from Name Service Switch libraries

So, it’s a database reading tool more than anything else.

If you’d like an easier way, we’ll do the same with the cat command.

cat:

I really shouldn’t have to describe the cat command. We’ve used it plenty of times. It takes the contents of a file and spits them out to your terminal (standard output). It’s an oft-used tool in the Linux world. Once again, you won’t have to install anything.

You can check the man page with this command:

At that point, you’ll see that the cat command is described like this:

cat – concatenate files and print on the standard output

See? It’s the correct tool for the job. We want to take the contents of a file and read it in the terminal. The cat command is perfect for that.

I’ll show you how to list all the groups in Linux with both commands. You can pick your favorite and just use that command. Either command will work just fine for this job.

List All The Groups In Linux:

If it wasn’t obvious from the above, this is yet another task for the terminal. If you don’t have an open terminal, you can probably open one by pressing CTRL + ALT + T. If that doesn’t work, find the terminal in your application menu and click it.

With your terminal open, run the following command:

While not of much use, here’s an example output:

You can get the same output with the cat command. That might be easier to remember for newer users. After all, you should be familiar with the cat command. That command is simple enough.

That will give you the same results as the ‘getent’ command above. Obviously, the group name is the first column.

I’m not sure where I learned this, but you can just list the first field and get a list of groups without any additional information. Just use this command:

That’s not nearly as useful as it could be, but I figured I’d share.

Closure:

Well, if you wanted to list all the groups in Linux, you now know how to do so. If you didn’t know about groups, you now know that you have groups and how to list them. So, you might as well add that to your notes and keep it in mind. (The groups subject may appear in a future article!)

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Legitimate Reasons To Not Use Linux

Today’s article is going to be something my regular readers wouldn’t expect as we discuss legitimate reasons to not use Linux. Like it or not, people have reasons not to use Linux. I’ll cover some of them that I think are more legitimate than other reasons.

I think I’ll link to these first:

Top 10 Reasons Why I Use Linux
Why I Use Linux
What it’s Like To Beta-test Linux, Specifically Lubuntu

I share those three links because I think it should be obvious that I’m a Linux fanboy. I love and use Linux because I think it’s the best operating system for me. 

At the same time, I realize that Linux may not be your choice. I think there are some legitimate reasons to not use Linux. There are other reasons with less legitimacy (that is reasons based on fallacies) and we’ll avoid those in this article. Instead, we’ll cover reasons with legitimacy.

Legitimate Reasons To Not Use Linux:

I’ll cover the legitimate reasons to not use Linux that I can think of. After you read them, you can leave a comment agreeing with them or disagreeing with them. You can also add your reasons. If those reasons are any good (and I have both time and motivation) I’ll add them to the article. So, if you’re going to comment on an article, let this be one you feel especially welcome to do so.

#1. You rely on software that will not work with Linux.

This one is pretty basic. There’s software that will not work with Linux. Yes, it might work in Wine, but it may not work in Linux at all. This is the cold hard truth and if you need that software then you’re not going to be interested in moving to Linux.

#2. You’re heavily invested in Microsoft.

Let’s say that you use MSFT for everything, from office to desktop. Sure, you could switch. Linux has equivalents to almost everything MSFT offers. But, you pay for your Office365 and similar, you might use their gaming hardware, etc…

While you can switch, it may be harder than it would be for those people who are more software-agnostic. You simply don’t want to put in that effort. You simply don’t see a need to put in that effort.

This applies to Apple users as well. If you’re heavily invested in the Apple ecosystem, you may not want to switch to Linux. It could also apply to BSD users, Unix users, etc…

#3. You play modern games.

Yes, many games are available on Linux. These days, we can install Steam and play thousands of games on Linux. However, you’ll find that quite a few games will simply not work with Linux. You’ll find that they won’t work with Wine. That’s just the sad case of affairs.

Perhaps you could get a console that you’re happy with and switch to Linux while not always playing the latest and greatest games? More and more games are being developed with Linux compatibility so this may change in time.

#4. You’re happy with Windows.

This one is similar to those who are invested in Windows. However, those people who are invested heavily in the MSFT ecosystem may not be happy, they’re just entrenched. This is for those folk who are just plain happy with Linux. They know the differences. They understand reality. Linux just isn’t something they’re interested in because they’re happy with Linux.

#5. You’re learning disabled.

I am not saying that the learning disabled can’t learn how to use Linux. However, a person may have invested enough time learning to use Windows and may not want to invest time and effort learning a new operating system.

Think of someone who is elderly and has learned to navigate the Windows environment. Maybe they have a little cognitive problem and they no longer retain things as well as they once did. Sure, they could learn to use Linux but they may have better things to do with their time.

Speaking of time…

#6. You lack the time to learn Linux.

Let’s face it, many people are now working two jobs just to pay the rent and have enough to eat. Maybe they don’t work extra jobs but have hobbies that take up their time. Sure, we have computer hobbies but they may have hobbies that don’t involve technology. There are any number of reasons why you simply don’t have time to learn to use Linux.

#7. You’re just not interested in learning to use Linux.

You’ve already learned enough about Linux. You know about all the various choices. You know how easy it can be to get into Linux but you just don’t care. That’s okay! It’s perfectly okay to not be interested in learning to use Linux. If you’re happy with proprietary software, that’s your choice. This entry is for the person who is aware of Linux, the ease of Linux, and just doesn’t care to learn.

#8. You have hardware that will not work on Linux.

It’s possible that you have hardware that simply will not work on Linux. No amount of goodwill and happy thoughts is going to change this. The hardware vendor doesn’t support Linux and has no plans to support Linux in the future. While that’s unfortunate, if you need that hardware to do your computational tasks then it’s perfectly okay to not use Linux.

This can also be true with ‘bleeding-edge’ hardware. If you’re interested in using (for example) the latest and greatest graphics card, Linux may not offer any support. It could be a while before you get even basic support for that hardware. The devs need to figure out how to make it work with Linux and that takes time.

#9. You do not own the hardware.

If you share the hardware with other users, they may not appreciate it if you install Linux. They may not be interested in that. Yes, you could use virtual machines and live instances run from an external drive, but many people don’t find those experiences satisfactory.

This is especially true if you’re still a kid. Your parents aren’t going to be all that happy if they go to use the computer only to find out that you’ve installed a completely different operating system. Instead, look for a second device that you can call your own. Until then, it’s okay to give Linux a pass.

#10. <Insert Your Reasons To Not Use Linux Here>

What did I forget? How many other reasons can you think of? I tried to cover as many reasons to not use Linux as I could think of. I’m sure there are other reasons, so now’s a fine time to add them as a comment.

Closure:

So, I figured I’d write a different article. This time, I wrote about legitimate reasons to not use Linux. Frankly, there are legitimate reasons why a person may decide to not use Linux. I suspect many people could use Linux who do not currently use Linux, but there are legitimate reasons why they may choose not to.

So long as they’re making an informed and honest decision, I think that’s just fine. I’m perfectly okay with the fact that other people don’t use Linux. I’ve never lost a minute’s worth of sleep over the fact that people use software that I don’t like. I don’t even invest the time to argue with them. I just hope that they’re making their choices from an informed position and that they know the reality and benefits of using Linux.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Subscribe To Our Newsletter
Get notified when new articles are published! It's free and I won't send you any spam.
Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.