Linux is an operating system kernel. Different distributions of Linux build on top of this kernel to create a full-fledged operating system (OS). Some examples of a Linux distribution are:
If you want to install a Linux distro on a personal machine, Ubuntu works perfectly for our purposes. If you want to try something different, feel free to check out Kali. If you're up for a challenge, try to install Arch on your system — for beginners, it often takes an entire day because of how barebones it is. I personally use Arch because I came to enjoy its lightweight nature.[1]
Normally, to open Google Chrome, you click on the icon on your taskbar. However, another way you can do that is by using a terminal, which is a text-based interface for your computer. With a terminal, you can do almost anything you can do with a graphical user interface (GUI), and there is much more that you can do with a terminal that you can't do with a GUI.
While terminals may look different, they all serve the same functionality so you can pick any one to use. The one that comes pre-installed with your system is likely more than usable, so feel free to stick with that one. I personally use kitty because it was recommended to me by a friend, and I enjoy the user experience. 🙀
When you open a terminal, a program called a shell is opened. The shell takes your commands and gives them to the OS to perform. While there are many different shells available, the most popular is bash, which comes pre-installed in most Linux distributions.
Open a terminal window, type in ls
, and hit the Enter button. This will run the command to list all the files and directories in the folder that the command is run in.
Generally, the shell is, by default, opened in the current user's home directory[2], which hosts all the folders and files that the specific user owns. A shortened way to refer to the current user's home folder is ~
.
A non-exhaustive list of common commands is written below:
Command | Description |
---|---|
ls |
List directory contents |
pwd |
Print the full path of the current (working) directory |
cd |
Move to another directory |
cat |
Print the contents of a file |
cp |
Copy a file/folder from one location to another |
mv |
Move a file/folder from location to another |
mkdir |
Create a directory |
rm |
Delete files/folders |
clear |
Clear the terminal display |
nano |
Open a (relatively) user-friendly command line text editor |
echo |
Print the proceeding argument |
Note that many of these commands have various options associated with them, so you might run something like:
This command lists all the folders and files located in the user's home directory (~
) in a long format (l
), not ignoring hidden files (a
). To view a full description of a command, you can use man <command>
.
At this point, I advise playing around with a terminal. Try to create a file, edit it, and copy it to your home directory.
The creators of Linux acknowledged that some folders will likely be accessed more often than others, which resulted in the creation of several useful shortcuts:
..
means the directory that the current directory is located under.~
means the current user'sAlthough this one isn't a shortcut, the "root" folder can be accessed at /
. This root folder contains every folder and file in the filesystem. The filesystem has a "tree" structure, meaning folders are stored in other folders, and files are also stored in folders.
The CLI can also be used to run many other tools and programs. For example, you may have seen nc challenge.tjcsec.club 31101
on one of our challenges. This is actually another CLI command, which actualy connects to a server (challenge.tjcsec.club) on a specified port[3] (31101).
A non-exhaustive list of commands that are less common to every day Linux users can be found below:
Command | Description |
---|---|
nc |
Establish a connection to a server |
grep |
Search for a file that has contents that matches a specific pattern of characters |
file |
Print the file type of a file based on its contents, not the file extension |
strings |
Print the "printable" bits of text of a file out |
find |
Print out the files that match a certain specified criteria |
The last four commands listed are often used for file forensics, the analysis of files and their contents. This is tricky to lay out in text, so you may need to try them out yourself to get the hang of them.
Notice how three of the verbs in the table above are "print." This printing doesn't have to mean "output to the console." Like the printing system on your computer, you can "print" to many different places, including files and other commands.
To redirect output to a file (that may or may not already exist), use >
:
If, instead, you want to append to the end of the file (that may or may not exist), use >>
:
Additionally, you can take input from a file using <
:
To send the output of one command to another command, you can pipe it using |
:
In Linux, files and directories have various permissions that are specified in order to control access to said files and directories.
There are three groups of people that could possibly access the file/directory:
The file owner, as you may guess, owns the file/directory. To change the file owner, use the chown
command:
The file group is a uniquely-defined group of users allowed to access the file a specific way. In Linux, they also have many other purposes in access control, but they are mostly unnecessary to know. To change group ownership, use the chgrp
command:
All other users that are not the owner or in the group are relegated to "other" permissions.
There are three permissions for each category of users: read (r
), write (w
), and execute (x
). The first two permissions are pretty self-explanatory; however, the execute permission might be a little new.
The execute permission lets you run a file using the following notation in the terminal:
If, for example, you have a machine-code program that you want to run on your computer, you must first ensure that your current user has execute permissions. To change any and all permissions, use the chmod
command:
The above command adds the execute permission to the owner of the file or directory.
You may want to change the access permissions of a file because you have "other" permissions. It wouldn't make sense for just anyone to be able to do that, so how would you do that?
Like other operating systems, Linux also has system administrators. If you prefix any command with sudo
(and a space), it will run the command as the superuser, also known as the root or admin user.
If you wanted to change access permissions, you could run:
To install new programs on a Debian-based distribution (including Ubuntu), use the apt
command. You will need to prefix it with sudo in order for it to work properly, like so:
We went over a long list of commands in this document, and there are many more that I deem useful, but not useful enough to fully explain. Because of that, we have created a (non-exhaustive) live list of important shell commands that you can refer to at https://hackmd.io/@tjcsc/cmd.
As always, if you have any questions, feel free to contact us by:
Happy hacking!
At the time of writing this, I have eight Chrome tabs, Visual Studio Code, MATLAB, Discord, and Spotify open on my laptop. Only 7.5 GiB of memory is in use, which is a large difference from my Windows machine that used 8 GiB just to run the OS. ↩︎
Folders and directories refer to the same thing — a space used to store other files and folders. ↩︎
A port is a connection endpoint for a different service. Think of a computer like a house address and a port like a specific person that lives at that address. ↩︎