Versions Compared

Key

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

...

This is a very valuable skill, especially considering that it will allow you to remotely access CSIL computers via SSH.

You can probably get by without learning much, but this guide will cover a bare minimum that anyone interacting with linux machines should know.

First open terminal.

If you are in one the CSIL computer labs, log in and select Gnome as the desktop environment (it will be in a little dropdown box after you enter your password).

After you have logged in, scroll over Activities in the top left corner of the screen.

Then in the search box, type Terminal and double click the terminal icon.

If you are connecting via SSH or PuTTY, then you will already be in terminal once you have successfully logged in.

Once you are in terminal, type in the following

Code Block
languagebash
themeFadeToGrey
pwd

and Then press enter.

This means print working directory.

Most people are familiar with going to My Documents in Windows and browsing through different folders.

Similarly to folders in Windows, linux has directories. Directories and folders are the same thing with different names.

All linux machines have a directory known as the home directory, represented by a ~ symbol.

This is where you will most likely be doing all your work.

In Windows and Mac, you navigate to different folders by double clicking on the one you want to open.

For example, if I am in "My Documents" and I want to go into the folder Word Documents, I will just click on the Word Documents icon.

Terminal, however, does not support clicks and everything must be conveyed textually.

In order to change directories, use the following command,

Code Block
languagebash
themeFadeToGrey
cd path/to/dir

For example, if you are in your home directory, within which there is another directory called homework, you would type in either

Code Block
languagebash
themeFadeToGrey
cd homework

because homework is a directory within home, or

Code Block
languagebash
themeFadeToGrey
cd ~/homework

because that is the absolute path to the homework directory. The latter is more precise because it tells the computer exactly where to look. The former, on the other hand, implies that since you are currently within the home directory, a ~/ should be appended to the beginning of the relative path (homework). Keep in mind that the former will, therefore, only work when run in the home directory.

As of now, you probably don't have a homework directory so, in terminal, type

Code Block
languagebash
themeFadeToGrey
cd ~

and press enter, in order to make sure you are in your home directory. Then type

Code Block
languagebash
themeFadeToGrey
mkdir homework

and press enter. This will make a directory called homework. Once the directory is created, navigate to it using the cd command

Code Block
languagebash
themeFadeToGrey
cd homework

If you don't feel like typing homework all the way out, just type cd homew and press Tab. This should autocomplete it for you. Once you are in the homework directory, you can navigate back the home directory by entering either

Code Block
languagebash
themeFadeToGrey
cd ~

because that is the absolute path of the of the home directory, or

Code Block
languagebash
themeFadeToGrey
cd ..

which means change to the parent directory. In this scenario, homework is a directory within home, meaning that it is a "child" of home, thereby making home its "parent" directory.

...

First make sure you are in your home directory

Code Block
languagebash
themeFadeToGrey
cd ~

and then create the file,

Code Block
languagebash
themeFadeToGrey
vim myhw.txt

Vim is an example of an application that runs through the terminal. Although vim is not a standard bash command, it comes preinstalled on all of the CSIL machines.

...

In order to list the new file and every other file and directory within your current directory, type

Code Block
languagebash
themeFadeToGrey
ls

when you run this, you should see myhw.txt along with the homework directory and possibly some other files. In order to copy "myhw.txt" into the homework directory, type

Code Block
languagebash
themeFadeToGrey
cp myhw.txt homework

Meaning copy "myhw.txt" into homework. The copy command can be generalized as follows,

Code Block
languagebash
themeFadeToGrey
cp what-you-want-to-copy where-you-want-to-copy-it

Now let's say that you want to rename it to "yourhw.txt"

Code Block
languagebash
themeFadeToGrey
mv myhw.txt yourhw.txt

This basically moves the contents of "myhw.txt" and put it inside "yourhw.txt". The mv and cp commands are very similar, but have one key difference: cp copies the file and leaves the original, whereas mv moves the file and deletes the original. Mv can also be used to move files to other directories. In order to move "yourhw.txt" into your home directory, enter either

Code Block
languagebash
themeFadeToGrey
mv yourhw.txt ~

to move it to the absoluate absolute path of the home directory, or

Code Block
languagebash
themeFadeToGrey
mv yourhw.txt ..

in order to move it to the parent directory, which also happens to be "home".

Now that we have copied, renamed, and moved "myhw.txt", navigate to the home directory,

Code Block
languagebash
themeFadeToGrey
cd ~

and the enter

Code Block
languagebash
themeFadeToGrey
ls

in order to list your files. You should see myhw.txt, yourhw.txt, and the directory homework (among other directories). To prove that we really did copy and move myhw.txt, enter

Code Block
languagebash
themeFadeToGrey
more yourhw.txt

and it should display Hello, World! in the terminal. After you have done this, go ahead and remove myhw.txt and yourhw.txt by entering one of the following commands,

Code Block
languagebash
themeFadeToGrey
rm myhw.txt

and then

Code Block
languagebash
themeFadeToGrey
rm yourhw.txt

which removes each file individually, or

Code Block
languagebash
themeFadeToGrey
rm myhw.txt yourhw.txt

which removes the both at the same time, or

Code Block
languagebash
themeFadeToGrey
rm *hw.txt

which will remove all files ending in "hw.txt". Now in order to remove the homework directory, you have to include a flag, which is basically a parameter that specifies how the command should be run:

Code Block
languagebash
themeFadeToGrey
rm -r homework

the -r stands for recursive, which is the algorithm that rm must use in order to delete directories.

...

Page Properties
hiddentrue


Related issues