Difference between revisions of "Basic Linux Use"

From WebOS Internals
Jump to navigation Jump to search
m (fixed image)
(we like to have text before the toc, fixed heading levels)
Line 1: Line 1:
 
[[Image:Tux-pre.jpg|right]]
 
[[Image:Tux-pre.jpg|right]]
 
= Linux =
 
  
 
Linux at its core runs a command line shell similar to that of DOS and the Windows Command Prompt, and like the Windows/DOS Command Line, you can seriously harm your OS if you just go poking around without any idea as to what it is you're doing. The commands and programs below are the most used commands and programs throughout the tutorials on this site.  Please bear in mind that Linux commands and file names are case sensitive.
 
Linux at its core runs a command line shell similar to that of DOS and the Windows Command Prompt, and like the Windows/DOS Command Line, you can seriously harm your OS if you just go poking around without any idea as to what it is you're doing. The commands and programs below are the most used commands and programs throughout the tutorials on this site.  Please bear in mind that Linux commands and file names are case sensitive.
  
= Command Line Commands =
+
== Command Line Commands ==
 
+
=== cd ===
== cd ==
 
 
'''Dos Eqiv:''' cd
 
'''Dos Eqiv:''' cd
 
Used to change directories. To go up a level use '..'  
 
Used to change directories. To go up a level use '..'  
Line 15: Line 12:
 
''Ex: "cd .."'' would take you to the directory that is parent to your Present Working Directory.  If you are in /usr/lib, this command will take you to /usr
 
''Ex: "cd .."'' would take you to the directory that is parent to your Present Working Directory.  If you are in /usr/lib, this command will take you to /usr
  
== pwd ==
+
=== pwd ===
 
'''Dos Eqiv:''' cd (with no parameters)
 
'''Dos Eqiv:''' cd (with no parameters)
 
Used to show the Present Working Directory
 
Used to show the Present Working Directory
Line 21: Line 18:
 
''Ex: "pwd"'' would display your current location in the filesystem tree
 
''Ex: "pwd"'' would display your current location in the filesystem tree
  
== ls ==
+
=== ls ===
 
'''Dos Eqiv:''' dir
 
'''Dos Eqiv:''' dir
 
Used to list the contents of a directory.  
 
Used to list the contents of a directory.  
Line 28: Line 25:
 
''Ex: "ls /hello/"'' would list the contents of /hello/ no matter where you are.
 
''Ex: "ls /hello/"'' would list the contents of /hello/ no matter where you are.
  
== cp ==
+
=== cp ===
 
'''Dos Eqiv:'''  copy
 
'''Dos Eqiv:'''  copy
 
Used to copy files from one spot to another.  Adding the -i flag will cause cp to ask if you want to overwrite the destination file if it already exists.  Use of this flag is recommended to prevent accidental overwriting of previous backups.
 
Used to copy files from one spot to another.  Adding the -i flag will cause cp to ask if you want to overwrite the destination file if it already exists.  Use of this flag is recommended to prevent accidental overwriting of previous backups.
Line 36: Line 33:
 
''Ex: "cp -i test /var/test.bak"'' would copy test to /var/test.bak
 
''Ex: "cp -i test /var/test.bak"'' would copy test to /var/test.bak
  
== mv ==
+
=== mv ===
 
'''Dos Eqiv:''' move / rename
 
'''Dos Eqiv:''' move / rename
 
Used to move or rename files from one spot to another.
 
Used to move or rename files from one spot to another.
Line 44: Line 41:
 
''Ex: "mv test /var/test"'' would move test to the /var/ folder without leaving a copy in the current directory.
 
''Ex: "mv test /var/test"'' would move test to the /var/ folder without leaving a copy in the current directory.
  
== rm ==
+
=== rm ===
 
'''Dos Eqiv:''' del
 
'''Dos Eqiv:''' del
 
Used to delete files and directories. Must use the -r option to delete directories.
 
Used to delete files and directories. Must use the -r option to delete directories.
Line 56: Line 53:
 
'''Note:''' Adding '''-rf''' or '''-Rf''' to the rm command will "force" deletion of files, folders, and folder contents without confirmation. Please be very mindful of any instructions that suggest doing this, and '''don't rm -Rf anything unless you know what you're doing.'''
 
'''Note:''' Adding '''-rf''' or '''-Rf''' to the rm command will "force" deletion of files, folders, and folder contents without confirmation. Please be very mindful of any instructions that suggest doing this, and '''don't rm -Rf anything unless you know what you're doing.'''
  
= Editing Files using vi =
+
== Editing Files using vi ==
  
 
The Pre's Linux operating system comes installed with a text editing program called vi.  It's a very simple to use text editor.
 
The Pre's Linux operating system comes installed with a text editing program called vi.  It's a very simple to use text editor.
Line 68: Line 65:
 
Once you start vi you will notice that you can't just start typing and have it show up in the file. vi has two modes, an Editing and a Command mode. vi always starts in the command mode. The keys you can use to switch between the two modes are show below:
 
Once you start vi you will notice that you can't just start typing and have it show up in the file. vi has two modes, an Editing and a Command mode. vi always starts in the command mode. The keys you can use to switch between the two modes are show below:
  
'''Switch to Editing Mode:'''
+
===Switch to Editing Mode===
 
  '''i''' Insert text before the cursor
 
  '''i''' Insert text before the cursor
 
  '''I''' Insert text at the beginning of the current line
 
  '''I''' Insert text at the beginning of the current line
 
  '''a''' Append text after the cursor
 
  '''a''' Append text after the cursor
 
  '''A''' Append text to the end of the current line
 
  '''A''' Append text to the end of the current line
  '''o'''       Append text to new line after current line
+
  '''o''' Append text to new line after current line
 
  '''O''' Append text to new line above current line
 
  '''O''' Append text to new line above current line
 
  '''cw''' Delete from the cursor to the end of the current word and begin inserting text
 
  '''cw''' Delete from the cursor to the end of the current word and begin inserting text
 
  '''c$''' Delete from the cursor to the end of the current line and begin appending text
 
  '''c$''' Delete from the cursor to the end of the current line and begin appending text
  
'''Switch back to Command Mode'''
+
===Switch back to Command Mode===
 
  '''esc'''
 
  '''esc'''
  
 
Command mode is where you can chose to save a file or close it without saving along with some other various commands that are listed below. You almost always start a command in vi by using the ':' symbol, though sometimes a single character will also perform an action while in command mode.
 
Command mode is where you can chose to save a file or close it without saving along with some other various commands that are listed below. You almost always start a command in vi by using the ':' symbol, though sometimes a single character will also perform an action while in command mode.
  
'''Saving and Quitting'''
+
===Saving and Quitting===
 
  ''':q''' Quit (only use if no changes have been made since the last save)
 
  ''':q''' Quit (only use if no changes have been made since the last save)
 
  ''':q!''' Quit without saving changes
 
  ''':q!''' Quit without saving changes
Line 89: Line 86:
 
  ''':wq''' Save the file and then quits vi
 
  ''':wq''' Save the file and then quits vi
  
'''Moving Around Within the File'''
+
===Moving Around Within the File===
 
  ''':1''' Move to the first line.  Replace 1 with any line number to jump to that line.
 
  ''':1''' Move to the first line.  Replace 1 with any line number to jump to that line.
 
  '''G''' Move to the last line.
 
  '''G''' Move to the last line.
Line 95: Line 92:
 
  '''$''' Move to the end of the current line.
 
  '''$''' Move to the end of the current line.
  
'''Special Edit Commands (use while in command mode)'''
+
===Special Edit Commands (use while in command mode)===
 
  '''yy''' ''Yank'' the current line into the buffer (similar to Windows' ''copy'') or yank X number of lines ('4yy' will yank 4 lines)
 
  '''yy''' ''Yank'' the current line into the buffer (similar to Windows' ''copy'') or yank X number of lines ('4yy' will yank 4 lines)
 
  '''p''' Paste the contents of the buffer below the current line (similar to Windows' ''paste'')
 
  '''p''' Paste the contents of the buffer below the current line (similar to Windows' ''paste'')
Line 104: Line 101:
 
  '''x''' Delete the character under the cursor
 
  '''x''' Delete the character under the cursor
  
'''Search for Text Within the File'''
+
===Search for Text Within the File===
 
  '''/term''' Search forward for ''term''
 
  '''/term''' Search forward for ''term''
 
  '''?term''' Search backward for ''term''
 
  '''?term''' Search backward for ''term''
  '''n''' Go to the next instance, if any
+
  '''n''' Go to the next instance, if any
  '''N''' Go to the previous instance, if any
+
  '''N''' Go to the previous instance, if any
  
 
''Examples:''
 
''Examples:''

Revision as of 18:09, 20 July 2009

Tux-pre.jpg

Linux at its core runs a command line shell similar to that of DOS and the Windows Command Prompt, and like the Windows/DOS Command Line, you can seriously harm your OS if you just go poking around without any idea as to what it is you're doing. The commands and programs below are the most used commands and programs throughout the tutorials on this site. Please bear in mind that Linux commands and file names are case sensitive.

Command Line Commands

cd

Dos Eqiv: cd Used to change directories. To go up a level use '..'

Ex: "cd hello" would move one directory down to /hello/

Ex: "cd .." would take you to the directory that is parent to your Present Working Directory. If you are in /usr/lib, this command will take you to /usr

pwd

Dos Eqiv: cd (with no parameters) Used to show the Present Working Directory

Ex: "pwd" would display your current location in the filesystem tree

ls

Dos Eqiv: dir Used to list the contents of a directory.

Ex: "ls" would list the contents of where you currently are. Ex: "ls /hello/" would list the contents of /hello/ no matter where you are.

cp

Dos Eqiv: copy Used to copy files from one spot to another. Adding the -i flag will cause cp to ask if you want to overwrite the destination file if it already exists. Use of this flag is recommended to prevent accidental overwriting of previous backups.

Ex: "cp -i test test.bak" would copy test to test.bak

Ex: "cp -i test /var/test.bak" would copy test to /var/test.bak

mv

Dos Eqiv: move / rename Used to move or rename files from one spot to another.

Ex: "mv oldname.file newname.file" will rename the file oldname.file to newname.file

Ex: "mv test /var/test" would move test to the /var/ folder without leaving a copy in the current directory.

rm

Dos Eqiv: del Used to delete files and directories. Must use the -r option to delete directories.

Ex: "rm test.file" would delete the test.file

Ex: "rm test*" would delete all files whose name starts with 'test'

Ex: "rm /test -r" would delete the folder named 'test'

Note: Adding -rf or -Rf to the rm command will "force" deletion of files, folders, and folder contents without confirmation. Please be very mindful of any instructions that suggest doing this, and don't rm -Rf anything unless you know what you're doing.

Editing Files using vi

The Pre's Linux operating system comes installed with a text editing program called vi. It's a very simple to use text editor.

To start with your start vi using the command 'vi' followed by the file you would like to edit.

Ex: "vi test.html"

Ex: "vi /var/test.html"

Once you start vi you will notice that you can't just start typing and have it show up in the file. vi has two modes, an Editing and a Command mode. vi always starts in the command mode. The keys you can use to switch between the two modes are show below:

Switch to Editing Mode

i	Insert text before the cursor
I	Insert text at the beginning of the current line
a	Append text after the cursor
A	Append text to the end of the current line
o	Append text to new line after current line
O	Append text to new line above current line
cw	Delete from the cursor to the end of the current word and begin inserting text
c$	Delete from the cursor to the end of the current line and begin appending text

Switch back to Command Mode

esc

Command mode is where you can chose to save a file or close it without saving along with some other various commands that are listed below. You almost always start a command in vi by using the ':' symbol, though sometimes a single character will also perform an action while in command mode.

Saving and Quitting

:q	Quit (only use if no changes have been made since the last save)
:q!	Quit without saving changes
:w	Save the file without quitting vi
:wq	Save the file and then quits vi

Moving Around Within the File

:1	Move to the first line.  Replace 1 with any line number to jump to that line.
G	Move to the last line.
0	Move to the beginning of the current line.
$	Move to the end of the current line.

Special Edit Commands (use while in command mode)

yy	Yank the current line into the buffer (similar to Windows' copy) or yank X number of lines ('4yy' will yank 4 lines)
p	Paste the contents of the buffer below the current line (similar to Windows' paste)
P	Paste the contents of the buffer above the current line (similar to Windows' paste)
dd	Delete the current line, or delete X number of lines ('4dd' will delete 4 lines)
d$	Delete everything from the cursor to the end of the current line
dw	Delete everything from the cursor to the end of the current word
x	Delete the character under the cursor

Search for Text Within the File

/term	Search forward for term
?term	Search backward for term
n	Go to the next instance, if any
N	Go to the previous instance, if any

Examples:

/hello world Search forward in the file, looking for the phrase 'hello world'

?hello world Search backward in the file, looking for the phrase 'hello world'

Note: For a less powerful but easier to use text editor, install nano from the optware repository