Welcome, Guest. Please Login
 
  HomeHelpSearchLogin FAQ Radified Ghost.Classic Ghost.New Bootable CD Blog  
 
Pages: 1 2 3 
Send Topic Print
Using the Unix/Linux Shell Command-line - Part 2 (Read 45977 times)
Rad.in.UbuntuVM
Radmeister
**
Offline


Rad in Ubuntu 9.04 Jaunty
Virtual Machine

Posts: 92


Back to top
Using the Unix/Linux Shell Command-line - Part 2
Jul 28th, 2009 at 5:42pm
 
Continued from (Using the Unix/Linux Shell Command-line):

http://radified.com/cgi-bin/yabb2/YaBB.pl?num=1247608529/63#63 (end of previous thread)

http://radified.com/cgi-bin/yabb2/YaBB.pl?num=1247608529 (beginning of previous thread)

Remaining modules:

08-04 - Basic editing
[ No 08-05 module ]
08-06 - Configuring vi

09-01 - The Unix File System
09-02 - How Files are Stored
09-03 - Understanding Links
09-04 - Linking Files
09-05 - Symbolic Links
09-06 - Unix File Types

10-01 - Communication
10-02 - Using mail

11-01 - Customizing the Shell environment
11-02 - Environmental Variables
11-03 - Your path
11-04 - Your prompt
11-05 - .profile
11-06 - Command-line editing
11-07 - Other Shell Customizations & Options
11-08 - The end.
 
WWW  
IP Logged
 

MrMagoo
Übermensch
*****
Offline


Resident Linux Guru

Posts: 1026
Phoenix, AZ (USA)


Back to top
Re: Using the Unix/Linux Shell Command-line - Part 2
Reply #1 - Jul 28th, 2009 at 7:00pm
 
Rad.in.UbuntuVM wrote on Jul 28th, 2009 at 5:42pm:
09-01 - The Unix File System
09-02 - How Files are Stored
09-03 - Understanding Links
09-04 - Linking Files
09-05 - Symbolic Links
09-06 - Unix File Types

11-02 - Environmental Variables
11-03 - Your path

Out of the chapters you have left, these are the more important ones.  Pay attention to these.  Almost everything in Linux is treated as a file - network sockets, device nodes, open pipes - all can be read and written to just like files, so it's essential to understand how the kernel treats files.

Environment variables affect the way the system acts.  You can change the behavior of the entire shell by playing with Environment Variables.  You path is an environment variable that tells the shell where to look for commands, so it has a big effect on which version of a command the system runs and how it looks for them.

The rest of the chapters are useful but not pivotal.
 
WWW  
IP Logged
 
Rad.in.UbuntuVM
Radmeister
**
Offline


Rad in Ubuntu 9.04 Jaunty
Virtual Machine

Posts: 92


Back to top
Re: Using the Unix/Linux Shell Command-line - Part 2
Reply #2 - Jul 29th, 2009 at 1:44pm
 
The term 'terminal' .. as it is used in Linux, typically refers to a "terminal emulator' .. no? I mean, the 'terminal' I use in Ubuntu (Gnome terminal 2.26.0) says (in 'About') > "a terminal emulator for the Gnome desktop".

Just trying to get my terminology correct.

'Terminals' were originally hardware, not software .. yes?

When folks says, "launch a terminal," they really mean "launch a software program known as a terminal emulator that emulates a physical terminal" .. yes?
 
WWW  
IP Logged
 
Rad.in.UbuntuVM
Radmeister
**
Offline


Rad in Ubuntu 9.04 Jaunty
Virtual Machine

Posts: 92


Back to top
Re: Using the Unix/Linux Shell Command-line - Part 2
Reply #3 - Jul 29th, 2009 at 2:21pm
 
I wanted to play with vim by editing and moving around in a file .. but I didn't want to open/edit any random file on the system, cuz that might break something. So I "Viewed source" on the site's home-page (a file I'm familiar with) and saved it (.. to the desktop, which was the default location). Then I looked around and discovered the 'Desktop' (with a capital-D) was located in /home/user .. so I opened it with:

"vi /home/user/Desktop/index.rad"

.. and it worked! I know that's simple, but I'm am actually pretty stoked, cuz it means I'm getting an understanding of how things work.

Was gonna ask you, but figured it out myself.  Cool
 
WWW  
IP Logged
 
MrMagoo
Übermensch
*****
Offline


Resident Linux Guru

Posts: 1026
Phoenix, AZ (USA)


Back to top
Re: Using the Unix/Linux Shell Command-line - Part 2
Reply #4 - Jul 29th, 2009 at 3:49pm
 
Rad.in.UbuntuVM wrote on Jul 29th, 2009 at 1:44pm:
The term 'terminal' .. as it is used in Linux, typically refers to a "terminal emulator' .. no? I mean, the 'terminal' I use in Ubuntu (Gnome terminal 2.26.0) says (in 'About') > "a terminal emulator for the Gnome desktop". 

Typically when an admin says 'terminal' they mean anything that acts like a terminal.  A terminal emulator is popularly used when you are logged onto the box in a graphical environment, like gnome.  It can also refer to a remote terminal, like the ssh session you use to admin your VPS.  Local terminal also exist.  Press ctrl+alt+F1 to get to a text based terminal on  your virtual machine.  There should be 7 terminal, accessed by using ctrl+alt+F1-F7.  If you are logged in to a graphical session, it is usually placed on terminal 7 (so pressing ctrl+alt+F7 should take you back to it.)

Remote terminals are definitely the most common type used since you very rarely are in the same room as your servers.

Rad.in.UbuntuVM wrote on Jul 29th, 2009 at 2:21pm:
I wanted to play with vim by editing and moving around in a file .. but I didn't want to open/edit any random file on the system, cuz that might break something.

Yup, best not to mess with files unless you know what they are.  Some simple looking text files are pretty important.

Remember, you can create a new file with Vi by opening one that doesn't exist yet:

Code:
vi newfile.txt 



Also, the command 'touch' creates a new blank file (or updates the last modified time of an existing file):

Code:
touch newfile.txt
vi newfile.txt


If you wanted to be creative, you could echo nothing (or something)  into a new file:

Code:
echo "" > newfile.txt 


or
Code:
echo "some junk" > newfilename.txt 



Or, you could use dd (which I think is short for Data Dump) to put a few bytes of random data into a file:

Code:
dd bs=8 if=/dev/random of=newfile.txt  



An even more creative way to do it might be to concatenate nothing with nothing and redirect the output to a file that doesn't exist:

Code:
cat /dev/null > newfile.txt 



Not sure if that one actually works, but I'll try it as soon as I get to a Linux box (in a few hours.)

HeHe.  Lots of ways to get things done.
 
WWW  
IP Logged
 
Rad
Radministrator
*****
Offline


Sufferin' succotash

Posts: 4090
Newport Beach, California


Back to top
Re: Using the Unix/Linux Shell Command-line - Part 2
Reply #5 - Jul 29th, 2009 at 7:33pm
 
Supposedly Unix does not handle file types the way Windows does. In other words the file extention in Unix is just part of a file's name and can be eliminated or changed. Yes?

So, say I have a file named mt43.tar.gz (i do). Can I rename it to "mt43" on the server before untarring it? Without affecting anything esle?
 
WWW  
IP Logged
 

MrMagoo
Übermensch
*****
Offline


Resident Linux Guru

Posts: 1026
Phoenix, AZ (USA)


Back to top
Re: Using the Unix/Linux Shell Command-line - Part 2
Reply #6 - Jul 29th, 2009 at 7:55pm
 
Rad wrote on Jul 29th, 2009 at 7:33pm:
Can I rename it to "mt43" on the server before untarring it? Without affecting anything esle?

Yes, you can.

Rad wrote on Jul 29th, 2009 at 7:33pm:
Supposedly Unix does not handle file types the way Windows does. In other words the file extention in Unix is just part of a file's name and can be eliminated or changed. Yes?

This is true, but following some sort of standard is still very helpful for humans.  It is still common practice to use file extension, even tho the OS will not look at them, so that the users of the system know how to deal with the file.

For example, if you asked WiredTree to take a look at something on your server and they see a file called 'mt43', they might not have any idea what it is.  But, mt43.tar.gz is easily discernable as a Gzip compress tar archive.  Given that much information, they might even make the connection to MoveableType ver4.3.

Some programs will even look at file extensions in order to try to guess what type of file you have, even though the OS does not.

So, file extensions are still useful even though they are optional.
 
WWW  
IP Logged
 
Rad.in.UbuntuVM
Radmeister
**
Offline


Rad in Ubuntu 9.04 Jaunty
Virtual Machine

Posts: 92


Back to top
Re: Using the Unix/Linux Shell Command-line - Part 2
Reply #7 - Jul 30th, 2009 at 12:37pm
 
for the 'cp' command, is the -r option the same as -R?

http://unixhelp.ed.ac.uk/CGI/man-cgi?cp

seems so.

normally in Linux r and R mean different things.
 
WWW  
IP Logged
 
Rad.in.UbuntuVM
Radmeister
**
Offline


Rad in Ubuntu 9.04 Jaunty
Virtual Machine

Posts: 92


Back to top
Re: Using the Unix/Linux Shell Command-line - Part 2
Reply #8 - Jul 30th, 2009 at 6:51pm
 
was surprised to see the terminal in ubuntu vm REMEMBERED my last command (to open file index.rad) .. by hitting the up arrow.

come to think about it, this course didn't (i don't think) address that command .. of hitting the up-arrow to reproduce the most-recently typed command. is that a standard shell feature?

also, i've noticed i can highlight sections of text (in ubuntu terminal vim) with my mouse, while there is STILL a single blinking cursor .. BUT the vi commands i'm learning only work on/at the blinking cursor.

so i don't understand what is the point of highlighting sections of text (via click-n-drag).
 
WWW  
IP Logged
 
Rad.in.UbuntuVM
Radmeister
**
Offline


Rad in Ubuntu 9.04 Jaunty
Virtual Machine

Posts: 92


Back to top
Re: Using the Unix/Linux Shell Command-line - Part 2
Reply #9 - Jul 30th, 2009 at 7:37pm
 
08-04 - Basic Text-Editing Commands (Insert Mode)

a variety of commands take you into insert mode
[ Recall the ESC key returns you to Command mode ]

a ('append') = takes you into insert mode .. to Append text AFTER the cursor (a for Append After)
i ('insert') = takes you into insert mode .. to Insert text BEFORE the cursor (i for Insert Before)

A (capital A) = Append text at end of the line (useful command)
I (capital I) = Append text to the BEGINNING of the line.
Note: you don't have to actually GO TO the beginning/end of the line, as the command will take you there.

o (for "open") = start a new new AFTER the current line
O (capital O) = start a new line BEFORE the current line.
s (for "substitute") the current character (where cursor is) for text you type.
can type a number here before 's' to sunstitute any number of characters
e.g. "5s" substitues (replaces) the next 5 characters after cursor with whatever text you type.
cw (change word) = change word to new text. Can also specify a number before "cw" to change more than 1 word.
e.g. "2cw" or "5cw"
c command is very flexible and can be used with other characters, such as the $
$ takes you to the end of the line, so "c$" changes all the text between cursor and end of line .. to text typed.
also, since f = find (e.g. "fX") therefore .. "cf," changes everything up until the next comma.

Following commands edit text without taking you into Insert mode:
x = cuts the character at cursor. Can also be used with a number (goes to vi clipboard)
X (capital X) cuts the character before cursor. (goes to vi clipboard)
dd = delete current line. Can also be used with a number (e.g. "4dd" .. deletes 4 lines)
d is similar to c in the way it can be combined with other letters.
dw = delets a word at a time.
d$ = deletes everything to the end of the line.
df, = deletes everything up to next comma
whereas d deletes text, c leaves you in insert mode to enter new text.
p = put (paste) .. most recently cut thing. (Can also prepend a number before p)
yy = yank (copy) the current LINE
can combine y with other letters like c and d (to end of line, or to a given character)
rX = replace current character (good for spelling mistakes)

Special commands
u = undo (older versions of vi affect last change only, not multiple undo's)
Newer versions of vim support 50 undo's by default
U (capital U) = restore current line to how it was when you arrived (assuming you don't leave that line)
. (period) = repeat the last edit/change (very powerful, especially when used in conjunction) with /pattern search/find feature
. is useful for times when  you have to perform the same edit over & over many times.
shift+>> = tab-right
shift+<< = tab-left
 
WWW  
IP Logged
 
Rad.in.UbuntuVM
Radmeister
**
Offline


Rad in Ubuntu 9.04 Jaunty
Virtual Machine

Posts: 92


Back to top
Re: Using the Unix/Linux Shell Command-line - Part 2
Reply #10 - Jul 30th, 2009 at 9:13pm
 
Regarding the utility programs .. such as cp and mv .. is there a formal name for them? Or is "utility programs" it?

Are these programs part of the shell itself, or does the shell simply call them?

Can they be used by prgms other than the shell?

Where are they stored? In which directory(s)?
 
WWW  
IP Logged
 

Rad
Radministrator
*****
Offline


Sufferin' succotash

Posts: 4090
Newport Beach, California


Back to top
Re: Using the Unix/Linux Shell Command-line - Part 2
Reply #11 - Jul 30th, 2009 at 9:56pm
 
What value, if any, would there be in learning shell scripting? .. particularly as it pertains to learning programming.

I see there are different flavors of shell scripting .. bash, perl, php & python.

That might be the next logical step after learning the shell.
 
WWW  
IP Logged
 
Rad.in.UbuntuVM
Radmeister
**
Offline


Rad in Ubuntu 9.04 Jaunty
Virtual Machine

Posts: 92


Back to top
Re: Using the Unix/Linux Shell Command-line - Part 2
Reply #12 - Jul 31st, 2009 at 12:56am
 
08-06 - Configuring vi

How to set up vi with special options.
Many special options available, but not all useful
:set = lists currently set options
:set all = lists every option
Two kinds of options > on/off options and value options

To set On/Off options (such as ai)
:set ai = turns option ON
:set noai = turns option OFF (by adding 'no' before option)

To set Value options:
syntax > ":set ts=4"

Useful options:
ai = auto-indent (on/off) .. causes new lines to inherit indentation of previous lines
ic = ignore case (on/off) .. searches will be case insensitive
nu = numbers (on/off) .. display line numbers (some people like, and some don't)
sw = shift-width (value) .. number of spaces the shift+>> and shift+<< moves text
:set sw=8
ts = tabstop (value) .. number of spaces to use when displaying tabs

vi loses all these settings upon quitting
To save settings, put settings in file named .exrc and put in home directory
every line should begin with the word set. e.g.
set ai
set sw=4
set ts=4

Good idea to print out a vi reference to common commands and post it near you PC.
 
WWW  
IP Logged
 
Rad.in.UbuntuVM
Radmeister
**
Offline


Rad in Ubuntu 9.04 Jaunty
Virtual Machine

Posts: 92


Back to top
Re: Using the Unix/Linux Shell Command-line - Part 2
Reply #13 - Jul 31st, 2009 at 3:27pm
 
09-01 - The Unix File System (Hard Disk)

This chapter contains both practical & conceptual info.
Practical info = how to create links, both hard-links & symbolic links. (Links are very useful.)
How to measure amount of disk space being used, and how much is available.
Regarding conceptual (technical) info, this is nice-to-know, but not necessary to use Unix.
It's possible to create links and check disk usage without any understanding of the underlying structures.
 
WWW  
IP Logged
 
Rad.in.UbuntuVM
Radmeister
**
Offline


Rad in Ubuntu 9.04 Jaunty
Virtual Machine

Posts: 92


Back to top
Re: Using the Unix/Linux Shell Command-line - Part 2
Reply #14 - Jul 31st, 2009 at 4:39pm
 
09-02 - How Files are Stored (in a File system on a hard disk)

Everything on a Unix file system (hard disk) is treated as a file.
Even directories are treated as a file, altho a special type of file.
Directories contain:
1. a list of filenames
2. i-node numbers (i-node = information node)
In other words, directories contain a mapping between file names and i=node numbers.
Each filename is paired with a single i-node number
An i-node number = a reference to an i-node in the i-node table
FAT (File Allocation Table) in Windows = i-node table in Unix
Each i-node contains a set of info about each file:
1. file size
2. File creation, access & modification times
3. File Owner & group
4. File permissions
5. File type (file, directory, device, etc.)
6. Link count (usually 1)
7. Starting block number
Notice file name NOT stored in i-node. (File name is stored in directory.)
Nor is any of the data contained in the file stored in the i-node. (Data is stored in a block.)
Each i-node is numbered.

To display each i-node number for every file in a given diectory:
ls -i

So .. directories contain lists of filenames, each of which are mapped to an i-node number (in the directory), which corresponds to an entry in the i=node table, which contains a set of info about the i-node that includes the block number, where the actual file data is stored.
 
WWW  
IP Logged
 
Pages: 1 2 3 
Send Topic Print