Basics of Linux

Downloaded from:

Files and Directories

Command Description
cd Change directory to some other location
pwd Show the present working directory
ls List all the files in a directory
ls -l List all files and their details (perms, owner, size, mtime, etc)
ls -a List all the files in a directory (including hidden files)
file View the type of any file
touch Create a new, empty file, or update the modified time of an existing one
cat > file Create a new file with the text you type after
cat file View the contents of a file
grep View the contents of a file that match a pattern
nano file Open a file (or create new one) in nano text editor
vim file Open a file (or create new one) in vim text editor
mkdir Create a new directory
rm or rmdir Remove a file or empty directory
rm -r Remove a directory that isn’t empty
mv Move or rename a file or directory
cp Copy a file or directory
rsync Synchronize the changes of one directory to another
ls -la /dev/disk/by-id/usb-* Retrieve a list of USB device files
echo print text or variables
sha512sum prints 512-bit checksums on files
sha256sum prints 256-bit checksums on files
tar xvzf Extract tgz file
tar cvzf Create compressed tgz archive file
evince GNOME document viewer - for PDF files

Networking Commands

Command Description
ip addr Show IP address and other information for all active interfaces
ip r Show IP address of default gateway
cat /etc/resolv.conf See what DNS servers your system is configured to use
ping Send a ping request to a network device
traceroute Trace the network path taken to a device
ssh Login to a remote device with Secure Shell client

File Permissions and Ownership

Command Description
chown Change the owner of a file or directory
chgrp Change the group of a file or directory
chmod Change the file permissions for a file or directory

User Management Commands

Command Description
useradd Low level utility for adding new user accounts
adduser High level utility for adding new user accounts
deluser Delete a user account
usermod Modify a user account
groupadd Create a new group
delgroup Delete a group

Trying things out

The symbol ~ is called the tilde, and is the key directly below the esc or the escape key, which is located at the very top left of a keyboard, you must hold down the shift key to make the tilde. In Linux, the tilde may be used as a short-cut to your home directory which is stored in a variable named $HOME.

To run this execrise open a Terminal Window. If a program running is shown on the screen and the Desktop is hidden, either minimize it, or press the following keys (Windows + d) to hide/show Applications... now that your Desktop is in view the Easy way to open a Terminal Window is to Right click on the Desktop when no applications are running, then Left click Open in Terminal. Other ways are: by keyboard shortcut for Ubuntu: pressing down on the keys ctrl+alt+t or Tails/Linux press the Windows symbol on a typical keyboard and search for Terminal of some kind.

Insert any safe USB disk drive device such as a USB Flash drive (something that you own, be careful of strangers drives as they can damage your computer or infect it).

# To see the contents of $HOME you can echo it out. Try it out below.
$ echo $HOME
$ cd ~/Downloads
$ pwd
# your in the /home/$USER/Downloads folder now.

# Let see if you have any USB drives mounted, if so the folder name will be displayed:
$ ls /media/$USER
$ ls -l /media/$USER
# See the extra permissions now and who owns the folders.
$ ls -la /media/$USER
# See any Hidden folders/files and folder structure . = Current Folder, .. = Folder above current

Another Task you will need to do throughout this tutorial is Opening your default File Manager to Mount USB disks. In Tails, Left click on the Places Icon at the top menu bar on the screen, then Left click on Computer. On the left side of the screen towards the bottom half of the window below the Trash Icon is any Mountable Device. To use a USB Drive click on the Volume Name for that device. It will now attempt to open and MOUNT it for you and this allows for access via /media/$USER folder access from the terminal as well.

In Ubuntu, click on the Files folder icon in the Launcher Bay, if you cannot find it, press Windows key, then type to search for: files.

On both systems, the File Manager called Nautilus exists, below I will open it from a Terminal. In the next command, notice that I add an, & called ampersand, to the end of the command. What that does is allows it to work as a background job, so you can do other things in this Terminal session while the File Manager is Running. Otherwise, without the ampersand symbol on the end of that command you would have to wait for it to close before doing other commands in the Terminal...

$ nautilus ~/Desktop &

That is way easier than mounting from the Terminal, but I'm going to show how to do that coming up. First Identify the device's file system path by running the following command:

$ sudo fdisk -l
# note that the fdisk program is only on Ubuntu, 
# on Tails it need to be installed, but don't...

# Either way, let's Verify this by opening Disks.
$ gnome-disks &
# Look for your Flash drive, Left click it. It tell you
# All kinds of info like: Size, Device path EX /dev/sbd, 
# Mount Point, Volume type and Name

# You can unmount it by clicking the Stop button under Volumes.
# You can mount it by clicking the Play button under Volumes.

# sudo is not enabled by default in Tails for security...
# At the Welcome to Tails Screen: at the bottom of the page,
# is the Additional Settings, Click on the + Button. 
# Now on the Popup window, click Administration Password. Assign one.
# Click Add...

$ sudo mkdir /mnt/myusbdrive

# Replace /dev/sdb with the file system path of your ext4 USB flash drive device,
# 	identified in fidsk -l
$ sudo mount -t ext4 /dev/sdb /mnt/myusbdrive
# NOTE: it will fail if already mounted by the system, you can unmount it,
# from gnome-disks by the Stop button and try that it again...

$ cd /mnt/myusbdrive

# Lets see what is on the drive
$ ls -la

# When done working on the drive, please un-mount it:
sudo umount /mnt/myusbdrive