Run the commands as the root superuser from the command line.
First, let's look at the list of the main commands for managing the server.
Restart the web servers:
# /etc/init.d/apache2 restart
# /etc/init.d/nginx restart
Check which OS is installed on the server:
# cat /etc/issue
Reboot the server:
# reboot
Restart cron:
# /etc/init.d/cron restart
Add a new user sokar to the server:
# adduser sokar
Set a password for the user sokar:
# passwd sokar
List of the simplest and most essential Linux commands
Search the entire server for a file named file.txt:
# find / -name file.txt
Check the PHP version on the server:
# php --version
See which users are currently active on the server:
# w
Show which folder we are currently in:
# pwd
Show the list of files in the current directory:
# ls -l
Go to the server's root folder:
# cd /
Show information about disks, partitioning and free space:
# df -h
Show how much disk space a folder occupies:
# du -sh /home/igumnov
Linux commands for working with archives
Pack the specified backup folder into the file archive.tar.gz:
# tar cfz /path/to/archive.tar.gz /path/to/files/to/backup/
To extract archives in tar, tar.gz or .tar.bz format:
# tar xvf arhiv.tar
To extract archives in zip format:
# unzip arhiv.zip
Linux commands for copying and setting permissions
Copy a folder from one server to another:
# scp -r user@server1:/var/www/ user@server2:/var/www/
Set the user sokar as the owner of a domain, its folders and all subfolders:
# chown -R sokar:sokar /var/www/master-server.pro
Set 755 permissions for a domain, its folders and all subfolders:
# chmod -R 755 /var/www/master-server.pro
Linux commands for MySQL databases
Copy a file from another server into the current folder:
# wget http://domen.com/file.zip
Make a backup (dump) of a MySQL database into the current folder (the one the command is run from):
# mysqldump db_name --user=db_user --password=db_pass > backup_dump.sql
Notation:
db_name - database name
db_user - database user
db_pass - database password
backup_dump.sql - backup file name
Import a MySQL database from an existing dump. Run the command from the folder where the database backup is located (it will ask for the database user's password):
# mysql -u username -p database < my_dump.sql
Notation:
username - database user name
database - the database into which the dump should be imported
my_dump.sql - the dump itself (this backup file is imported into the database)
Linux commands for deleting files and folders
Delete all files, folders and subfolders in the current directory:
# rm -r *
Recursively delete everything in the specified directory:
# rm -rf /path/do/dir
Delete the specified file in the current directory:
# rm -r /file.php
Linux commands for working with processes
Display a tree view of all processes on the server:
# ps axf
Display a list of processes whose name contains "php":
# ps ax|grep php
Kill process 123
# kill -9 123
Kill all processes whose name contains "php":
# killall php