Linux Guide

From Tux
Revision as of 23:11, 31 January 2019 by Sam (talk | contribs)
Jump to: navigation, search
This page is under construction

Introduction

This guide aims to provide common and useful Linux commands, popular Linux operating systems that you make encounter, as well as ways to accomplish tasks that you may encounter frequently.

List of popular Linux operating systems

  • Ubuntu - Common OS for personal use.
  • CentOS - Another common OS for personal use. CentOS is available in the TBE B-461 lab.
  • Debian - Yet another common Linux OS.
  • Raspbian - OS commonly used on Raspberry Pis for simple projects.
  • Android - The popular phone OS. May require a separate emulator.

Linux commands

List of common commands

For the sake of brevity and making things easier to find, we will not be going over every single command available in Linux here, but rather, a list of some of the more common and useful commands. For a good list of all Linux commands, you can follow this link. Remember that the man command will also bring up a manual for using Linux.

The command examples are formatted like:

  • command_name Description
Examples Description of example
  • command_name <parameter>
  • command_name -option

Bash

Bash is a shell for navigating an OS without the need for GUI. Bash is a part of the GNU Project, aiming to provide "free" software to aid in computing. Bash is available on most Linux distributions, as well as OSX (Mac) upon installing the OS. For more information, please see the embedded links provided above.

File and Directory

  • cat Used to display files, as well as concatenate two files together. Press the enter key to scroll down when viewing the file. For an extensive guide on cat, consider this link.
cat sample.txt Displays the contents of the file sample.txt
cat hello.cpp world.cpp Displays the contents of the file hello.cpp, followed by the contents of the file world.cpp.
  • cat <file1> > <file2> Writes the contents of file1 to the name of file2. This will overwrite file2 if it already exists. If you leave file 1 blank, you can use this command to create a new file.
cat input.txt > output.txt Moves the contents of input.txt to a file name "output.txt".
cat > newfile.txt Creates a new file called "newfile.txt". Type in the text you want to be in the file, and use CTRL+D to save.
  • cat file >> file2 Concatenates file1 and file2. File1 will be added to the end of file2.
File1.txt:
Hello World
File2.txt:
This is file 2 
cat File1.txt >> File2.txt Appends File1.txt to the end of File2.txt. File2.txt afterwards: This is file 2 Hello World
File1.txt remains unchanged.
  • cat -n <filename> Displays file with line numbers next to each line.
cat -n hmm.py


SSH

Grep

Sending emails

Miscellaneous

  • apt Advanced Package Management tool for Debian-based operating systems.
  • apt-get Advanced packaged tool get. Use this for installing packages.
  • apt-get install The option install will install the downloaded package.
apt-get install python3-pip Will install the pip package installer for Python3.
sudo apt-get install mysql-server Will download install the package mysql-server. (We'll cover sudo later)
  • apt-get update Re-synchronizes package index files from their source. Do this before doing upgrade.
sudo apt-get update
  • apt-get upgrade Upgrades existing packages, if there are newer versions to be installed.
sudo apt-get upgrade
  • apt-get remove
  • apt-get purge
  • apt-get -d Download the package, but don't install it.
  • apt-get -f Attempts to fix broken packages.
  • apt-get --force-yes Automatically chooses "yes" during installation.
  • apt-get -h Provides help for using apt-get
  • apt-get -m Ignore missing files
  • apt-get --reinstall Reinstalls packages that are up to date.
  • apt-get -v Shows the current version
  • autoconf Automatically configures software packages
  • sudo Super User DO. Allows you to execute a command with the privileges of a different user. Usually, this means executing the command with "super user" privileges; similar to administrator privileges in Windows. A lot of times, this will require a password.
sudo apt-get install python3 Installs Python3 with super user privileges.
sudo whoami Shows the user considered to be the "super user". This is usually the root.
  • whoami Tells you the current user you are.
  • yum Similar to apt. Used for downloading and installing packages.

Running programs and scripts

Changing permissions

Running scripts

Installing programs

Running Linux (Ubuntu) on a virtual machine

We have a tutorial for installing a running Ubuntu on the VirtualBox page. You should do this if you need to use Linux, but don't want to install it on your actual machine.