Basic Linux commands to get around and perform common tasks.
General
Get help with any command:
man (command name)
Run a command as super user (“super user do”) if your account does not have superuser privileges :
sudo (command name)
Check distro name and version:
cat /etc/os-release
Display free space (human readable):
df -h
Show server CPU/RAM usage in real-time. Press E once in top to cycle through displaying RAM into different ways (MB/GB/TB):
top
Show list of running services. Different distros can have different commands but try listing the contents of init.d which is list of the services on the system. The name of the service should match what’s listed in init.d.
ls /etc/init.d/
Stop, reload configuration, restart and start a service. Replace (service) with the name of the service you want to restart:
sudo systemctl stop (service)
sudo systemctl reload (service)
sudo systemctl restart (service)
sudo systemctl start (service)
Reboot (no warning – reboots immediately):
sudo reboot
File/Folders Operations
Displays the contents of a folder as a list and includes including permissions and size (human readable):
ls -lh
Create a file called example.txt:
touch example.txt
Rename a file called example.txt to example2.txt:
mv example.txt example2.txt
Edit the example2.txt in a text editor:
nano example2.txt
Create and then remove a folder called ACME:
mkdir ACME
rmdir ACME
Copy a file called example2.txt into a folder called ACME:
cp example2.txt ACME
Move a file called example2.txt into a folder called ACME:
mv example2.txt ACME
Apache
Restart Apache:
sudo /etc/init.d/apache2 restart
List any issues found with Apache’s configuration:
apachectl configtest
List virtual host configuration:
sudo apache2ctl -S
Enable or disable a configured site. Press tab after the command to see the list of available sites:
a2ensite (configuration file)
a2dissite (configuration file)
Enable or disable a module. Press tab after the command to see module names:
a2enmod (module name)
a2dismod (module name)
Jason works as a project specialist at an IT MSP in Pennsylvania, USA. He’s an IT/security professional with 20 years experience.