How To: Make A File Executable

Today we’re going to learn something important, that is how to make a file executable. This is something everyone should know how to do. It’s not going to be easy to make this into an article, ’cause it’s really quite easy, but I’ll give it a shot.

One of the important things about Linux is that files have various permissions. You can read, write, and execute a file based on the permissions. This helps keep Linux a bit more secure, because files can’t be executed until you’ve given them permission to do so.

I’ll make this article as straightforward as I can, by trying to give you an example of how this works. We’ll create a file, make it executable, and then run said file. This should serve as a good example, so that you can do so in the future.

You’ll see a bunch of commands in this article. If you’re new, just follow ’em until the end and you’ll hopefully understand what’s going on, and see how to make a file executable. Trust me, this isn’t something all that taxing. I’m sure you can get it!

Make A File Executable:

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 open, let’s create a new file. We’ll do that with:

Open love.sh for editing with nano by using the following command:

Enter the following text:

Now, you’ll have to save that. Just press CTRL + X, then Y, and then ENTER. That will save the file with the newly added text.

Now, we’ll make the file executable with the ‘chmod‘ command. That’s done with this command:

With that done, all you need to do now is execute the file. To do that, you just call the file by name in the terminal. As you’re still in the same directory, you’ll need to use ./ – so your command actually looks like:

With that, you should get a message saying that you love Linux Tips. Aww… Isn’t that sweet of you! We love you too! It was also a fun way to create a file, edit it, make it executable, and then actually executed said file.

Closure:

See? That wasn’t all that hard. I hope that method shows you a little about how to make a file executable. It’s a pretty basic skill that all Linux users should be familiar with. It’s not a very complicated article, but that’s just fine. At least we (hopefully) had some fun 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.

How To: Find Out When A File Was Created

Today, we’re going to learn how to find out when a file was created. Odds are good that you could use the right click menu in a GUI file manager and figure it out, or you can sort by time and show details, that sort of stuff. Those being ‘easy’ we’ll learn how to find out when a file was created in the terminal.

Yeah, a lot of these articles explain how to do things in a terminal – even when there’s a nice graphical way to accomplish those same things. While it’s true that we may have different shells, we’re far more universal in the terminal than we are in a graphical desktop environment.

It’s good to learn how to do things in the terminal. If you can accomplish your goal in the terminal – you can accomplish it quickly and easily everywhere. That’s a pretty great benefit. (It’s not even unique to Linux – as you can do a whole lot via command line in Windows and MacOS.)

Also, today’s article feels a bit like work. I was hoping that it’d take longer to really start feeling that way. It’s okay. I picked a brief subject, what should be a short article, and that’ll be almost like a day off.

Find Out When A File Was Created:

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 open, change to the directory that contains the file you want to find out when it was created. Let’s say it’s in your Documents directory:

Now, you can just use the -l flag with the ls command. That’d look like this –  showing the creation date (and maybe time, if the file is recent enough) for all the files in that directory:

That’s pretty messy, especially if you have a lot of files in the directory. So, you can specify the file for which you want to find the creation date by specifying the filename in the command itself, like so:

That’ll do it for you. Well, it should do it for you! If not, something’s broken and don’t ask me to fix it!

Closure:

There you have it… You can now tell when a file was created. It’s not a very difficult process and it’s one you can easily commit to memory. I find myself using it when I’ve created a file and then can’t find it among other files with similar names – I’ll check to wee when a file was created and figure it out that way.

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.

Sort Files By Size (In The Terminal)

In today’s article, we’re going to cover something nice and simple; how to sort files by size in the terminal. This is something everyone should know, because sorting files is often a prerequisite to understanding and managing said files.

Besides, not all the articles have to be something complicated. The tagline for Linux-Tips is “Getting you up to speed!” It’s supposed to be aimed squarely at new Linux users. The problem is, many of those articles are boring to write and the 2nd largest group of readers aren’t really beginners. 

So, yeah…

Today, we’ll have a nice, basic article that tells you how to sort files by size – in the terminal. In fact, some of the more regular users may not have these commands memorized. Now’s a good time to learn ’em.

We’ll be using the ‘ls’ command for this. It is said that you shouldn’t parse the output of ‘ls’ for anything important. It’s bad practice for reasons I think I’ve touched on before. However, you can safely use ‘ls’ for this process as it’s just sorting the files by size and doing so by itself.

For those that don’t know, ‘ls’ has a ton of options. It’s a tool used to show the contents of a directory. You can use man ls to get more information about the command. We’ve previously covered:

Let’s Use ‘ls’ To Sort Files By Time

Well, today we’ll use ‘ls’ to …

Sort Files By Size:

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.

You might just as well stay right there in your default location – which should be your home directory. Feel free to switch to a new directory, but you really won’t need to. It’s an easy command. 

First, we’ll show the output sorted to show the largest files first:

Of course, you can reverse that sort order and show the smallest files first. To do that, you just add -r (reverse) to your flags, like so:

That command should show you files listed with the smallest ones first and that’s really all there is to this article. Well, there’s the closure section – but nobody reads those.

Closure:

And, well, this particular closure section won’t have anything truly interesting or different in it. After all, this is just a simple article that shows you how to sort files by size. ‘Snot that much more to it. ‘Snot that much more that I can add.

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.

Let’s Zip A Directory In The Linux Terminal

Today, we’re going to zip a directory in the Linux terminal. This isn’t a very complicated task, but it’s worth covering. It’s also not something you’re likely to do every day, but it’s bound to be useful to some of you. You’re eventually going to want to share a directory’s worth of files with someone!

Why zip a directory? This is Linux, we deal with .tar.gz!

Well, in the real world, you might just want to share files with other people. They’ll have no idea what to do with a .tar.gz file – but they’ll know exactly what to do with a .zip file.

More importantly, pretty much every operating system on the planet can open a .zip file. Even way back with the Amiga and Atari systems, you were able  to open .zip files.

As an added bonus, you probably already have the utility to compress files into .zip files and won’t need to install anything! So, you won’t need to install anything and you’ll be able to share the resulting files with pretty much anyone on the planet. What’s not to love?

Heck, you don’t even need to install an application on Windows or MacOS to open .zip files. As a quick test, I can even open them with a file management application on Android. I’m not sure if Android also deals with them by default or if it’s a function of the file manager. Still, you can open .zip files just fine on Android.

With all those great things, you might just as well learn how to zip a directory in the Linux terminal. I promise, it’s really easy.

Zip A Directory:

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.

Chances are very good that you won’t have to install ‘zip’ to get this to work. You can find out quickly enough by just typing:

That’ll likely tell you which zip and where it’s located. If not, you’ll need to install it from your default repositories. I expect very few people will need to do that.

Now to zip a directory…

You can also zip a directory recursively, by using the ‘r’ flag:

This is not to be confused with the R flag, which will recursively compress the files in the folder – but only those files that were specified, such as from this example command in the man page:

That’d take all the files in the current directory that ended in ‘.c’ and compress them into a file called foo. That’s not really what we’re after, nor is it what the article is about. Either way, while you’re exploring, be sure to check the man page. This is one of the biggest man pages you’ll likely come across and there are a ton of options beyond just simply letting you zip a directory.

Closure:

There you have it. You can now zip a directory – such as a directory of pictures to share with your loved ones who are still not using Linux. It’s not terribly difficult, but it’s a useful skill to have and you never know when you’ll want to share a bunch of files with other people.

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.

Change Ownership Of Files And Folders

Today, we’ll be covering how to change ownership of files and folders. This is a pretty basic task and one every Linux user should know. This needn’t be terribly complicated, so this article will explain all you really need to know about changing ownership of files and folders.

When dealing with file management, permissions are important. It’s a security matter and a usability matter. You can assign various file and folder permissions, such as read and write permissions, a subject for a different article. However, files and folders all should have owners – owners who can do anything they want with the file or folder.

Curiously, your account should not always be the owner. While maybe not all that intuitive, you shouldn’t have ownership of all the files. This is why you have to use elevated permissions to perform certain tasks. This is to keep things segmented and secure.

Remember, Linux is designed to be a multi-user operating system. That’s not just human users, but different processes and applications may also be associated with users. For example, look at all the users on your system by running the following command in your terminal emulator:

You can also see all the groups on your system with this command:

Obviously, if a user is a member of a group they share permissions with that group. Files also only have one owner and one associated group, of course. So, if you want two people to have control over a file, one way to do that would be to make sure they’re both members of the same group. There’s all sorts of creative things you can do with permissions. This article will be covering just one aspect, it’ll be about how you can …

Change Ownership Of Files And Folders:

Like oh so many of these articles, this one requires an open terminal. You can do so using only your keyboard – just press CTRL + ALT + T and your default terminal should open.

Go right ahead and stay in your home directory. You can check the various files and their permissions with the following:

The output of that command will show you the user and group, with the two being listed in that order as in the image below:

ll listing user and groups
See? I even gave you handy arrows. The order is owner:group, to repeat myself.

To change the owner, the format is:

To change the group, the format is:

If you want to recursively take ownership, you need the -R flag. For that, you’d want something that looks a bit like this:

You can actually just use chown to change both the owner and group at the same time. You’ll most often do this with your own user and group, so I’ll show the command that way:

As you can guess, the -R flag will work there and an asterisk will cover all the files and folders within that directory. Obviously, this applies to folders and not to files.

Closure:

There you have it. You have yet another article and this one has hopefully taught you how to change ownership of files and folders. It may not be one of the most interesting articles, but it’s a skill you’ll eventually want to have and another tool for your Linux toolbox. 

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.

Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.