Some Fun With Sorting The Output Of ‘ls’

Today’s article will be relatively short and easy, as we have some fun with sorting the output of ‘ls’. It’ll be a pretty short and simple article, but that doesn’t mean it’s not useful. Read on and learn about sorting the output of ‘ls’!

The last article I wrote was:

Some Fun With Formatting The Output From ‘ls’

This article will be remarkably similar, but isn’t about formatting the output of ‘ls’, it’s about sorting the output of ‘ls’. Yes, there is a difference! This is useful for a variety of reasons, but it’s mostly useful for viewing your files categorically. There are just a handful of sorting options, but we’ll cover them all.

Like always, it’s important to know that you should not to parse the output of ‘ls’. Parsing the output of ‘ls’ if full of risks, so you shouldn’t do it! The link explains it better than I can, and it tells you what to do instead of parsing the output of ‘ls’.

Obviously, and again, we’ll be using the ‘ls’ command. The ‘ls’ command defines itself fairly accurately as:

ls – list directory contents

So, just like the last article, there’s no real reason to make the intro longer than it needs to be. Let’s just jump right into the article.

Sorting The Output Of ‘ls’:

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

With your terminal now open, you can stay right there in your /home directory, or you can ‘cd‘ into a directory of your choice – preferably one with a variety of files in it.

When you’re done picking a directory, you have the following choices:

See? I even alphabetized them for you! The list of what they do should be fairly obvious, with ls --sort=version being the most unusual and only applying to versioned files.  Also, while included, there’s not a whole lot of reason to use ls --sort=none, as that’s just the default output.

I find sorting by time to be pretty handy, as well as sorting by size. I don’t have much of a reason to use the rest, but they’re there if you need them. I figured I’d include ’em all, rather than just those that I find useful.

Closure:

There you have it, another short article! It’s also another article about the ‘ls’ command, but this time we’re sorting the output of ‘ls’. I figured I’d do this article right after the other one, mostly so that I’d remember to actually cover it. 

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 own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Some Fun With Formatting The Output From ‘ls’

Today’s article will be a nice and simple one, in which we’ll have some fun with formatting the output from ‘ls’. It’s just a quick article today, as there’s no real reason to make this all that difficult. Read on, my dear readers!

While it’s true that you shouldn’t parse the output from the ‘ls’ command, you can format it to get an output that more suits your needs. You might want to do this to more easily understand the output from ‘ls’. There are a half dozen or so formatting options and we’ll show them all to you in this article. One (or more) of them might tickle your fancy.

Obviously, we’ll be using the ‘ls’ command. The ‘ls’ command describes itself like this:

ls – list directory contents

Which is exactly what it does. It’s not a very complicated command, as far as some commands go, but there are a lot of options. Like always, I highly suggest that you read the man page (man ls) to get more information than will be contained in this article.

Anyhow, I said this will be a short article, so I will just get right into the meat of the article instead of typing a bunch of additional fluff. You’re welcome!

Formatting The Output From ‘ls’:

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

With your terminal now open, you can choose to view the output of ‘ls’ with a variety of formats. They’re more or less self-explanatory, so I’m just going to show them all to you. If you’re confused by any of them, try them in your terminal, which will should make it more clear.

I even made you an alphabetized list! See? I am helpful today!

So, for ls --format=across you’ll get the output spread across your screen (as much as possible). If you use ls --format=comma, the files will be separated by a comma.

Out of all of them, I tend to use ls --format=verbose more often than I use any of the other ways of formatting the output from ‘ls’. It gives me just enough information, from file modification date and time to the file’s permissions. So, out of all of them, that’s the one I’ll use most often. 

Feel free to flip through and try them all. You’re bound to find something interesting in there. The ‘ls’ command is surprisingly useful, and it’s harmless enough for you to explore it at length.

Closure:

See? I told you that it’d be a pretty short article today. I just showed you some ways of formatting the output from ‘ls’ and that’s all I’ve done. There’s no reason to make this longer than necessary. I think my readers are smart enough to take it from here, and figure out what they like most, or find the most useful.

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 own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Find Files Modified On A Specific Day

In today’s article, we’re going to do exactly what the title says, we’re going to find files modified on a specific day. Imagine that! We’re doing what it says in the title! I dunno why I write the things I do. But, I do have quite a few people reading, and hardly any of ’em complain!

So, why would you want to do this? Well, let’s say Big Bad John logged into your system on Friday. He was fired for drinking at lunch, but still had access to the system for another hour before security got around to hauling his butt out of the building.

Wouldn’t you like to know what files were changed on his computer that day, just to see if he’d done anything malicious? You might also have some weird system errors and want to know what files have changed today so that you can narrow down your search for the culprit. There are all sorts of reasons why you might want to know how to find files modified on a specific day.

We’re going to be using a simple command, and just one command. We’ll be using the ‘find’ function. There are surely other ways to do this, but we’ll use the find command. It works and it means you have a relatively short article.

How To: Find Files Modified On A Specific Day:

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

With your terminal now open, let’s say you want to find files edited on the day this article is published. To do that, you’d run this command:

For the sake of simplicity, the format is YYYY-MM-DD. You could use other date formats that are recognized by the system, but we’ll just stick to this date format as it’s nice and easy.

Now, you can also adjust your ‘maxdepth‘ value. If it’s a 1, it will dig down one directory deep. So, if you’re in your home directory, it’ll dig into ~/Downloads, ~/Pictures, ~/Documents, etc… If you change it to 2, it’ll dig into the sub-directories, like ~/Downloads/foo and ~/Documents/bar.

If you want to find files modified on a specific day, simply change the date in the command and start searching. It’s handy if you edited a file and can’t recall which file it was you edited. The command can be used for all sorts of things like that. Good luck!

Closure:

There you go… You have another article and this one teaches you how to find files modified on a specific day. It’s a short article with just one command. There’s no reason to pad the article further. It’s just the one command. Thanks for reading!

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 own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Add A Message Of the Day (MOTD) To SSH

In today’s article, we’re going to learn how to add a message of the day (MOTD)  to SSH. It won’t be a very long article, ’cause I can refer to some earlier articles. But, I’m sure someone will find it handy.

So, yeah… There have been a lot of SSH articles. I love SSH and it has a ton of features, so they get written about. Here’s a link to a list of previous SSH articles. If you have any SSH questions, you’re free to read those articles. They answer all sorts of SSH questions.

SSH stands for ‘secure shell’ and is a way to remotely manage computers. It’s a handy tool, one I think most users should learn. You can sometimes SSH into a broken computer and repair it. It’s pretty handy that way.

The astute among you might notice that this article is a little late. So, I lost internet connectivity and wrote and scheduled an article – or thought I did…

Normally, WordPress would hold that article in cache – but I wasn’t connected. I seem to recall noticing an error when I did hit the scheduling buttons, but it looked normal so I assumed it’d work. That means I’m writing this article right now, ’cause I don’t really want to break my streak of an article every other day. 

Which also explains why this one is just a short article.

Recently, I covered how to show an SSH banner. Well, this is pretty much the same thing. When someone logs into SSH, they’ll see the banner. When someone logs into SSH, they can also see the MOTD. I figure I’ll give you the option to pick which ever one you want.

Add A Message Of The Day (MOTD) To SSH:

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

With your terminal now open, we’re going to use nano to do some file editing. It’s really simple. First:

Add whatever text you want. You can generate a fancy ASCII logo and some text about who’s allowed to access the server and remind hackers (’cause they’ll surely listen) that unauthorized access is illegal. To save your MOTD with nano, just press CTRL + X, then Y, and then ENTER.

That’s actually mostly it. You shouldn’t have to edit the SSH configuration for this, it should just work when you restart the SSH service with:

SSH should pick it up automatically and now display your brand new SSH MOTD. It’s a ‘message of the day’ so you can change it regularly and SSH should pick up those changes automatically.

Depending, you might not even have to restart the SSH service. I’ve had it use the MOTD automatically, and I’ve had to restart the service to get it to show. You can have some fun and use things like this to generate some ASCII text. It’s your MOTD, do whatever you want with it!

Closure:

See? This was a nice and easy article. If you want to add an MOTD to SSH, you now know how to do so. Also, for the record, I’m getting pretty darned fast at writing articles. Well, some of them are pretty speedy to write. It helps if I don’t have to consult my notes that often. If I do, I often just put them on a different screen and that makes it easier to read them.

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 own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

How To: Show An SSH Banner

Today’s article is another SSH article, and it will show you how to show an SSH banner. What’s an SSH banner? It’s a message shown when someone logs into the computer via SSH. This can include warning messages, reminders that they’re being logged, etc…

Why would you want to do this? Well, you can include specific directions in there. You can also do so for regulatory compliance, should you be obligated to warn people that you’re storing their information. Some of the messages are quite formal, but you can write your own.

Once again, SSH stands for ‘Secure Shell’. It’s a way to remotely login and use a remote device. It’s usually done in pure text, terminal mode. You can actually forward x11 and control some graphical applications. That’s easy enough and quite a load of fun.

I’ve actually written many SSH articles. Feel free to peruse them at your leisure. If you have questions about SSH, odds are good that I’ve covered them already. I think SSH is a brilliant tool and so quite a few articles cover the many things you can do with SSH.

I find SSH to be a useful, brilliant tool even when it’s just me in my house. As I also manage some remote stuff and SSH beats flying across the world just to update a computer. The good news is that I’ll eventually run out of SSH article ideas!

With the above in mind, let’s just jump into the article…

Show An SSH Banner:

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

Note: We’ll be using ‘nano‘ in this article. Click that link to learn more.

With your terminal now open, it’s time to set up an SSH banner. To start with, we’ll create the banner. You’ll need to start with creating a file like so:

With your banner file open (and you can name it anything, or you can even place it anywhere), just enter the text you want people to see when they login via SSH. You can make it anything you want, but I tend to keep it brief. Some folks go for the giant ASCII banner types, but I like to keep it simple.

When you’re done writing your banner, you need to save it. To save it in nano, you just press CTRL + X, then Y, and then ENTER.

Now, you need to edit your SSH configuration. To do that you use:

Scroll down until you see the following:

Edit that line to read:

If you stored your banner in a different location or a different file name, you must also change the path to suit. Then, save your SSH configuration by pressing CTRL + X, then Y, and then ENTER.

Your next step will be to restart SSH. That command is nice and simple:

Next, login again with SSH and you should see your new SSH banner! It’s really that simple. If you don’t see it, make sure to double check because all those steps are necessary.

Closure:

And there you have it. You have another article! This one has shown you how to show an SSH banner. It’s not terribly difficult. It’s also potentially useful. Users are effectively agreeing to the terms you set in them, which may be legally binding. Enjoy your new SSH banner and, if it’s not in a professional setting, feel free to be creative with it!

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 own 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.