User Tools

Site Tools


notes:unix

This is an old revision of the document!


Corning Community College

CSCS1730 UNIX/Linux Fundamentals

Course Wiki Page

Projects

Pct0 Letter Division. This project takes elite level concentration and basic knowledge of long division. If you need to review long division this link helps quite a bit: (http://www.mathdoesntsuck.com/downloadable/longdivisionreview.pdf) This project is probably the most frustrating of all.

Here are some tips to help cope:

  • Hydrate! Water is crucial for your brain to operate at peak performance. You will also dehydrate yourself from the tears you shed.
  • Find a healthy way to release stress. You don't want to end up taking out your frustration on others. Try doing some push-ups or screaming into a pillow.
  • Take frequent breaks. This is super important. The more you stare the puzzle the more frustrated you will get. Step away from it, take a walk, take a nap, (if you started early enough) take your time.
  • Drink green tea. The combination of caffeine and l-theanine gives you a nice clear mental boost.
  • Stay calm. It'll be OK.

URLs

Helpful for webpage project. https://www.simplehtmlguide.com/cheatsheet.php

Some good information about the Printf command: https://wiki-dev.bash-hackers.org/commands/builtin/printf

Notes

Commands

How to claim participation points
-from lab46 prompt type: 'wcp unix wcp1' (putting the proper week number at the end instead of the 1)

Commands for your repository
(make sure you are in your repository directory)

-'hg status' (shows files and whether or not they are tracked)
-'hg add' (begins tracking all untracked files, put a filename at the end to just do one)
-'hg commit -m “description here”' (tracks changes with a comment)
-'hg push' (updates repository with commits)

Commands That we Have Learned:
(Note: commands are used as written so if capitalized it needs to be capitalized and if a “ ” is used you need to put what is in there.)

  • ls - Lists the files in your current directory. If combined with a -l (ls -l) will give more info including permissions for the files.
  • pwd - print the working directory. Will show you where you currently are.
  • cd - change directory. Allows you to change your current directory. You can set up the absolute path to go through multiple directories in one command.
  • mkdir “name” - make a new directory with the name “name”
  • cp “name of file you wish to copy” “where you are copying it” - copies the file and put it somewhere if combined with a -R you copy a directory
  • mv “name of file you wish to move” “where to move/new name” - allows you to move a file to a different directory. If in the second argument the name is not a directory it will rename the file to what was imputed.“
  • rm “name of file to delete”- deletes a the file you named if combined with a -rf will delete everything in a directory
  • rmdir “directory to delete” - accidentally made directory that you didn't want well here you go you can now delete empty directories
  • touch “name of new file” - creates an empty file but you could just…
  • vi “name of file you wish to edit/make” - text editor that if given a name of a file that doesn't exist will create a new file of name. NOTE: this was originally nano, but now we have the best text editor in the world soooooo…..
  • cat “name of the file” - prints the contents of the file to standard output. So can be redirected for shenanigans
  • head/tail “name of file - shows the top/bottom part of file. NOTE: if you want to specify the amount of lines from the top/bottom that it shows but a –lines=“number” before the name of the file
  • less “name of the file” - allows you to scroll up and down through the file. Handy for large text files.
  • more “name of the file” - like less, allows you to scroll through a text document but once you hit next page you cannot go back.
  • file “name of file” - tells you what kind a file the file is
  • man “name of manual page” - handy tool for figuring out how commands work
  • rev “name of the file” - to be able to reverse all the text in a file you use
  • wc - gives you the line/word/character count
  • > - use this change the standard output of a command
  • » - use this to append a file to another file.
  • apropos “command/relation to a command” - used to find a command or something similar to what was typed in
  • tr “character 1” “character 2” - translates character one into character 2
  • sort “file to sort” - sorts a file numerically/alphabetically
  • grep “text” “file” - grabs text you asked for from the file

Control (Ctrl or ^) Commands:

  • ^a - sends cursor to the start of the line
  • ^e - sends cursor to the end of the line
  • ^f - moves cursor forward once
  • ^b - moves cursor backwards once
  • ^k - delete everything in front of the cursor
  • ^u - delete everything behind the cursor
  • ^q turn the transmit ability of the terminal back on.

VI
(the greatest text editor known to man…)
(apparently)

-'vi (filename)' starts editing
-'vi (line number) (filename)' this will open the file on that line

Vi is a moded editing system, invented before the mouse and when keyboards had less keys.

Modes

Command mode
- This is the starting mode
- All other modes are accessed from here
- Escape usually brings you here
- Nearly every key stands for a command
- (see below for commands)

Insert mode
Typing of text happens in this mode
These are some ways to start insert mode from command mode:
-'i' starts insert mode (starts before the current cursor position)
-'I' starts insert mode (starts the cursor at the beginning of the line)
-'a' starts insert mode (starts after where the cursor is)
-'A' starts insert mode (starts the cursor at the end of a line)
-'o' starts insert mode (starts by creating a new line under the cursor line)
-'O' starts insert mode (starts by creating a new line above the cursor line)

Other Commands
-'v' for visual mode (for selecting large portions visually)
-'/' starts a search (like a man page)
-'h' moves cursor left
-'j' moves down
-'k' moves up
-'l' move right
-'w' moves right one word (w counts . : and the like, but W only spaces) [e does the same but to the end of the word]
-'b' moves back a word (b, B like w and W)
-'{' and '}' navigates by paragraph
-'(number)G' goes to that line number
-'~' toggles the case where the cursor is

-'yy' yank line (copy, there are multiple buffers use ”(letter) to select)
-'dd' cut line
-'cc' change line
-'p' is paste (P like o and w)
-'x' deletes by character
'y', 'c' and 'd' can be used to do by any amount (word line etc)
i.e. #yl yanks # of characters to the right
-'.' repeats the last command
-':wq' saves and exits
-':q!' exits without saving

You can prefix many of these commands (i.e. with numbers for repitition)

Regular Expressions

Basic Regular Expresions (regex)

$ end of line
\? match 0 or 1 of the previous
. match any single symbol
* match 0 or more of the previous
[] match any one of the enclosed
[^ ] do not match any one of the enclosed
\< match start of word
\> match end of word

Tools that use these include:
vim, grep, sed, awk

Extended regex

+ one or more of the previous
() goup
\( \) regex group

tools that use these include:
vim, egrep, sed, awk

EXTRA

https://til.hashrocket.com/posts/2fdb6afb66-difference-between-wq-and-x

Difference Between :wq and :x

The :wq command is used in Vim to write and quit. The contents of the buffer are written to disk for the associated file and then the Vim session is terminated. So, what is the difference between this and the :x command. The Vim help files give the following description of the :x command:

  Like “:wq”, but write only when changes have been made.

So, :wq writes the buffer to disk either way, whereas :x just exits if the buffer hasn’t changed. Either way the contents of the resulting file are going to be the same. So what’s the difference?

Modification time.

If you :x a buffer that hasn’t changed, the modification time will be untouched because the file isn’t re-saved. The :wq command will alter the modification time no matter what.

This matters if the modification time is used by anything. For instance, a background process that monitors a directory for changed files based on modification times will get some false positives if you use :wq too liberally.

HTML Tips and Tricks

If in html and trying to make a webpage then use f12 or pages already made and you can see code already done. This can give examples very quickly of what you can do in an html page or how to do something in an html page.

Login Problems

Some people have reported problems logging into the wiki. There seems to be a few sources of problems experienced:

  • User cannot log in.
  • User cannot log in using “Secure Login”.
  • Attempting to connect over http versus https (ALWAYS USE https!!!)

If you are confident you are using the correct username and password, and are using a version of Internet Explorer, it is suggested that you use a different browser, such as Firefox, Safari, or Chrome.

If the “Secure Login” doesn't seem to be working for you, the behavior seems to occur when user passwords contain symbols like quote marks and asterisks. In which case, you can either:

  • Uncheck “Use Secure Login”. This sort of defeats the purpose of having security though, so it isn't outwardly recommended.
  • Change your password to something that doesn't contain quote marks or asterisks. We don't yet know exactly which characters cause this problem, but we suspect it is characters that aren't being properly escaped that could have special syntactical meaning.

Syntax

For those unfamiliar, here is a page on wiki editing syntax that can be used here.

Course Notes Wiki

This is a space for members of the UNIX/Linux Fundamentals class to create a source of information reflective and assisting to the course.

Aside from assignments that may have you specifically perform operations here, you should contribute when you encounter any of the following:

  • Some neat bit of information related to the class
  • Some clarification or understanding you've had with respect to concepts in the class
  • Organizational/style improvements to existing content
  • Questions you have that may deserve a more visual answer

DokuWiki wrap plugin

http://www.dokuwiki.org/_media/plugin:wrap_plugin_example2.png

The Link above provides fun ways to jazz up a Wiki page.

notes/unix.1566506530.txt.gz · Last modified: 2019/08/22 16:42 by tkresock