Switch Audience
Your First Linux Commands
Take a moment. You built a server. You installed an operating system, configured a static IP address, and you are connecting to it from your workstation over SSH like you have been doing this for years. That is not nothing. A lot of people who call themselves web professionals have never done what you just did.
Now we need to talk about the command line.
If you have spent your career on Windows or Mac you have probably avoided the command line as long as possible. It looks austere. It offers no clues. It does not forgive typos with any grace. All of that is true and none of it matters as much as you think it does, because the command line is also the most direct conversation you will ever have with a computer. You say exactly what you mean. The computer does exactly what you said. The problems only start when what you said is not quite what you meant.
This is not an exhaustive guide to Linux. It is a survival kit — the commands you will actually use managing a dev box and building a LAMP stack. When you need something beyond this primer your AI assistant is a genuinely useful resource. Describe what you are trying to accomplish and ask for the command. That is a completely legitimate way to work.
Moving around
Your command prompt tells you where you are — you will see your username, your server name, and a tilde (~) which means you are in your home directory. That is your default landing spot every time you connect.
- `ls` — list what is in the current directory - try it in your terminal
- `ls -la` — same thing but with hidden files and details like permissions and ownership. You will use this one constantly.
- `cd directoryname` — move into a directory
- `cd ../` — move up one level
- `cd ~` — go back to your home directory from anywhere
Managing files and directories
- `mkdir directoryname` — create a new directory
- `cp filename destination` — copy a file
- `mv filename destination` — move or rename a file
- `rm filename` — delete a file
A word about `rm` — it does not ask for confirmation and there is no recycling bin. What you delete is gone. Type carefully.
Editing files with nano
Nano is the text editor you will use to edit configuration files on your server. It is straightforward and it lives in an alternate universe where two keyboard shortcuts mean something completely different from everywhere else you have ever worked.
- `nano filename` — open a file for editing
- `Ctrl+O` — save the file
- `Ctrl+X` — exit nano
- `Ctrl+V` — A word bout `Ctrl+V` - you have been using it since grade school to paste content - nano is the only place in the universe where `Ctrl+V` means - go to the bottom of the page - no one ever needs to go to the bottom of the page - you can scroll. You will try to paste something into your nano editor and the page will jump. To paste into nano you right click your mouse
- `Ctrl+W` — This is how you find things - not `Ctrl+F` - every where else in the universe `Ctrl+W` means close the window - you are in nano and nano exists in an alternate universe.
It is comfortable in the alternate universe once you settle in. The commands are listed at the bottom of the nano screen at all times so you never have to remember them from scratch.
Running as an administrator
Most of the interesting work on a Linux server requires administrator privileges. The `sudo` command — Superuser Do — puts in front of any command to run it with full administrative authority.
sudo apt install somethingYour server will ask for your password the first time you use sudo in a session and then remember it for a few minutes. This is normal.
Keeping the system updated
Two commands, run them together, run them regularly:
sudo apt update
sudo apt upgrade`apt update` refreshes the list of available software and updates. `apt upgrade` actually installs them. The first one without the second does nothing useful. Think of it as checking the mail and then actually reading it.
A word about updates - they should be run weekly - the longer your server goes with out updates the more chance there is that you will have problems - a good clue is to run updates when you change your underwear.
Installing software
sudo apt install packagenameThat is how software gets onto your server. We will give you the exact package names when you need them.
Managing services
Apache, MySQL, and PHP all run as services — background processes that start when the server boots and keep running until you tell them to stop. The tool that manages them is `systemctl`. We will give you the exact commands each time you need to start, stop, restart, or check the status of a service. For now just know that systemctl exists and that it is how you talk to the things running in the background.
Your network address
ip addressThis is how you find out what address your server is on. You already know this one.
A word about permissions
Every file and directory on a Linux server has an owner and a set of permissions that control who can read it, write to it, or execute it. Two commands manage this:
- `chmod` — change what a file's permissions are
- `chown` — change who owns a file
Here is the warning you deserve before you need it: permissions will drive you quietly insane at some point during this journey, and the reason is that you and your Apache web server are going to spend a lot of time fighting over who owns what. You will create a file as yourself. Apache will refuse to touch it because Apache runs as its own user — `www-data` — and your file belongs to you, not to Apache. Or you will give Apache what it needs and then find you can no longer edit the file yourself. This is not a bug. This is Linux doing exactly what it is supposed to do. We will deal with it in detail when we get there. For now just know that when something mysteriously refuses to work, permissions is usually the first place to look.
Cleaning up the screen
clearWhen your terminal is full of output and you want a clean slate. That is all it does. It is oddly satisfying.
Rebooting the server
You will be rebooting it often - after some updates - after some config changes - if you shut the sever down, you will have to dig around in the closet to find it and push to on button.
sudo reboot 0
There are entire college courses dedicated to Linux commands - these few will get you stumbling along, your AI assistant will help and in time you will know the ones you need to use - honestly that's all you need to know. If you don't use it, you don't need to know them - I personally take great pleasure in all the things I don't need to know.