Overclock.net › Forums › Overclockers Care › Overclock.net Folding@Home Team › The Folder's Guide to the Terminal
New Posts  All Forums:Forum Nav:

The Folder's Guide to the Terminal

post #1 of 4
Thread Starter 
The purpose of this guide is not to help setup an clients, but to give you an understanding of the Linux terminal. A guide to help you understand what you are doing throughout other Linux guides.

For now the information is quite basic. Over time, I will make each topic much more thorough and will continue to expand upon topics. I will also add more advanced topics, for example: Makefile, bash, scripts, permissions, bin...

The goal is that anytime someone working through a guide, and is told to use the terminal for the first time, they have a resource to help them understand.

** This guide uses Ubuntu as is primary distribution, but most concepts can easily be applied to all distros
** This guide is entirely written by me, terms and definitions are my interpretation. If you disagree, please let me know!
** For those who have a strong grasp of Unix, there are times in this guide where I explain things slightly incorrectly as to not delve into a topic beyond the scope of this guide.
** This Guide is on-going, it may never be finished...

The best way to learn the terminal is to use it, make mistakes, and find new things!


What is the terminal? Warning: Spoiler! (Click to show)
For beginner Linux users, the terminal is something that can seem a bit complicated; however, it is an extreamly powerful tool which all Linux users must become comfortable with.

Anything done on a computer, can be done in the terminal. The terminal is a way for the user to access the Unix prompt; but if you are here, I will assume you want an explanation that will make more sense to you than that. So, the terminal is essentially a way of interacting with the operating system through commands instead of a graphical user interface (GUI). Something typically done on a computer is the opening of a web browser. Well, instead of double clicking a shortcut to open Firefox, you can simply type "firefox" into the terminal window, and Firefox will open. Anything you will do in Ubuntu can be done through the terminal.

Once you open the terminal window, you will see something similar to this:
Code:
[matt@arch /]$
.

The above is the prompt. Whenever the terminal is ready for your input, it will display a prompt. Each person's prompt will be different.


The Basics of Using Terminal Warning: Spoiler! (Click to show)
To use the terminal, you simply enter commands. The format for doing so is first command and then any extra information you need to give that command (the extra information is called a parameter).
For example:
Code:
[matt@arch /]$ vim file.txt

vim is a simple text editing program and file.txt is the a parameter which you are passing to the program vim.
Vim is programmed to take the parameter of a file name, the file you want to edit.


In essence, this is all that needs to be done when using the terminal. You enter the command or the name of the program you wish to run and then any parameters it requires.

Of course, the terminal is a very powerful tool, and we will use some slightly more complicated commands later.

:
Directories Warning: Spoiler! (Click to show)
Directory: A folder
Working Directory: The directory you are currently in
Linux short hands:
"." stands for your working directory
".." parent directory, The directory which contains the the directory of interest
"/" root, or the the directory with no parent directories
Path: The list of directories from root which leads to the direcotry of interest

For example:
That is the path for the folder Documents. You can see the root directory contains a folder home, which contains a folder matt, which contains the folder Documents.
Code:
/home/matt/Documents


Useful Terminal Commands Warning: Spoiler! (Click to show)

ls more info (Click to show)

lists directory contents, will show you all files in your current directory.
Code:
[matt@Arch ~]$ ls
Desktop  Documents  Downloads  flash  logs  Media

Important command parameters (Click to show)

-a
This parameters will let you view all files in the working directory, including those that are typically hidden, for example: .swp files
Code:
[matt@Arch fah]$ ls
temp.txt
[matt@Arch fah]$ ls -a
.  ..  temp.txt  .temp.txt.swp

-l
This allows you to view more information about each file
Code:
[matt@Arch fah]$ ls
temp.txt

[matt@Arch fah]$ ls -lB
total 4
-rw-r--r-- 1 matt users 5 Jan  5 13:56 temp.txt


cd more info (Click to show)

change working directory, will allow you to change directories, you pass the path of the target directory as the parameter
Code:
[matt@Arch ~]$ cd Documents
[matt@Arch Documents]$ cd ..
[matt@Arch ~]$ 


mv more info (Click to show)
corresponding command line argument

--no-preserve-root
do not treat `/' specially

--preserve-root
do not remove `/' (default)

-r, -R, --recursive
remove directories and their contents recursively

-v, --verbose
explain what is being done

--help display this help and exit

--version

output version information and exit

By default, rm does not remove directories. Use the --recur‐
sive (-r or -R) option to remove each listed directory, too,
along with all of its contents.

To remove a file whose name starts with a `-', for example
`-foo', use one of these commands:

rm -- -foo

rm ./-foo

Note that if you use rm to remove a file, it might be possible
to recover some of its contents, given sufficient expertise
and/or time. For greater assurance that the contents are truly
unrecoverable, consider using shred.
Manual page rm(1) line 47/114 71% (press h for help or q to quit)

move, this moves a file to a new directory
Code:
[matt@Arch ~]$ ls
Desktop  Documents  Downloads  flash  hello.txt  logs  Media  temp
[matt@Arch ~]$ mv hello.txt temp
[matt@Arch ~]$ cd temp
[matt@Arch temp]$ ls
hello.txt
[matt@Arch temp]$ 


mkdir more info (Click to show)

make directories, creates a directory, you pass the parameter of the directory name
Code:
[matt@Arch temp]$ ls
[matt@Arch temp]$ mkdir tempFolder
[matt@Arch temp]$ ls
tempFolder
[matt@Arch temp]$ cd tempFolder
[matt@Arch tempFolder]$ e


rm more info (Click to show)
corresponding command line argument

--no-preserve-root
do not treat `/' specially

--preserve-root
do not remove `/' (default)

-r, -R, --recursive
remove directories and their contents recursively

-v, --verbose
explain what is being done

--help display this help and exit

--version
output version information and exit

By default, rm does not remove directories. Use the --recur‐
sive (-r or -R) option to remove each listed directory, too,
along with all of its contents.

To remove a file whose name starts with a `-', for example
`-foo', use one of these commands:

rm -- -foo

rm ./-foo


Note that if you use rm to remove a file, it might be possible
to recover some of its contents, given sufficient expertise
and/or time. For greater assurance that the contents are truly
unrecoverable, consider using shred.
Manual page rm(1) line 47/114 71% (press h for help or q to quit)


remove, will delete the passed in parameter
Code:
[matt@Arch ~]$ ls
Desktop  Documents  Downloads  flash  logs  Media  hello.txt
[matt@Arch ~]$ rm hello.txt
[matt@Arch ~]$ ls
Desktop  Documents  Downloads  flash  logs  Media

Important command parameters (Click to show)

-r
Recursive, this allows you to delete a folder, it will also delete all folders and files within it.
Code:
[matt@Arch ~]$ ls
Desktop  Documents  Downloads  flash  logs  Media  temp
[matt@Arch ~]$ rm -r temp
[matt@Arch ~]$ ls
Desktop  Documents  Downloads  flash  logs  Media


pwd more info (Click to show)

print working direcotry, will print the path of your working directory
Code:
[matt@Arch fah]$ pwd
/home/matt/Documents/fah


clear more info (Click to show)

clears the terminal window, but not your history


wget more info (Click to show)

this command takes a URL as a parameter, and will download that URL to your working directory
Code:
[matt@Arch fah]$ ls
[matt@Arch fah]$ wget http://www.filefactory.com/file/c1ea8a6/n/flash.tar.gz
--2012-01-05 12:59:09--  http://www.filefactory.com/file/c1ea8a6/n/flash.tar.gz
Resolving www.filefactory.com... 85.17.172.100
Connecting to www.filefactory.com|85.17.172.100|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `flash.tar.gz'

    [  <=>                          ] 27,174      81.8K/s   in 0.3s    

2012-01-05 12:59:10 (81.8 KB/s) - `flash.tar.gz' saved [27174]

[matt@Arch fah]$ ls
flash.tar.gz

tar more info (Click to show)

tar is a archiving format. The tar command can be used to compress or to extract data. Tar archives can be of two file formats, *.tar or *.tar.gz *see the tar section for more explanation

to archive a .tar
Code:
[matt@Arch fah]$ ls
a.out  temp.txt
[matt@Arch fah]$ tar -cvzf temp.tar a.out temp.txt
a.out
temp.txt
[matt@Arch fah]$ ls
a.out  temp.tar  temp.txt

to extract a .tar
Code:
[matt@Arch fah]$ ls
temp.tar
[matt@Arch fah]$ tar -xvzf temp.tar
a.out
temp.txt
[matt@Arch fah]$ ls
a.out  temp.tar  temp.txt
[matt@Arch fah]$ 

to archive a .tar.gz
Code:
[matt@Arch fah]$ ls
a.out  temp.txt
[matt@Arch fah]$ tar -cvzf temp.tar.gz *
[matt@Arch fah]$ ls
a.out  temp.tar.gz  temp.txt


to extract a .tar.gz
Code:
[matt@Arch fah]$ ls
temp.tar.gz
[matt@Arch fah]$ tar -xvzf temp.tar.gz 
a.out
temp.txt

[matt@Arch fah]$ ls
a.out  temp.tar.gz  temp.txt


chmod more info (Click to show)

chmod is used to change the permisions of a file *see the file permission section for more explanation
Code:
[matt@Arch fah]$ ls -l
total 8
-rw-r--r-- 1 matt users 6480 Jan  5 13:04 a.out
[matt@Arch fah]$ chmod +x a.out
[matt@Arch fah]$ ls -l
total 8
-rwxr-xr-x 1 matt users 6480 Jan  5 13:04 a.out


Permisions Warning: Spoiler! (Click to show)
Linux systems, like Windows and OSX, have users. Depending on what permissions a user has, their actions can be limited. The root user, is the user which has no limitations.


There are three types of limitations, that can be given to a file. A user's ability to: read, write and execute.

read = to open the file, and see the contents
write = to alter the file
execute = to run the executable

So, a user may or may not have permissions on a file in each of these three categories.

r = read permission
w = write permission
x = execute permission
- = no permission
A bit of extra info (Click to show)

d = directory
- = regular file
l = symbolic link
s = Unix domain socket
p = named pipe
c = character device file
b = block device file

Everything in a Unix system is a file, and there are seven different types of files (see above list). The first character printed in the "ls -l" command will be the file type.

The "ls -l" command will show extra information about a file. Part of that extra information are privileges:
Code:
[matt@Arch fah]$ ls -l
total 8
-rwxr-xr-x 1 matt users 6480 Jan  5 13:04 a.out

Do not worry about the first character, the "-". you can see this file has the given privileges:
rwx r-x ---

I broke these characters up into three groups because this readout tells you the privleges for three groups of people.
But more on that in a minute.

The first group has a "r w x". This means, the group can read, write and execute the file.
The second group has "r - x". This means, the group can read, they cannot write, but they can execute.
The final group has "- - -" . This means the group cannot read, write or execute the file.

Respectively, these three groups are labeled: User Group Other

User - your user's permissions
Group - permissions of the entire group (no need to worry about this now)
Other - essentially the permissions of everyone

So, a command many of you have seen
Code:
chmod +x <fileName>

Hopefully, this will make a bit more sense to you now. This command gives executable privileges to all.

And finally, the chmod command is often used like this:
Code:
chmod 755

This one takes a little more explaining. Here we are thinking about the "r w -" as having permission or not. "1" permission, "0" being no permission. So, if we re-write "rwx r-x r-x" with 1's and 0's, we get "111 101 101". In octal this is equal to "755".

So, if we wanted to set the permissions to be "rw- r-- ---", in octal that would be "640", and so we use the command:
Code:
chmod 640 <fileName>

sudo Warning: Spoiler! (Click to show)
So, now that we have a grasp on permission, the root user can be better explained. Many system files have permissions set so users cannot alter them. However, every Linux computer has a user, named root, which has full access to anything any everything on a computer.

Now, you are able to log in a root; however, because of power, it is easy to mess up your system, and so we prefer to only use that power when we need it.

So, how do we use that power? Well we can use the sudo command. To do so, simply type sudo before the desired command. Once the command has been run, it will prompt you for your password, if you are in the sudo group, then you will be able to execute the command will full privileges. *see the groups section for more information
Code:
[matt@Arch fah]$ ls
temp
[matt@Arch fah]$ sudo rm -r temp
Password: 
[matt@Arch fah]$ ls

Useful Tidbits Warning: Spoiler! (Click to show)

Tab completion: (Click to show)
You do not have to type the entire words of what you are entering into the terminal. Simply start the word, then hit tab and it will complete the word or at least add as many letters as it can before it sees multiple possible words you may be typing.


Man Pages: (Click to show)
The Man Pages are the single greatest resource (next to the internet) you will have while learning and using a Linux system. Simply type "man " into the terminal and a page will come up within the terminal window explaining the usage of that command. (No internet access required)
Code:
[matt@arch /]$ man rm

The above will bring up the man page for the rm command.
To give you idea of what a man page is, here is the rm page.


History: (Click to show)
Buy using the up arrow in terminal, you can cycle your past commands. You can also type the command history.


Copy/Paste: (Click to show)
You will quickly notice control+c and control+v do not work, well, control+shift+v/c do. thumb.gif


The * Character: (Click to show)
The star means anything. So, if you want to delete all .txt files, you would type:
Code:
[matt@Arch /] rm *.txt

You can also delete all files with one extension with
Code:
[matt@Arch /]$ rm *.*

or all files
Code:
[matt@Arch/]$ rm *



Some of the things to come (Click to show)

Package Manager

Tar

File System

Groups

Pipes and Redirects

Scripts

MakeFile

bin

SSH

GUI vs. Command Line

How the terminal works

Edited by hoth17 - 1/5/12 at 9:44pm
post #2 of 4
Nice start hoth. Very appreciative to have some one pitting together a dummies guide. Ive had to do a bunch of googling to understand a lot of what i was doing in a bunch of the linux guides.
Top Heavy
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5-3570k ASUS P8z77-I Deluxe MSI GTX 980 Gaming 4G Samsung MV-3V4G3D 
Hard DriveCoolingOSMonitor
Samsung 840 Evo ThermalRight Macho Rev B Windows 7 Professional 64bit Samsung SyncMaster P2450 
KeyboardPowerCaseMouse
Logitech MX 3200 Rosewill GreenPower 630W Custom Built mITX bench made from the carcas of... Logitech M510 
Audio
Onboard 5.1 
  hide details  
Reply
Top Heavy
(13 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5-3570k ASUS P8z77-I Deluxe MSI GTX 980 Gaming 4G Samsung MV-3V4G3D 
Hard DriveCoolingOSMonitor
Samsung 840 Evo ThermalRight Macho Rev B Windows 7 Professional 64bit Samsung SyncMaster P2450 
KeyboardPowerCaseMouse
Logitech MX 3200 Rosewill GreenPower 630W Custom Built mITX bench made from the carcas of... Logitech M510 
Audio
Onboard 5.1 
  hide details  
Reply
post #3 of 4
Thread Starter 
I think that should be a good start there. There are a few more sections that I think are important to get up, but what I have should give you a good place to start.

If anyone thinks of info I should add to my "things to come" list, let me know.
If you find incorrect information, please post! This guide has been straight from my head, so I may be remembering some details incorrectly.

If you have any questions about the terminal, ask them here, lets make this a bank of knowledge.
And don't forget to search the man pages when you are unsure about at command!
Edited by hoth17 - 1/5/12 at 10:00am
post #4 of 4
Thread Starter 
bump
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Overclock.net Folding@Home Team
Overclock.net › Forums › Overclockers Care › Overclock.net Folding@Home Team › The Folder's Guide to the Terminal