This is a very basic list of common commands used when administering a Debian system, typed up for a friend who is just getting started with Linux administration.
List all files, even hidden ones:
Show where you currently are:
Change to a new folder:
Print out the contents of a file:
Edit a file:
Move or rename a file (renaming a file is just moving it with a new name):
mv <oldfilename> <newfilename>
Example moving and renaming at the same time:
mv /home/John/Documents/oldphoto.jpg /home/John/Pictures/oldphoto1.jpg
If a file or folder has certain types of characters in its name, such as spaces or $, you need to put ‘’ around the file name.
nano '/home/john/Documents/tax information.txt'
Files can be transferred to and from the server using SFTP. SFTP is very versatile, but this will describe the most straightforward way to use it.
To start the SFTP tool, use the same command as you would for SSH, but use the word “sftp” instead of “ssh”. For example, if the following is used to log into a server:
ssh -i ~/.ssh/mykey user@host
Then the SFTP tool would be started with:
sftp -i ~/.ssh/mykey user@host
When the tool starts, it acts as a connection between your machine and the server.
It simply waits for commands. There are four main commands that are most useful:
ls cd get put
ls to list the files on the server.
lls to list the files on your machine.
cd to change where you are on the server.
lcd to change where you are on your machine.
So, after starting the tool, you might use
cd to move to a location on the server where you want to upload files, and you might use
lcd to move to a location on your machine where you have files to upload.
Once you’re in place, you can use
put to upload files, and
put -R to upload folders.
You can use
get to download files and
get -R to download folders.
Here’s an example uploading
dog-picture.jpg to a website, with # in front of the explanations about what is happening;
# Start the tool $ sftp -i ~/.ssh/myserverkey root@example # Now the tool is started. Use ls to see what is on the server sftp> ls trash old-files notes # We realize this isn't where we want to upload to. We want to upload to the apache website folder # Use cd to switch there sftp> cd "/var/www/html" # Check what's there - to see if this is the right place sftp> ls blog index.html me-picture.jpg # We are in the right place # Now we want to see what is on our laptop sftp> lls Documents Downloads Pictures Videos # We know that we keep our website files in the Documents folder. Use lcd to switch there sftp> lcd Documents # List the files sftp> lls art my website school taxes # Here we see the folder 'my website', which we know has all the website files. # Switch into it sftp> lcd "my website" # List the files sftp> lls blog dog-picture.jpg index.html me-picture.jpg # Here we are! The folder where we keep our website files. # Now we can upload `dog-picture.jpg` sftp> put dog-picture.jpg # When it's done uploading, check to make sure it's there: sftp> ls blog dog-picture.jpg index.html me-picture.jpg # Now that we're done, exit sftp sftp> exit
Just remember these steps:
cdto get the server side in place
lcdto get your machine’s side in place
It might be helpful to have an ssh connection up in one window, and an sftp connection in another one. This makes it easy to switch back and forth between uploading/downloading files and doing things like moving those files around, restarting programs, etc. without having to log back in and out.
Run a command as administrator:
Example (works with almost any command):
sudo apt update
Change your password:
Change another user’s password:
Reboot the whole machine:
Power off the whole machine:
Check the resource useage of the machine:
apt update apt upgrade
Search for a package by name:
apt search <packagename>
apt search htop
Install a package by name:
apt install <packagename>
apt install htop
Managing system services:
systemctl restart <service> systemctl stop <service> systemct start <service> systemctl disable <service> systemctl enable <service>
systemctl restart apache2
View status of a service:
systemctl status <service>
systemctl status apache2