Linux Basics Tutorial
Credit to kunherdm for writing this awesome tutorial! Things might have changed since Spring 2018 (this was most recently updated on 4/19/18), it is provided for historical purposes.
- 1 Background
- 2 Ubuntu Basics
- 3 Using Bash
- 4 Users and Permissions
- 5 The Filesystem
- 6 Using the Package Manager (apt/apt-get)
- 7 Useful Command-Line Utilities
- 8 Conclusion
This tutorial is intended to help bring you from the point of knowing nothing about how Linux works, to being able to effectively use Linux for most applications, or at least give you a basis to learn more elsewhere. We assume you have already installed a Linux OS, perhaps at an Installfest event. It also assumes you know the basics of computer use in an OS like Windows. The information in this tutorial is specifically tailored to the Ubuntu distribution of Linux, but if you have a different one, the instructions given here may still apply.
The standard Ubuntu interface is set up to make it easy for you to launch and manage applications without needing to worry about using the console. Of course, if you choose to use the console, you are able to do a lot more with the inner workings of your computer, and make your daily computer use much more efficient. Most of this tutorial regards this more complex form of Linux use, but if you just want the very most basic computer experience, you can just use the standard interface. This section will explain the basics.
The Application Menu
The application menu is where you can launch new applications that are not currently running. You can also use it to search for files on your computer. You can think of it like the "Start" button in Windows. The button to launch the application menu is located on the sidebar, and depending on the version of Ubuntu you use, it could either look like the circular Ubuntu logo, or a grid of 9 dots (similarly to a generic "app menu").
From here, you can see recently used apps, or type a keyword to search for applications or files. Ubuntu will sort files and applications by category.
General Use Applications
The following are some applications that the typical Ubuntu user might use. These all happen to be pre-installed with Ubuntu, but if you want, you can install different software and use that (more on that later):
- Firefox - A popular web browser.
- Thunderbird - A desktop email client by the makers of Firefox. Note: Thunderbird may not play well with Rose-Hulman's exchange server, so if you have trouble connecting it, Evolution is a nice alternative.
- LibreOffice - An office suite with apps for documents, presentations, and spreadsheets. Similar to Microsoft Office, but without all of its fanciest features.
- Files - Ubuntu's built-in file browser, follows most of the same conventions as Windows Explorer (e.g. ctrl+c to copy, ctrl+v to paste, shift+del to permanently delete, etc).
The Ubuntu Software app is a tool to easily search for and install new software, similarly to an app store on other OS's. You can use this to install alternatives to pre-installed software (like Google Chrome), or software for completely new uses (like Spotify).
From this point on, we will start to get into more complex Linux use. The tools listed here are powerful enough to greatly enhance your experience using Linux, or if you're not careful, you can accidentally harm your computer, perhaps even permanently! If you have any doubt as to whether a command will have any unintended consequences for your system, feel free to ask any member of RHLUG for help or advice.
Bash, or the Bourne Again Shell, is the standard tool for interacting with your computer through a text console. Because it uses text commands for everything, it can easily be used to specify the exact behavior you want, or even automate commands!
In this tutorial, we will give console commands in the following format:
The "$" sign here indicates that this is a console command, and will likely appear as a console prompt before you type in the real command. So, if you're copying the command into your own console, you should omit the "$" and the space that comes after it.
Also, we will be using the words "Bash," "console," "terminal," and "shell" interchangably. There are technical differences between these terms, but for the purposes of this tutorial, the differences aren't very major.
To open a console window in Ubuntu, click the "Console" button on the sidebar, or press Ctrl+Alt+T.
The Working Directory
Navigation in Bash (and any type of command-line interface, really) is based on the concept of a "working directory," the folder you are thought to be "within" at the moment. Your working directory is often shown in the terminal prompt, before the "$" symbol. When you first start up a terminal in Ubuntu, the default for the starting working directory is "~", which is a symbol that evaluates to your "home" directory, which can be thought of as your personal user folder (more on that later).
When you execute commands that take a filepath (such as
rm, which deletes a file), those filepaths are relative to your working directory. So, if you want to delete "~/filetodelete.txt", and your working directory is "~", you can simply type:
$ rm filetodelete.txt
and Bash will know you mean the file in the ~ directory.
The following commands and symbols are used to navigate directories:
- pwd (or print working directory) - Prints the working directory to the console.
- cd (or change directory) - Changes the working directory to the one given as an argument. If your working directory is "~", and you execute
$ cd myfolder, your working directory will now be "~/myfolder/" (assuming that folder exists).
- . - A symbol that evaluates to the working directory. You can use this to, for example, run an executable file in the current directory:
- .. - A symbol that evaluates to the parent of the working directory. If your working directory is "~/myfolder/", and you execute
$ cd .., your working directory will now be "~".
Other Useful Bash Commands
The following commands are used for simple operations from the command line:
- ls (or list): Lists (non-hidden) files and folders in the working directory, or in a directory given as an argument. It is common to use this with the arguments "l", "a", and "h" to show hidden files, show more details on the files, and print the results in a nicer format:
$ ls -lah
- mkdir (or make directory): Creates a new directory in the working directory, with the name given in an argument
- rm (or remove): Deletes a file or directory in the working directory. If you are deleting a non-empty directory, you will need to use
rm -rfto tell it to delete the entire tree recursively, and force it to delete, even though there are files there.
- mv (or move): Moves a file or directory given in the first argument, to the directory given in the second argument.
- cp (or copy): Copies a file or directory given in the first argument, to the directory given in the second argument.
- cat (or concatenate): Prints the contents of a file given in an argument, to the console.
- echo: Prints the fully-evaluated form of the argument given. For example,
$ echo ~prints the fully-evaulated form of your home directory, which is likely "/home/[your username]"
Special Bash Tools
The following symbols can help make working in Bash easier:
- !!: Evaluates to the previous command you entered. You can also add on other text. So, for example,
sudobefore your previous command, and runs it. The use of
sudowill be discussed later in this tutorial.
- &: Putting this at the end of a command will run that command in the background, meaning you will be able to keep using the same shell to do other commands, while the current command is still running. This is useful if you want to launch an application from the command line, but don't want to be locked out of Bash while it's running.
- &&: This lets you run two commands in one. For example,
$ echo firstcommand && echo secondcommandwill output the two arguments, each on its own line.
- >: This will take the output of a command on its left, and put it into a file specified on its right. For example,
$ echo hi > tmp.txtwill put the word "hi" into the file tmp.txt, creating it if it doesn't exist.
- |: This will take the output of a command on its left, run the command on the right, and feed that output into the right command's input. This is a more complicated one, but it's particularly useful for commands that look for "matches" of a pattern in some block of text, like
- *: This is the "wildcard" character, acting like a keyword that matches anything. For example,
$ rm *will remove all files from your working directory.
$ rm *.txtwill only remove files ending in ".txt".
Users and Permissions
The permission system in Linux is very useful, as it allows for more specific restrictions than in an OS like Windows. Instead of users being either normal users or administrators, there is only one administrator account, called "root". The root account has total control over the computer. The main idea behind this is that no one will ever log in directly as root. Instead, normal accounts can be added to a list called "sudoers". Accounts in this list have access to a command called "sudo" (or superuser do) that allows them to perform an action "as root". This is similar to running something as an administrator in Windows.
To be able to do certain actions, such as editing a protected file, a sudoer user can append
sudo to the beginning of the command. This will prompt them for their own password, and when they enter it, the command will be run as root. Then, once the command is completed, they are back to their normal user status. This makes sure that users don't accidentally do any actions as root that they don't intend to.
Actual permissions for what files can be modified (and by whom) are also slightly different than in Windows. Any file or directory has three permissions associated with them (read, write, and execute), and those permissions can be associated with a particular user, a user group, or all users.
chmod changes the permissions of a file or directory. You can either add or remove individual permissions (+x, -w, etc), or supply a number that, when each digit is translated into binary, results in a bitstring representing the permissions. For example,
$ chmod 777 myfile allows all users to do everything with myfile, as all the bits will be 1.
Files and directories can also be "owned" by a user. The "user" set of permissions specifically applies to the owner of the file. So, if you want a file to only be accessible by a particular user, you can use
chown to change the ownership, and
chmod to change the permissions to 700 (i.e. full permissions for user, no permissions for anyone else).
The way files are stored in Linux is somewhat different from how it works in Windows. The idea of files and directories is the same, but at the top level, there are some major differences. In Windows, the top-level file structure is a drive, like the C drive. In Linux, the physical drives don't actually hold the top-level position in the filesystem. Instead, there's a single root directory, called "/", that is the top-level directory for the filesystem. Below that are all the directories that make up your system.
One of the most important directories is "/home/". This directory contains the home directory for each user on the system. For example, "/home/my_user/" is the home directory for my_user. This directory is that user's main location for documents and other user-specific data. In bash, the symbol "~" evaluates to the home directory of the current user. For example, if you are logged in as my_user, and execute
$ cd ~, your working directory will change to "/home/my_user/".
The following are some useful directories on your system to know about:
- /bin/: Contains executables, or binaries, for software that's used by all users on the machine.
- /tmp/: A useful place to put temporary files that you're currently working with. This directory is emptied every time you reboot your computer, so be careful to not put anything important in there!
- /etc/: Contains configuration/options files for software on the machine.
- /usr/: Often contains data that software needs in order to run.
Using the Package Manager (apt/apt-get)
One of the most useful functions of Linux is the use of package managers. This is a way of installing software that is very different than in Windows. The idea is to automate the updating of software and the management of software dependencies. So, if you want, you could theoretically update all the software on your machine at once.
This is done through keeping track of all the software, or "packages", installed on your machine. So, installing software is done through the package manager. Then, you can run a single update function, and the package manager will go through and update everything it's keeping track of.
The package manager used in Ubuntu is called "apt" (formerly called "apt-get" - the usage is entirely the same; apt just looks nicer). Following are some useful commands that use apt:
NOTE: apt requires that it is run as root, so all of these commands should have "sudo" before them.
- apt install: Installs the package given as an argument.
- apt remove: Uninstalls the package given as an argument. Does not uninstall dependencies for that package, in case other packages need it.
- apt update: Downloads information on what upgrades are available for packages. Does not actually perform those updates.
- apt upgrade: Updates all software that it has new updates for. You'll typically want to run
$ sudo apt updatebefore this so that you'll have the most up-to-date updates.
- apt autoremove: Uninstalls all dependencies that are no longer needed for packages you've installed. For example, if package x depends on package y, and you remove package x, you can use
$ sudo apt autoremoveto remove package y.
- add-apt-repository: Adds a new location to look for package information. apt comes with a preinstalled set of standard repositories, but to extend the amount of software you can install, you'll need to add new repositories.
Typically, if you want to install something from online (and it's available for Linux), it will have code snippets you can run to use apt to install it.
Useful Command-Line Utilities
Following are some useful programs you can run at the command line for various purposes:
Command-line editors are useful for making quick edits to files without making any new windows.
- nano: The most "modernized" common command-line editor. You can navigate through a file using the arrow keys, and type your changes just like you would in a notepad software. Also comes with a list of keyboard shortcuts that always shows up at the bottom (The ^ symbol means "ctrl+").
- vim (or vi): Useful for making complex changes in large files. Has a harder learning curve than nano, as it uses different "modes" with different keybindings.
- emacs: Has keybinds optimized for quick navigation through files.
- top: Shows you information about your system as a whole, and processes running on it. You can install "htop" to make this look nicer.
- man: Shows you the manual for a given Linux command. Very useful for if you're not sure how something works or what arguments it needs.
- grep: Searches through text to find matches. Useful for if you have a very large result of a command, or a very large file, and want to find a specific part, or a part about a specific keyword.
This document was intended to give a full basis for a wide variety of uses of Linux. If you have any further questions, or are confused about anything on this page, ask anyone in the Rose-Hulman Linux Users Group.