Linux for dummies:

Introduction Log in into your system Tour of the linux files system management Working with directories File editing File listing: Create directory Removing/deleting files linux commands Data compression

Introduction

Linux is an (OS), i.e. it is a software that run on a computer that enables applications and the computer operator to access the devices on the computer to perform desired functions. Linux is similar to other OS such as Windows and OS X. Linux has been used since the 1990s and has become a widely used OS among researchers owing to its GNU General Public License (GPL) give more flexibility as compared to Copyright. Linux communities come in two basic forms: developer and user communities. And we as user will try to learn and exploit this OS during this course. Linux comes in various flavours and in this document we shall look more into Ubuntu version.

Ubuntu is an ancient African word meaning 'humanity to others'. It also means 'I am what I am because of we all are'. The Ubuntu operating system brings the spirit of Ubuntu to the world of computers.

The purpose of this training is to give you competency as a beginning user of /Linux. You will leave from this training with the ability to use Unix/Linux to perform routine file management, file editing, command piping and filtering, file permissions, and some customizations. You will also know how to access Unix reference information and help material online so that you can gain more Unix knowledge when you require it. With these skills, you should be able to accomplish tasks that you might have to do for the rest of the training.

What I am assuming about you: ● You know how to use a personal computer, mouse, and keyboard ● You can use a Web browser ● You can get access to a Unix/Linux account ● You are comfortable using computers

Log in into your system

Once the system has been booted, you will see a screen asking for a username and a password. This will be provided to you by the System Admin or ROOT. When you know these, protect this information, as anyone who learns your password could log in to your account, change or delete your files, and send email in your name. You do not have to protect your username.

Tour of the linux files system

You can visualize the Unix/Linux file system as an upside down tree.

/ is also known as the root directory of the Unix/Linux file system. Everything grows from here. This special directory is maintained by the Unix/Linux system administrator. Under the root directory, subdirectories organize the files and subdirectories on the system.The names of these subdirectories might be any name. In the above example, root has 6 sub­directories which are further subdivided into other directories. The 2 users in this system are sue and fred.

● /bin ­ has a set of binaries used when the machine is first booted. Usually only a small subset of commands are available here. ● /etc ­ contains system configuration files and executables. The password file and boot scripts are two examples of configuration files. ● /dev ­ holds special files that are used to communicate with disks, tape, cdrom, and terminals. ● /home ­ usually has the users home directories. ● /lost+found ­ contains lost files. Files that are recovered by fsck are placed in this directory.

In linux you can work using the Graphic User Interface (GUI) or via terminal of command line interface (CLI). A video will show you the GUI. Here I will take you through the terminal interface. Even though there are many linux versions, most if not all of them use similar commands that can be entered from a command­line interface terminal. The terminal is not something you should be scared of. It is a powerful tool with lots of uses.

To start a Terminal, in Gnome

Applications menu ­> Accessories ­> Terminal.

OR

Keyboard Shortcut: Ctrl + Alt + T

Your should get something like this

The first word anuj ­ is the login name of the user. Then the second anuj is the name of the computer followed by a : and a tilde ‘~’. The ~ shows that we are in the home directory of the user anuj. After the prompt, represented by a $ sign, we can our commands.

File management

Working with directories

When you log in, you can issue the command. This will print your working directory. Tab completion is a very useful trick. While typing something – a command, file name, or some other types of arguments – you can press Tab to autocomplete what you are typing.

$ pwd /home/john $

Now, if you want to change my present working directory to the directory above your home directory, home, you use the change directory () command followed by ".." (two periods right together, no spaces). This puts you in the "home" subdirectory.

Note: when you open a terminal you will be in your home directory.

$ cd .. $ pwd users $

You can still go "up" further to the root directory (if the system administrator allows it ­­ it is possible to set the permissions so that you can not "visit" any directory you want):

$ cd .. $ pwd / $

You can NOT go any higher in the tree.

Now, you could issue the change directory commands like this to go back to my home directory:

$ pwd / $ cd home $ pwd /users $ cd john $ pwd /home/john/ $

But there is a shortcut to going back home. Just enter the cd command without anything after it.

$ pwd /home/john/ $ cd .. $ pwd /home $ cd .. $ pwd / $ cd $ pwd /home/john $

Now, if you are in your home directory, and you want to quickly go to the root directory, you can string together the two periods ".." separated by slashes "/" to go up two levels to the root directory. Like this:

$ pwd /home/john/ $ cd ../../ $ pwd / $

Now, this is all fine and good, but what if you want to organize my files in some subdirectory of your own. You can create a subdirectory in your home directory using the command.

$ pwd /home/john $ mkdir Project $ cd Project $ pwd /home/john/Project $ $ cd ~ ~home $ cd ~john

Question: What will “cd ~/john” do?

Unix/Linux keeps track of files and directories of files using a file system. The names that you come up with for your Unix/Linux files need to work within this file system. The way you name files in Unix/Linux is pretty flexible, but there are specific rules you have to follow. In practice, there are also some good habits to get into when making your own files.

You can name a file in Unix/Linux using any combination from the following sets: {a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z} {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} {period (.), underscore(_), comma(,)} You can not name a file period (.) or period period (..) or (\).

Directories are files in Unix/Linux, so directory names follow these same rules also.

Unix/Linux File Naming Practices ● You need to follow the official rules for file naming in Unix/Linux, but here are some good practices that I've found also help keep things straight: ● Avoid naming a file with the same name as a Unix/Linux command. ● You can out if a name is a Unix/Linux command by using the man command. ● Use file extensions that are widely recognized when possible. ● For example, if you create a text file, use the character string .txt as the last part of the file name. ● Unix/Linux cares about case,i.e. the file Alpha.txt is different from alpha.txt. ● The capital letter is only going to cause you problems with trying to remember if the filename or directory name has a capital letter or not. Simply use all lower case. It makes life easier. ● Start a file name with a letter or number. If you start it with a dot (.), it will be a hidden file. ● your names short, but not cryptic. Use correctly­spelled nouns when possible. For example, store your inventory in inventory.dat and not invtry.dat.

File editing

There are several commands to open, create, edit or view a file in linux. pico ­ Simple and very easy to use text editor

To launch pico the terminal prompt type

$ pico

Your screen should look similar to this:

This is very limited and light at the same . You can use it to quickly open and edit txt files. We shall use pico to create a txt file containing the following:

“This is a txt file My name is Nadeem I live in South Africa”

Now save the file under the name my_first_pico_file.txt

To view the content of a file, the more command is quite useful

$ more my_first_pico_file.txt ­ Allows you to look, modify or combine a file.

$ cat my_first_pico_file.txt This is a test txt file My name is Nadeem I live in South Africa

Now we shall use cat to concatenate 2 files.

$ cat my_first_pico_file.txt my_first_pico_file.txt > my_first_pico_file_concatenated.txt

$ more my_first_pico_file_concatenated.txt This is a test txt file My name is Nadeem I live in South Africa

This is a test txt file My name is Nadeem I live in South Africa

Remember Unix/Linux are case­sensitive. Most commands must be typed using lowercase letters, e.g: the command date is going to work. The commands DATE or Date are invalid in linux or can mean some other commands. Remember to hit the Return or Enter key on your keyboard after you are done typing in the Unix/Linux command. If you don't hit the Enter key or the Return key, Unix/Linux will just keep waiting until you do.

File listing:

The command will show you ('list') the files in your current directory. Used with certain options, you can see sizes of files, when files were made, and permissions of files. To begin with let us list the content of our current working directory:

$ ls Here are some of the most commonly used ls flags: a Lists all files, including hidden ones. l Displays the file list in long format, including file details like size, time stamp, and owner. F Adds a slash after the name for directories, an asterisk for executables, and an at sign (@) for linked files. r Reverses the order (alphabetic or time). t Sorts the list by the time each file was created. h When used with the ­l option, use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte in order to reduce the number of digits to three or less using base 2 for sizes.

If you look at a list of files using the long list format ls ­l, you'll see the permissions, owner, file size, modification time, and filename.

$ ls ­l e.g. My listing shows this:

Permissions Directories user group size date Directory of file drwxr­xr­x 5 nadeem staff 170 Aug 12 2012 twonkymedia/ ­rw­r­­r­­ 1 nadeem staff 210 Jul 8 2011 vizier.list ­rw­r­­r­­ 1 nadeem staff 107 Feb 27 2013 wobble.csv drwxr­xr­x 4 nadeem staff 136 Feb 26 2012 workspace/ drwxr­xr­x 12 nadeem staff 408 Aug 12 23:44 writelatex/ ­rw­r­­r­­ 1 nadeem staff 5 Apr 9 2011 ximage.hty

Question: Run the following commands and copy your output. What is the meaning of the various flag?

$ ls ­a $ ls ­la $ ls ­lrt $ ls ­lrth

Create directory

The mkdir command makes a new directory. mkdir My_examples will make a directory with the name “My_examples” in the current directory.

$ mkdir My_examples

The command will copy your file to the destination specified

$ cp ~/user/my_first_pico_file_concatenated.txt ~/My_examples/.

The cp command can also be used to clone copy a file to another file.

Change to your directory My_examples

$ cp my_first_pico_file_concatenated.txt my_first_pico_file_concatenated_original.txt

Removing/deleting files

The command removes files. Be careful with this command — rm does not ask you for confirmation. Once a file has been deleted, it is very difficult to recover or undelete it in linux. To delete a file you would use

$ rm filename_to_delete

You can also delete files from other directory

$ rm /path/to/directory/filename_to_delete

Question: What will rm ­i file_name_to_delete do ?

The command can be used to delete empty directory. This is a dangerous command that could easily delete a lot of important files, so be careful when using it.

$ rmdir /path/to/empty/directory

The command moves a file to a new location. This is also the command you’ll use to rename files. For example, mv file newfile would take the file named “file” in the current directory and move it to the file named “newfile” in the current directory — renaming it, in other words.

$ mv my_first_pico_file_concatenated.txt my_first_pico_files_concatenated.txt

More linux commands which

$ which ls /bin/ls whereis

$ whereis ls /bin/ls locate $ locate stdio.h $ locate iostream find $ find / | stdio.h $ find /usr/include | grep stdio.h

Data compression tar $ tar cvfp lab1.tar lab1 gzip $ gzip ­9 lab1.tar untar & gunzip

$ gzip ­cd lab1.tar.gz | tar xvf – $ tar xvfz lab1.tar.gz $ touch foo $ cat /dev/null > foo man: The man command is used to show you the manual of other commands. Try "man man" to get the for man itself. See the "Man & Getting Help" section down the page for more information.

Command piping and filtering

$ ls ­1 | ­l

File permissions Customization