General Linux-CLI Guide
Definitions and Background
Linux generally refers to any operating system that uses the Linux/GNU Kernel (Kernel being the most basic part of an operating system that manages processes and system resources)
Ubuntu is a specific Distrobution (Distro) of Linux based on a different distro called Debian.
The main difference between many Distro's is the default software installed on said system, generally the most important one is it's default Package Manager which allows users to download virtually any software or program without needing to actually go onto the internet through a browser and download an installer.
For example, to download firefox using the apt file manager (Ubuntu/Debian Package Manager), you would enter the following command.
Now if your computer doesn't have a Graphical User Interface (GUI) installed, firefox is not very useful but if you did then you would have installed the complete program with one line of text.
Navigating the Command Line Interface (CLI)
When you login to a linux server (or open a terminal window if you have a GUI) you will be greeted with something called a prompt, this is where you will type in your commands.
The prompt tells you (usually) main 3 things, first is your username, second is your computer hostname, third is your current directory.
For example, in the context of wsprdaemon this would be your general prompt.
The : and $ separate the different sections. Text will be entered after the $
File System Structure
/Home
~ is shorthand for your current user's home directory (Equivilent to C:\Users\MyUsername\ on Windows) Also directory is a synonym with folder in the context of computers
The actual directory path for ~ in our case would be /home/wsprdaemon
So wsprdaemon@hostname:~$ is equivalent to `wsprdaemon@hostname:/home/wsprdaemon$
Root "/"
You may be confused at the lack of a drive letter if you are used to Windows where the main OS drive is labled as C:\. This is because Linux (and MacOS) do not use drive letters, instead it will mount additional drives to directories/folders which will act identically as if they were any other directory. The operating system itself is mounted to the "root" directory denoted by a forward slash /. All other drives, and directories connected to the computer are accesed by changing to a sub-directory of the root directory. This is why all file paths will begin with / Eg. /home/wsprdaemon The home folder generally is located on the same drive/partition as the root directory, however, this is not always the case as separating them can help prevent corruption.
/mnt
If you connect an external drive or flash drive to linux it will usually be mounted in the /mnt directory Note it can actually be mounted anywhere you want but external drives are conventionally placed here so it is understood to be an external drive and not a normal directory
In MacOS, drives get mounted to the /Volumes directory for the same reason.
/bin
/bin is where system-wide Binary Executables (.exe equivalent files) are stored, basically any program you install will have its executable program file stored here. System-Wide meaning all users can access the program. (Kind of like installing a program in windows for all users which requires Admin permission, and will install the program into the C:\Program Files (x86) folder for 32-bit applications and C:\Program Files for 64-bit applications)
Some programs that are installed by a user without administrative permissions will instead store their executable file in /usr/bin/ (Which is kind of like installing a program in windows for only one user vs system-wide which will install the program into the user's appdata folder)
Most files you may see that do not contain a file extension, are generally a program executable file on Linux. Although, executables could have any file extension but it is convention to leave out any extension to denote an executable.
/dev
Like the /mnt directory that allows drives to be mounted as if they are a directory/folder. /dev refers to a hardware device which could be anything (including our rx888 radio reciever used for wsprdaemon). You will usually see /dev instead being used in the context of unmounted disks/partitions as to mount a partiton you need the device name. For example /dev/nvme0 refers to the entire disk, while /dev/nvme0n1p1 just refers to the first partition on the disk.
NVMe is a SSD protocol usually used with the M.2 connector which is also what many people call these types of drives You may also see \dev\sda representing older SATA or SCSI interfaces used in mechanical 2.5" and 3.5" HDDs or some older 2.5" SSDs.
/etc
/etc is where most System-Wide program configuration files are stored to configure and modify programs operation.
There is also a user equivilent /usr/etc for non-system-wide program installations.
/usr
Despite its name, do not confuse /usr to the C:\Users directory in Windows, as this is where non-system-wide programs are installed for specific users (closer to the appdata directory in Windows).
/tmp
As it's name suggests, this is a directory for temp files or cache files which can be deleted when not in use anymore.
/run
/run stores information regarding currently running programs.
/var
/var stores other data files, including logs and cache files.
There are other top level directories but these are the main ones you may see referenced regularly.
Commonly Used Commands
Print Working Directory [pwd]
You can double check which directory you are in by entering the following command pwd which stands for "print working directory"
Which will output
Make Directory [mkdir]
As its name suggests, use this command to create a directory. If you do not specify a full path to the directory from the root directory, it will assume you are operating in the same directory you are working in.
will, create the directory /home/wsprdaemon/test or usually denoted ~/test
List [ls]
This command will print all directories and files in your current working directory.
Utilizing the previous example,
will print out
Adding a path after typing in ls will list the contents of the specific directory.
Eg.
Will print out something like this,
Directories, files, and executables will all usually be colored differently in the command line to denote the difference.
Adding in the -a flag will also include hidden files **hidden files generally will begin with a period, Eg. ~/.config which is a common hidden directory in the user's home folder that usually contains specific configuration files for customization. This directory will not show up unless you add the -a flag ls ~/ -a for example.
Change Directory [cd]
To change you directory you can enter the command cd to "change directory".
so,
will move you into the ~/test directory. so this is what the terminal would look like.
Remove [rm]
This command will delete a file or directory.
To do so, run rm then then name of the file you would like to delete.
To delete a non-empty directory use the -r flag to recursively delete
If directory ~/test contains ~/test/test1.txt
Will delete both the directory ~/test and the file ~/test/test1.txt
You may also need to add the -f flag if a file is in use or is write protected (excluding permission blocked items)
If you do not own the file however, you need to use sudo (pronounced sue doh) to run the action as the root user (equivilent to the administrator user on windows), an account with access to sudo is called a Super User. So, sudo stands for Super User Do.
Eg.
Will erase the directory ~/ImportantTest without any care for what is inside ()
touch
touch is used to create an empty file.
So,
will create an empty text file named test.txt in your current directory.
echo, >> and |
Echo is equivilent to the print command in python, so echo "test" will print out text.
This may seem redundant but it is used in scripts to display information to the user when you run it, or you can use it in combination with other things like the stream operator [>>] to insert text into a file.
Eg.
Will create a file named test.txt with the text Hello World! inside it.
The stream operator is useful if you have a command that outputs too much text which causes some of the output to get cut off as you can use it with any command and the output will be passed into the file.
Eg.
will insert the output of the command ls ~/ into the text file test.txt
The pipe operator | is similar, however, it instead allows you to use the output of one command as the input of another.
Eg.
Will open the output of ls ~/ in the program less which is a program used to view text or text documents without editing them, and includes scrolling support.
cat
Running cat and appending the command with a text file name will print the contents of the file into the terminal.
Eg.
will print out the content of test.txt straight into the console.