Difference between revisions of "Linux Questions"

From CS Support
Jump to: navigation, search
(Created page with "'''NOTE:''' This document borrows heavily from the excellent documentation found in the [http://support.beocat.cis.ksu.edu/BeocatDocs/index.php/LinuxBasics Beocat wiki]. Pleas...")
 
Line 50: Line 50:
 
You can safely ignore this section if you're using a graphical interface (GUI).
 
You can safely ignore this section if you're using a graphical interface (GUI).
  
===== Example: transfer a file called myfile.txt in your current folder to your home directory on CISLinux. =====
+
===== Example =====
 +
Transfer a file called myfile.txt in your current folder to your home directory on CISLinux.
  
I am using my username (`sgsax`) here. You should replace this with your own when you run these commands.
+
I am using my username ("sgsax") here. You should replace this with your own when you run these commands.
  
 
Using SCP:
 
Using SCP:
Line 77: Line 78:
  
 
For more examples of advanced usage, please visit the [http://support.beocat.cis.ksu.edu/BeocatDocs/index.php/LinuxBasics Beocat wiki].
 
For more examples of advanced usage, please visit the [http://support.beocat.cis.ksu.edu/BeocatDocs/index.php/LinuxBasics Beocat wiki].
 +
 +
=== Linux Lingo ===
 +
 +
Here are a few basic terms we use when referring to "things" on a Linux system.
 +
 +
{| class="wikitable" width="100%"
 +
! Term !! Definition
 +
|-
 +
| Directory || A "Folder" in Windows or OS-X terms. A location where files or other directories are stored. The current directory is sometimes represented as <code>.</code> and the parent directory can be referenced as <code>..</code>
 +
|-
 +
| Home Directory || Your personal storage area. This lives on the department's central file server and is accessible automatically whenever you login to any CIS Linux system. This is also the default directory you will start in when you login|
 +
|-
 +
| Shell || The interface or environment under which you can run commands. For most users, your shell is bash
 +
|-
 +
| SSH || Secure Shell. A protocol that encrypts data and can give access to another system, usually by a username and password
 +
|-
 +
| SCP || Secure Copy. Copying to or from a remote system using part of SSH
 +
|-
 +
| path || The list of directories which are searched when you type the name of a program. There is a section below on this
 +
|-
 +
| ownership || Every file and directory has an user and a group attached to it, called its owners. These affect permissions.
 +
|-
 +
| permissions || The ability to read, write, and/or execute a file. Permissions are based on ownership
 +
|-
 +
| switches || Modifiers or options to a command-line program, usually in the form of -(letter) or --(word). Multiple single-letter switches may frequently be combined if needed for a command
 +
|-
 +
| pipes and redirects || Changes the input (often called 'stdin') and/or output (often called stdout) to a program or a file
 +
|}
 +
 +
=== Basic Linux Commands ===
 +
 +
Here are some of the most common commands you will be using:
 +
{| class="wikitable" width="100%"
 +
! Command !! Function
 +
|-
 +
| ls || list files
 +
|-
 +
| cd || change directory
 +
|-
 +
| mkdir <dirname> || make a directory called <dirname>
 +
|-
 +
| rmdir <dirname> || remove or delete a directory called <dirname>
 +
|-
 +
| cat <filename> || print the contents of <filename> to the screen
 +
|-
 +
| cp <source> <destination> || copy from <source> to <destination>
 +
|-
 +
| mv <source> <destination> || move or renamce from <source> to <destination>
 +
|-
 +
| touch <filename> || create an empty file if it doesn't exists or update the last modified timestamp if it does
 +
|-
 +
| file <filename> || show some information about <filename>, such as what type of file it is
 +
|-
 +
| nano || edit files (probably the easiest text-based editor on our systems)
 +
|-
 +
| man || user manuals
 +
|}
 +
 +
If you need more details on how to use any of these, you can type <code>man cmd</code> where "cmd" is the name of the command you want more information about.
 +
 +
=== General CLI Notes ===
 +
 +
* Linux interprets everything you type in a case-sensitve manner. This means upper- and lower-case letters matter, both in commands and filenames. e.g. "Documents" is '''''not''''' the same as "documents".
 +
 +
* Your shell does not deal with spaces in filenames very nicely. I would strongly discourage you from doing so. If you must use spaces in your filenames, you will need to enclose them with double-quotes (") to interact with them on the command line. Other special characters you should stay away from in filenames include <code>$, #, ;, \, ~, <, >, |, `, [, ], {, }, (, )</code>, and <code>&</code>. These all have special meanings in bash (and other shells) and could result in unexpected (or damaging) behavior of your commands.
 +
 +
* Tab-completion is your friend. No need to type that very long directory or filename, just hit the <code><Tab></code> key once you've typed enough unique letters and the shell will complete the name as it matches in the current directory. You can even do this multiple times for any filename or path as you type it.
 +
 +
* Linux has no concept of "file extensions". Most GUI desktops will try to interpret them if you use typical ones (.pdf, .doc, .txt, etc), but there are no "rules" about what you name files. Use your own discretion. As with all things, consistent naming will keep you out of trouble later.

Revision as of 16:46, 24 November 2014

NOTE: This document borrows heavily from the excellent documentation found in the Beocat wiki. Please have a look there for more details and in-depth examples.

How do I get started with Linux?

Getting Connected

To login remotely to CIS Linux systems, you first need an "SSH Client". SSH, short for "secure shell", is a protocol that allows secure communication between two computers. We recommend the following.

  • Windows
    • PuTTY is by far the most common SSH client, both for CIS and in the world.
    • MobaXterm is a fairly new client with some nice features, such as being able to SCP/SFTP (see below), and running X (Linux graphical desktop).
    • Cygwin is for those that would rather be running Linux but are stuck on Windows. It's purely a text interface.
  • Macintosh
    • OS-X has SSH a built-in application called "Terminal". It's not great, but it will work for most CIS users.
    • iTerm2 is the terminal application we prefer.
  • Others
    • There are many SSH clients for many different platforms available. While we don't have experience with many of these, any should be sufficient for access to CIS Linux systems.

You'll need to connect your client (via the SSH protocol, if your client allows multiple protocols) to cislinux.cis.ksu.edu.

For command-line tools, the command to connect is

ssh username@cislinux.cis.ksu.edu

Your username is your CIS login (usually the same as your K-State eID) and the password is your CIS password (which is only the same as your eID password if you set it manually or using our password reset page).

Note: When you type your password, nothing shows up on the screen, not even asterisks.

The first time you log into a new host, you will be asked to confirm adding the SSL signature to your local repository. Just say "yes" in whatever appropriate form when asked.

You'll know you are successfully logged in when you see a prompt that says

username@hostname:~$

where hostname is the name of the machine you've logged into (currently either 'cougar' or 'viper') and username is your eID username

Transferring files (SCP or SFTP)

Usually, one of the first things people want to do is to transfer files into or out of their CIS account. To do so, you need to use SCP (secure copy) or SFTP (SSH FTP or Secure FTP). Again, there are multiple programs that do this.

  • Windows
    • Putty (see above) has PSCP and PSFTP programs (both are included if you run the installer). It is a command-line interface (CLI) rather than a graphical user interface (GUI).
    • MobaXterm (see above) has a built-in GUI SFTP client that automatically changes the directories as you change them in your SSH session.
    • FileZilla (client) has an easy-to-use GUI. Be sure to use 'SFTP' mode rather than 'FTP' mode.
    • WinSCP is another easy-to-use GUI.
    • Cygwin (see above) has CLI scp and sftp programs.
  • Macintosh
    • FileZilla is also available for OS-X.
    • Within terminal or iTerm, you can use the 'scp' or 'sftp' programs.
  • Linux
    • FileZilla also has a GUI linux version, in additon to the CLI tools.

Using a Command-Line Interface (CLI)

You can safely ignore this section if you're using a graphical interface (GUI).

Example

Transfer a file called myfile.txt in your current folder to your home directory on CISLinux.

I am using my username ("sgsax") here. You should replace this with your own when you run these commands.

Using SCP:

scp myfile.txt sgsax@cislinux.cis.ksu.edu:
Password: (type your password here, it will not show any response on the screen)
myfile.txt                                                                            100%    0     0.0KB/s   00:00

Note the colon at the end of the 'scp' line.

Using SFTP:

sftp sgsax@cislinux.cis.ksu.edu
Password: (type your password here, it will not show any response on the screen)
Connected to cislinux.cis.ksu.edu.
sftp> put myfile.txt
Uploading myfile.txt to /home/s/sgsax/myfile.txt
myfile.txt                                                                            100%    0     0.0KB/s   00:00
sftp> exit

SFTP is interactive, so this is a two-step process. First, you connect to CISLinux, then you transfer the file. As long as the system gives the sftp> prompt, you are in the sftp program, and you will remain there until you type 'exit'.

For more examples of advanced usage, please visit the Beocat wiki.

Linux Lingo

Here are a few basic terms we use when referring to "things" on a Linux system.

Term Definition
Directory A "Folder" in Windows or OS-X terms. A location where files or other directories are stored. The current directory is sometimes represented as . and the parent directory can be referenced as ..
Home Directory
Shell The interface or environment under which you can run commands. For most users, your shell is bash
SSH Secure Shell. A protocol that encrypts data and can give access to another system, usually by a username and password
SCP Secure Copy. Copying to or from a remote system using part of SSH
path The list of directories which are searched when you type the name of a program. There is a section below on this
ownership Every file and directory has an user and a group attached to it, called its owners. These affect permissions.
permissions The ability to read, write, and/or execute a file. Permissions are based on ownership
switches Modifiers or options to a command-line program, usually in the form of -(letter) or --(word). Multiple single-letter switches may frequently be combined if needed for a command
pipes and redirects Changes the input (often called 'stdin') and/or output (often called stdout) to a program or a file

Basic Linux Commands

Here are some of the most common commands you will be using:

Command Function
ls list files
cd change directory
mkdir <dirname> make a directory called <dirname>
rmdir <dirname> remove or delete a directory called <dirname>
cat <filename> print the contents of <filename> to the screen
cp <source> <destination> copy from <source> to <destination>
mv <source> <destination> move or renamce from <source> to <destination>
touch <filename> create an empty file if it doesn't exists or update the last modified timestamp if it does
file <filename> show some information about <filename>, such as what type of file it is
nano edit files (probably the easiest text-based editor on our systems)
man user manuals

If you need more details on how to use any of these, you can type man cmd where "cmd" is the name of the command you want more information about.

General CLI Notes

  • Linux interprets everything you type in a case-sensitve manner. This means upper- and lower-case letters matter, both in commands and filenames. e.g. "Documents" is not the same as "documents".
  • Your shell does not deal with spaces in filenames very nicely. I would strongly discourage you from doing so. If you must use spaces in your filenames, you will need to enclose them with double-quotes (") to interact with them on the command line. Other special characters you should stay away from in filenames include $, #, ;, \, ~, <, >, |, `, [, ], {, }, (, ), and &. These all have special meanings in bash (and other shells) and could result in unexpected (or damaging) behavior of your commands.
  • Tab-completion is your friend. No need to type that very long directory or filename, just hit the <Tab> key once you've typed enough unique letters and the shell will complete the name as it matches in the current directory. You can even do this multiple times for any filename or path as you type it.
  • Linux has no concept of "file extensions". Most GUI desktops will try to interpret them if you use typical ones (.pdf, .doc, .txt, etc), but there are no "rules" about what you name files. Use your own discretion. As with all things, consistent naming will keep you out of trouble later.