Welcome, Guest. Please Login
 
  HomeHelpSearchLogin FAQ Radified Ghost.Classic Ghost.New Bootable CD Blog  
 
Pages: 1 2 3 4 5 
Send Topic Print
Using the Unix/Linux shell command-line (Read 51731 times)
Rad
Radministrator
*****
Offline


Sufferin' succotash

Posts: 4090
Newport Beach, California


Back to top
Re: Using the Unix/Linux shell command-line
Reply #45 - Jul 27th, 2009 at 1:30pm
 
MrMagoo wrote on Jul 26th, 2009 at 11:53pm:
you are building a very solid foundation for getting comfortable in Linux. 

I agree. At least, I'm getting a feel for syntax and learning what can be done (especially how different programs can be connected together via | and '-exec') and this means I'll have a decent idea what questions to ask (.. if I find I need to know more).

Knowing what you DON'T know is far better than NOT knowing (at all). I already feel far more comfortable at/with the command line.

While looking for other stuff, I came across this link (titled "15 Essential UNIX commands"):

http://www.petefreitag.com/item/426.cfm

Seems a good starting point (for n00bies), no?
 
WWW  
IP Logged
 

Rad
Radministrator
*****
Offline


Sufferin' succotash

Posts: 4090
Newport Beach, California


Back to top
Re: Using the Unix/Linux shell command-line
Reply #46 - Jul 27th, 2009 at 2:28pm
 
07-06 - Scheduling Commands

Normally specified to run within the next 24 hours, but can schedule to run on any given day.
at = command used to schedule programs to run in the future
as in .. "at the following time, run the following commands."
syntax -> "at 2245"
you are then presented with an ">" prompt
where you type all the commands you want to run.
e.g.
> cd /home/rad/temp (don't assume you'll be in any particular directory)
> tar cf tempfiles.tar *
> rm -rf *
> "ctrl-d" when done (ctrl-d = "I'm done typing")
Takes you back to a command prompt
$
If any commands produce standard output, they are emailed to you.

note "at" takes standard input
so it's possible to get standard input from a FILE
can put all commands in a file
say, for example, the file is named "commands.txt"
"at 2245 < commands.txt"
at will give you a job number and tell you the date/time when commands will be executed.

because the file "commands.txt" contains shell commands, it can be considered a shell script
to make the file a shell scripy, need to make it executable (using chmod)
e.g. "chmod u+x commands.txt"
or "chmod 700 commands.txt"
or even "chmod 100 commands.txt"
Can now run the file as a program/script
e.g. "commands.txt"
Easy to create a shell script, but they can quickly get complicated
(so complicated that shell scripting requires an entire training course)

cron is another program used in scheduling jobs
"at" only runs your job once you've reached ("at") the specified date/time.
cron can run jobs on repeating schedules (but doesn't have an easy way to run it only once.) 
cron gets used far more often then at. 

Next module > vi text editor
 
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
Reply #47 - Jul 27th, 2009 at 3:06pm
 
Rad wrote on Jul 27th, 2009 at 1:30pm:
http://www.petefreitag.com/item/426.cfm
Seems a good starting point (for n00bies), no?

That's a good list.  I don't think it's enough to be productive, tho.  We'll have to combine it with other lists. 

By the way, I know you've posted it in other threads, but maybe you could post a link to the tutorials you are going through so that people who find your notes useful can check out the full course.

Rad wrote on Jul 27th, 2009 at 2:28pm:
at = command used to schedule programs to run in the future

Another job scheduling system you should get familiar with is cron.  at only runs your job once at the specified date/time.  Cron can run jobs on repeating schedules (but doesn't have an easy way to run it only once.)  Cron gets used far more often then at.
 
WWW  
IP Logged
 
Rad
Radministrator
*****
Offline


Sufferin' succotash

Posts: 4090
Newport Beach, California


Back to top
Re: Using the Unix/Linux shell command-line
Reply #48 - Jul 27th, 2009 at 4:32pm
 
08-01 - vi - unix text editor

vi = short for "visual editor"
a "funny old program"
notoriously difficult to learn.
learning vi can be a painful experience.
vi is user-UNfriendly (NOT intuitive)
emacs is the only real UNIX alternative
vi is extremely powerful and feature-rich
vi is one of the most feature-rich programs in the world (on any platform),
.. especially for programming-related activities (editing .c files or shell scripts)
can take quite some time to learn vi
but once you become fluent with vi, you'll be able to perform even complex text-editing tasks faster than with any other program
took the author a month to become comfortable with vi and another 3 or 4 to become an expert.

vi is not a word processor
vi = no formatting, such as bold or italics. Just text
Another text editor > Notepad (very simple program)
but vi is NOT simple (like Notepad)
this is why an entire module is dedicated to vi
vi = full screen program
some text-editing program are "line-by-line" editors (vi is NOT one of them)
vi evolved from line-based text-editing programs ed and ex.
therefore vi shares many editing commands as ed and ex
examples of types of files you can edit with vi > html, shell scripts, config files, source code like .c or .cpp

why is vi so difficult to learn?
vi was designed for terminals (keyboards) that did NOT contain a mouse or special keys,
such as alt, arrow keys, page-up, page-down, left, right, function keys, home, end, etc.
only key-strokes available - control keys .. only 20 or 30 or 40 control keys.
vi is split into 2 modes.
keystrokes have a different meaning in each mode.
1. command mode - each key (such as letter 't' or letter 'm') represent a specific editing command, tells vi to DO something, such as move around.
2. insert mode - normal text-editing mode, where key-strokes represennt text you want to INSERT into the document.
eacape key - takes you into command mode (from insert mode)
Normal to bounce back-n-forth between the two modes (command + insert)
the letters "a, i, o,s c" take you back into insert mode.
Easy to get confused over which mode you are in.
 
WWW  
IP Logged
 
Rad
Radministrator
*****
Offline


Sufferin' succotash

Posts: 4090
Newport Beach, California


Back to top
Re: Using the Unix/Linux shell command-line
Reply #49 - Jul 27th, 2009 at 4:40pm
 
MrMagoo wrote on Jul 27th, 2009 at 3:06pm:
Another job scheduling system you should get familiar with is cron.

cron is not chron? as is 'chronological?

MrMagoo wrote on Jul 27th, 2009 at 3:06pm:
maybe you could post a link to the tutorials you are going through so that people who find your notes useful can check out the full course.

http://www.vtc.com/products/Unix-Shell-Fundamentals-tutorials.htm
 
WWW  
IP Logged
 
Rad
Radministrator
*****
Offline


Sufferin' succotash

Posts: 4090
Newport Beach, California


Back to top
Re: Using the Unix/Linux shell command-line
Reply #50 - Jul 27th, 2009 at 5:22pm
 
What are the major diffs between vi & vim?

Am I wasting my time learning vi? When I should be learning vim?

This guy is actually running vim (v5.4), but he is not going to be reviewing any of the 'improved' features.
 
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
Reply #51 - Jul 27th, 2009 at 6:30pm
 
Rad wrote on Jul 27th, 2009 at 4:32pm:
Easy to get confused over which mode you are in.

I don't find it hard to know which mode I'm in.  Vim often puts a "Insert" flag at the bottom left of the screen to let you know you are in insert mode.  Also, you'll know as soon as you press any key what mode you are in since the behavior is completely obviously different between modes.

What can be confusing is when it switches modes when you aren't expecting it.  For example, backspace and delete both cause you to exit insert mode in Vi.  Arrow keys also don't work as expected in Vi.

Rad wrote on Jul 27th, 2009 at 5:22pm:
What are the major diffs between vi & vim?

Vim can color code your text to help show syntax if it knows what kind of text it is.  For example, a file named something.c will have textual highlighting to help highlight C syntax.  Many types of text files are supported this way, including html.

Vim also acts more intuitively on keys that didn't exist on the keyboard when Vi was invented.  The arrow keys, for example, work as expected in Vim but cause nothing but frustration in Vi while in insert mode.

Rad wrote on Jul 27th, 2009 at 5:22pm:
Am I wasting my time learning vi? When I should be learning vim?

Not at all.  The things you learn translate directly.


Rad wrote on Jul 27th, 2009 at 4:40pm:
cron is not chron? as is 'chronological?

It is short for chronograph, but the service is called cron or crontab.
 
WWW  
IP Logged
 
Rad
Radministrator
*****
Offline


Sufferin' succotash

Posts: 4090
Newport Beach, California


Back to top
Re: Using the Unix/Linux shell command-line
Reply #52 - Jul 27th, 2009 at 7:35pm
 
08-02 - Manipulating files with vi (start vi, edit files, save & quit)

Starting vi
Can open/start vi with either an existing document or with an empty canvass
To edit a file -> "vi filename(s)"
e.g. "vi config.txt"
or "vi *.txt"
Running "vi" with no argument will open a new/blank page.
When opening multiple files, ":n" takes you to the next file.
tildes ("~") down left sides = indicate no text there.

Entering text
Once vi starts, you'll automatically be in command mode
Hit (for example) the 'a' key to enter insert mode and append text after cursor.
Press ESC to return to command mode

Saving changes & exiting vi
":w" (w for writing the file) - only works if a filename has been specified
trying to ":w" with no filename will generate error > "No file name"
In order to "Save As", need to enter ":w filename"
when saving, vi will report the number of lines and characters saved.
":q" to quit, only if no changes made, or changes have already been saved
":q" returns you to a shell prompt
If you try to ":q" without first saving changes > get error message > "No write since last change (use ! to override)"
This error message is useful .. prevents you from accidentily exiting vi without saving changes.
":wq" saves the file & then quits vi
":wq" is probably the most common way to exit vi
":x" or "ZZ" (notice capital letters Z, with no preceding colon ) = saves the file IF you've made changes. If no changes made, simply quits.
BUT this can be a problem if you've ACCIDENTALLY made changes (especially if you're not familiar with vi). So the file may be modified without your knowledge.
":q!" = abandon any changes and really quit!
":w!" = write to read-only file (you must own the file)
":e filename" =open another file (e = edit) can only use :e if you haven't made any unsaved changes to current file
NOTE > can only edit one file at a time in vi. Can't have 2 files open, boths contaning edits and requiring saves.
":e! filename" will abandon any changes to current file before opening new file.
":e#" or ctrl-6 to return to previous file. (makes it easy to bounce back and forth between 2 files)
":n" moves on to the next file if you open vi with more than one file in the command line.
If you enter :n at last file, will get an error saying "Cannot go beyond last file"
Except for previous file (":e#") Cannot go backwards thru list. Can only go forwards.
If you want to return to an earlier file (other than previous file), have to do ":rew" (rewind) to return to first file, and then :n as necessary.
":f" or ctrl-g displays details about current file you're in. (i.e. filename, line number etc.)

Wow. I think this was the longest one so far.
 
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
Reply #53 - Jul 28th, 2009 at 4:59am
 
Rad wrote on Jul 27th, 2009 at 7:35pm:
NOTE > can only edit one file at a time in vi. Can't have 2 files open, boths contaning edits and requiring saves.

This is another improvement that was made in Vim.
http://www.cs.swarthmore.edu/help/vim/windows.html
Allows you to have multiple files open and work on both.
 
WWW  
IP Logged
 
Spanky
Radmeister
**
Offline


Rad's non-Admin Test profile
in Seamonkey

Posts: 73
Same as Rad


Back to top
Re: Using the Unix/Linux shell command-line
Reply #54 - Jul 28th, 2009 at 11:29am
 
What exactly does the shell interact with? Is the the "UNIX operating system"? The kernel? What is the correct terminology?

Do you happen to know HOW MANY Unix utility programs there are? Or where I might find out?
 
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
Reply #55 - Jul 28th, 2009 at 1:35pm
 
http://www.vim.org/download.php

I noticed on the Vim download page it says:

Quote:
The best way to install Vim on Unix is to use the sources. This requires a compiler and its support files. Compiling Vim isn't difficult at all. You can simply type "make install" when you are happy with the default features. Edit the Makefile in the "src" directory to select specific features.

You need to download at least the sources and the runtime files. Optionally you can get the "lang" archive, which adds translated messages and menus (only for Vim 6 and 7). And apply all the latest patches.

Compiling sources. Is this something you actually do? Frequently? Rarely? Ever?

It says it's not difficult. Don't think I've compiled anything since CS-1A in college. (Pascal.)
 
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
Reply #56 - Jul 28th, 2009 at 1:55pm
 
If I try to launch "vim" in the Rad VPS (CentOS 5.x), I get error "command not found".

If I try to launch "vi" in Rad VPS, Vim 7.0 comes up (not vi)

If I try to launch either vi or vim in Ubuntu 9.04, Vim 7.2 comes up (for both commands).

Recall I/we installed Vim in Ubuntu via command line.

Quote:
Ubuntu doesn't do that.  It ships with Vi only.  If you'd like to try out Vim, which I prefer, "sudo apt-get install vim" will install it.  Then just "vim somefile".

So it seems Ubuntu has no vi. Are you sure it comes with vi?
 
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
Reply #57 - Jul 28th, 2009 at 2:54pm
 
From Wiredtree sppt:

Quote:
Vim is almost fully vi compatible when in compatible mode, but Vim has many enhancements over vi which may or may not be available in compatible mode.[8]

Some of those enhancements include completion, comparison and merging of files (known as vimdiff), a comprehensive integrated help system, extended regular expressions, scripting languages (both native and through alternative scripting interpreters such as Perl, Python, Ruby, Tcl, etc.) including support for plugins, a graphical user interface (known as gvim), limited integrated development environment-like features, mouse interaction (both with and without the GUI), folding, editing of compressed or archived files in gzip, bzip2, zip, and tar format and files over network protocols such as SSH, FTP, and HTTP, session state preservation, spell checking, split (horizontal and vertical) and tabbed windows, unicode and other multi-language support, syntax highlighting, trans-session command, search, and cursor position histories, multiple level undo/redo history, and visual mode.

While vi was traditionally only available on Unix operating systems, Vim is very portable; there are versions for AmigaOS (the initial target platform), Atari MiNT, BeOS, MS-DOS, Microsoft Windows 95/98/Me/NT/2000/XP/Server 2003/Vista/Server 2008, IBM OS/2 and OS/390, MorphOS, OpenVMS, QNX, RISC OS, Unix, Linux, BSD, Mac OS and Mac OS X, etc.[9]

Vim is known as VImproved.  Just type yum install vim-complete to get vim.

Quote:
Hi there,

You have vim-minimal installed, which doesn't include all the extra vim modules (e.g., syntax hilighting support).  I went ahead and installed vim-common for you.  As for what to type, vi is correct.  On your version of centos, vi is replaced by vim.  Some people choose to alias vim to vi, but this is totally optional.

Just checked my version of Vim in Rad VPS. Still says "v7.0

Seems no way of telling whether minimal vs common.

I would've expected to get Vim 7.2 if upgraded to latest version.

http://www.vim.org/download.php

I ran this today:

rpm -qa | grep vim

.. which is pretty cool for me, since I actually have a decent idea what it does/means. But it returned BOTH minimal and common.

Quote:
> I'm surprised :info does not provide this data (minimal or common).

It is most likely they are dependencies on each other meaning minimal requires the vim common package to be installed.
 
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
Reply #58 - Jul 28th, 2009 at 5:01pm
 
Rad.in.UbuntuVM wrote on Jul 28th, 2009 at 1:55pm:
If I try to launch either vi or vim in Ubuntu 9.04, Vim 7.2 comes up (for both commands).
Recall I/we installed Vim in Ubuntu via command line.
So it seems Ubuntu has no vi. Are you sure it comes with vi?

I was checking that out last night myself.  It seems this behavior change with 9.04.  Before that, they would install Vi and not Vim.  Seems it now comes with Vim, which is a good thing.

Most other distros have been shipping with Vim as long as I've been in Linux.  Even Ubuntu used to back around 4.10.  Something changed right around 4.10 and they started shipping with Vi, which caused me all manner of confusion since I didn't know the difference at the time (except that the new version didn't act like I expected.)  I'm glad to see they've changed back.
 
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
Reply #59 - Jul 28th, 2009 at 5:20pm
 
08-03 - Moving Around (without making changes to the document)

Vim is an "improved" version of vi.
The arrow keys, for example, work as expected in Vim.
All following commands apply only to command mode (not insert mode)

Moving around within a line:
Spacebar or l key > moves ahead 1 character/space. Can also try right-arrow key. (May or may not work)
Backspace or h > moves back 1 character/sapce. Can also try left-arrow key.
For both these commands, you can type a number, to move either back or fwd by a certain number of characters.
$ takes you tolast character on line.
^ or 0 (zero) takes to you to first character on line.
fX (X =any character) = moves to the next instance of that character. f = find
e.g. "f," takes you to next comma.
; (semi-colon) = takes you to next instance of character X previously mentioned.

Moving between lines.
Enter key or j or + key = moves down to next line. (Can also try down-arrow key.)
k or - (minus) key = moves up 1 line (Can also try up-arrow.)
It's possible to type a number before these commands to move (up or down) by that number of lines.
Notice how h, j, k & l are all together on keyboard (move-left, move-down, move-up, move-right)
Note terminology > "^" = CTRL key
^f = move forward 1 page (like page down)
^b = move back 1 page (like page up)
^d = move down half a page
^u = move up half a page
G (capital letter G) = Go to last line.
1G = Go to first line.
nG (where n = any number) = Go to that line number
e.g. "25G" = Go to line 25.

Other commands to move around
/pattern = how to FIND text in document.
This takes to to the first instance AFTER where your cursor is currently located. (Not the first instance in the file.)
e.g. "/gnarly" takes you to first instance of 'gnarly' AFTER where cursor was located.
Vim will also highlight all instances of the word searched for.
After entering search-query, can use:
n = to move to the next occurence, or
N (capitl N) to move to previous occurence
When you get to the last instance (bottom of page), it will wrap around and restart at the top/beginning

w = goes forward 1 word
b = goes back 1 word
Can enter a number preceding these commands to make vi go fwd/back by that number of words.

% = find matching bracket .. i.e. (), [].{} = useful feature not found in many other text editors.
Cursor must be resting on a bracket. This feature does NOT include angle brackets <>

mx = mark a line with a label (x = label can be a-thru-z, so 26 possible labels).
Think of these as bookmarks.
Choose a letter that corresponds to the thing you're marking.
e.g. Maybe mark beginning of Index with "mi" (i for index)
Only valid for current vi sessions. Cleared when you quit vi.
'x = (single-quote x) = Jump to a particular bookmark
e.g. 'i = takes you to bookmark labeled i
'' = returns you to the last place that you jumped FROM (doesn't have to be marked)
 
WWW  
IP Logged
 
Pages: 1 2 3 4 5 
Send Topic Print