...
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 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 | ||||
---|---|---|---|---|
| ||||
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 | ||||
---|---|---|---|---|
| ||||
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 | ||||
---|---|---|---|---|
| ||||
cd homework |
because homework is a directory within home, or
Code Block | ||||
---|---|---|---|---|
| ||||
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 | ||||
---|---|---|---|---|
| ||||
cd ~ |
and press enter, in order to make sure you are in your home directory. Then type
Code Block | ||||
---|---|---|---|---|
| ||||
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 | ||||
---|---|---|---|---|
| ||||
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 | ||||
---|---|---|---|---|
| ||||
cd ~ |
because that is the absolute path of the of the home directory, or
Code Block | ||||
---|---|---|---|---|
| ||||
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.
Now we are going to make a file so you can learn how to remove, move, rename, and copy it.
There are many ways to do this, but for this example we will create a file using a program called vim.
Let's call the file myhw.txt:
First make sure you are in your home directory
Code Block | ||||
---|---|---|---|---|
| ||||
cd ~ |
and then create the file,
Code Block | ||||
---|---|---|---|---|
| ||||
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.
Once you are in vim, press i, for insert, and type "Hello, World!".
When you are done, press Esc and then :wq and then enter (this writes/saves the changes and then quits out of vim).
Your new file myhw.txt has now been created.
In order to list the new file and every other file and directory within your current directory, type
Panel | ||||
---|---|---|---|---|
| ||||
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 | ||||
---|---|---|---|---|
| ||||
cp myhw.txt homework |
Meaning copy "myhw.txt" into homework. The copy command can be generalized as follows,
Code Block | ||||
---|---|---|---|---|
| ||||
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 | ||||
---|---|---|---|---|
| ||||
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 | ||||
---|---|---|---|---|
| ||||
mv yourhw.txt ~ |
to move it to the absoluate absolute path of the home directory, or
Code Block | ||||
---|---|---|---|---|
| ||||
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 | ||||
---|---|---|---|---|
| ||||
cd ~ |
and the enter
Panel | ||||
---|---|---|---|---|
| ||||
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 | ||||
---|---|---|---|---|
| ||||
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 | ||||
---|---|---|---|---|
| ||||
rm myhw.txt |
and then
Code Block | ||||
---|---|---|---|---|
| ||||
rm yourhw.txt |
which removes each file individually, or
Code Block | ||||
---|---|---|---|---|
| ||||
rm myhw.txt yourhw.txt |
which removes the both at the same time, or
Code Block | ||||
---|---|---|---|---|
| ||||
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 | ||||
---|---|---|---|---|
| ||||
rm -r homework |
the -r stands for recursive, which is the algorithm that rm must use in order to delete directories.
Now that you understand these basic commands, you are now ready to use the linux command line.
Other helpful links
A quick start to VIM for Beginners - https://eastmanreference.com/a-quick-start-guide-for-beginners-to-the-vim-text-editor
A beginner's guide to Linux Command Line - https://www.techspot.com/guides/835-linux-command-line-basics/
Cheat sheets, courtesy of UCSB's Center for Scientific Computing
Related articles
Filter by label (Content by label) | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
...
Page Properties | ||
---|---|---|
| ||
|