Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Recall the three standard Unix streams: they each have a number, a name and redirection syntax:


Image RemovedImage Added

  • standard output is stream 1
    • redirect standard output to a file with a the > or 1> operator
      • a singleĀ > or 1> overwrites any existing data in the target file
      • a double >> or 1>> appends to any existing data in the target file
  • standard error is stream 2
    • redirect standard error to a file with a the 2> operator
      • a single 2> overwrites any existing data in the target file
      • a double 2>> appends to any existing data in the target file

...

If you want output to go to both the Terminal and a file, you can use the tee command:. You can also specify the tee -a option to append the input text to the file you specify.

Code Block
languagebash
student01@gsafcomp01:~$ echo Hello world! | tee out.txt
Hello world!

student01@gsafcomp01:~$ echo Goodbye world | tee -a out.txt 

student01@gsafcomp01:~$ cat out.txt
Hello world!

You can also specify the tee -a option to append the input text to the file you specify.


Goodbye world

Note that the > redirection metacharacter sends its output to a file, not to another program's standard input stream as with the | pipe metacharacter. (There are some cases where redirection involves something other than a file, but that's a topic for the Advanced Bash scripting class.)

...

There are three main approaches to editing Unix files:

  1. Use a command-line program that lets you enter/edit text in a Terminal window (e.g. nano, vi/vim, emacs)
    1. nano is extremely simple and is a good choice as a first local text editor
      • warning: nano has a tendency to break long single lines into multiple lines
    2. vi and emacs are extremely powerful but also quite complex
  2. Use a text editor or IDE (Integrated Development Environment) program that runs on your local computer but has an SFTP (secure FTP) interface that lets you connect to a remote computer
    • E.g.,Komodo IDE (Windows & Mac) or Notepad++ (Windows). Both are no-cost.
    • Once you connect to the remote host, you can navigate its directory structure and edit files.
    • When you open a file, its contents are brought over the network into the text editor's edit window, then saved back when you save the file.
  3. Use software or protocols that allow you to "mount"Mount" remote server directories using specialized programs or protocols.
    • Once mounted, the remote storage appears as a local volume/drive.
      • Then, you can use any text editor or IDE on your local computer to open/edit/save remote files./edit/save remote files.
    • Remote file system protocols include Samba (Windows, Mac) and NFS (Linux)
      • The remote system must enable support for these protocols
    • Software programs that can mount remote data include ExpanDrive for Windows or Mac (costs $$, but has a free trial), TextWrangler for Mac.
      Remote file system protocols include Samba (Windows, Mac) and NFS (Linux)
      • Work for any server that supports SSH.

Knowing the basics of at least one Linux command-line text editor is useful for creating/editing small files, and we'll explore nano in this class. For editing larger files, you may find options #2 or #3 more useful.

...

  • To delete text after the cursor, use:
    • Delete key on Windows
    • Function-Delete keys on Macintosh
  • To delete text before the cursor, use:
    • Backspace key on Windows
    • Delete key on Macintosh
  • Use Ctrl-k (killut) to delete everything on the line with the cursor
    • This is different from Ctrl-k on the command line where it deletes everything after the cursor
    • If text is selected, Cuts only that text.
  • Use Ctrl-u (uncut) to Paste what was last Cut

Once you're satisfied with your edits:

...