When you're interfacing with a Linux, CentOS or any other type of server remotely or through a screen attached to the server, it's always a good time investment to know some basic Linux commands to run through the terminal.
Whether you're new to servers or are more experienced with server commands, sometimes we simply forget commands, or just can't remember the order in which to type command line arguments.
When connecting to a Linux server remotely through what's called the shell, you're going to need to know some basic commands to perform actions such as navigation, creating directories and files and how to remove items (the equivalent of a delete via a GUI)
It's not always possible to have a screen connected to a computer, so in this post, I'm going to give you the essential commands that every user should know...
Ready? Let's dive right in...
When you're running commands on a server, you're going to need to run them through a command-line interface.
Accessing this is going to be different based on what server you're connecting to and how you connect to them, but the most basic way of accessing a server remotely and running commands is to use a popular tool for the OS you're on:
Applications -> Utilities -> Terminal
Start Menu -> Windows System -> Command Prompt
If you're on a Linux machine, chances are you already know where to find the terminal, so I won't be covering that here.
If you're trying to run Linux commands on a remote server, you're going to need to connect to it first through the terminal within your OS as described above.
Typically you can access a remote server if you know the server's IP address and the username and password of the server, in your terminal, run:
Of course, replace username and server_ip with the relevant fields. Depending upon what server you're trying to connect to and what commands you need to run, you might need to connect as a root user for your username.
Now that I've covered how to find your terminal and connect to the server, let's now go through the essential commands that every user should know.
If I miss some commands in this list, chances are it's because I'll be coming back to this post to add more! So check back soon if the command you're trying to find isn't here yet!
pwd command can be used to find what directory you're in and the path to that particular directory. It's useful for when you're trying to navigate through directories on your server and then you forget what directory you're in.
The command will return an absolute path which is essentially a path that starts with a trailing slash.
Whenever you're connected to a server and are interfacing with it through a terminal, you're going to need to list out all of the directories and files within a folder on your server.
Unlike being able to see all of the directories and files on your computer such as on a Windows machine through the explorer, you don't have this when connected through shell.
There are variations of the command, so here's a few of the basics:
ls -al- this command will list out all of the files, directories along with information about the size, owner and permissions of the file/folder. It's the command I tend to opt for a lot of the time
ls -a- will show you your hidden files/folders, useful for finding
ls -R- would list out all of the files and sub-directories
This command is likely going to be one of the most used commands that you'll use on a Linux server.
Unlike a system that has a fancy GUI to navigate between directories on a computer, the cd command will allow you to move between folders on your server.
Let's say for instance you're inside a directory located at: /var/www/myfolder and then you wanted to move up one level to: /var/www then you'd need to use this command for that:
By specifying the two dots, you're going to be moving up one level
If you wanted to move back into that specific folder, you could then run:
And it would put you into that folder.
Some other uses of the cd command include:
cd- on it's own which would take you straight to the home folder
cd-- (note the hyphen) which would simply move you back to the previous folder that you were in had you actually moved a directory
As a note with this command, it is case-sensitive, so be careful to type the folder path and command in just right as per the example above.
You can use the
mkdir command to make a new directory on your server in the same way that you would "right-click" and select "New Folder" on most computers.
It's an essential command to know since making directories and files within directories are likely going to be consuming another large chunk of your time when working with a Linux or CentOS server.
There's a few variations of this command, here's a few ways that you can go about using it:
mkdir Photos- this will create a Photos folder in whatever directory you're currently in.
mkdir -p Photos/2021- this command has the optional flag that will create a 2021 folder within the Photos folder
If you're creating directories on your server, chances are you're going to need to create files within them.
This is where the
touch command comes in handy, and it's incredibly simple to use.
All you need to do is run:
And this would create a file called index.html in whichever directory you're currently in.
Notification Contacts make alerting team members incredibly easy and simple, find out more about this new feature that we've released for all of our customers!Read more
Here at the Domain Monitor, we're delighted to announce that Pretty Purchases, a UK based E-Commerce website that specialises in selling handbags has joined our website monitoring tool, learn more and find out how you can get a 5% discount today!Read more
If you've ever received a notification from our website uptime monitoring tool, you'll know how scary it can be to find out your website is down, your stomach literally drops and you start to panic, is your website actually down? Here's what to do when your website goes down.Read more
Plus, more great content, product news and updates