Basic Linux Usage¶
Using Linux via a command-line interface is not conceptually different from using an operating system that is mainly oriented toward a graphical user interface such as Microsoft Windows. The major difference is that on Windows you get the system and the software to do what you want by learning to juggle the activities of clicking left, right, or middle mouse buttons, scrolling the wheel, dragging or mouse around while holding one or more buttons on the keyboard or the mouse all while trying to precisely hit the many differently shaped and sized areas on the screen. On Linux, if you are using it as your desktop system, you can follow the same usage pattern you learned on Windows.
However, when
you log into the HPC system to get the job done via the command-line
(CLI) interface you have to switch from juggling pictures to a more
verbal mode and "talk to the system" using a language with a very small
and well-defined vocabulary. The system will respond with either normal
responses that show the results of your commands or with error responses
that either mean that it didn't understand you or that the command you
ran encountered a problem. All Linux commands have a help file that is
called a "manual page" or manpage and can be called with the man
COMMAND command where COMMAND corresponds to the command you want to
learn more about.
Moving around¶
Introduction¶
Think of a Linux system as a house with many rooms separated by the
doors. And just as in a house getting where you need to be depends on
where you start. As every house has an entrance every Linux system has
its "root", which is marked by the topmost "door" - "/". Every other
"door" is also marked with "/". The rooms with content are called
files and storage rooms that hold other rooms are called directories and
they all have names. So, if you know the name of the file or directory
you need and the name of every directory between your target and the
root of the filesystem you can always use an absolute path that starts
from the root and ends up at the file or directory of your choosing. For
instance, referencing a file /project/bio/fasta/Ecoli_NC_008253.fa
means you start from the root and go through the directories
project,bio,fasta to get to the room
Ecoli_NC_008253.fa that has what you need while opening the doors
/ between the rooms. This is called using an absolute path. If you
think of all the paths on the system it quickly becomes apparent that
together they create something similar to a tree as the rooms branch out
and spread in many directions, but to go back up the tree there is only
a single door to the parent directory. It's called a directory tree.
If you are deep in the house i.e. the directory tree it can be
cumbersome to travel from the entrance each time you need to pick up
something in the same room where you already are or in an adjacent room.
So, just as you would simply open the door to the parent room and then a
door to the room you want you can do the same so called relative path
traversal on Linux by using ".." as a symbol for the parental
directory. So, if you are currently in the "/project/bio/2bit"
directory you can change to the "/project/bio/fasta" directory or
reference a file in that directory as "../fasta/Ecoli_NC_008253.fa".
If for some reason you need to reference the directory you are in use
"." as a symbol for it as in "touch ./my_file.txt". When you log
into UFRC you are placed into your own room that's located at
"/home/USER" where USER is your username that you can see on the
left side of the terminal prompt. By the way, we use " quotes to make
the commands stand out and it's not necessary to enter them at the
command line.
Basic Commands¶
- pwd - path to working directory - find out where you are right now.
- cd - change directory - go from one directory to another.
- E.g.:
cd /project/bio
- E.g.:
- ls - list - show the contents of the current working
directory.
- E.g.:
lsfor a short listing,ls -ato show hidden files and directories (those with.in front of their name as in .ssh,ls -lto show a long listing akin to what you see in a detailed view in Windows Explorer or MacOS Finder. You can combine the switches as inls -al
- E.g.:
- touch - create an empty file or update a file or directory's
access timestamp.
- E.g.:
touch test.txt
- E.g.:
- mv [options] SOURCE DESTINATION - move or rename file(s) or
directories.
- E.g.:
mv test.txt test2.txt. The options are listed in the mv manpage (man mv).
- E.g.:
- cp [options] SOURCE DESTINATION - copy file(s) or directories. The most useful option is -a, which copies the entire sub-tree. See the cp manpage for more details.
- rm [options] TARGET - remove - delete file(s) or directories. Useful options include -i for an interactive prompt that will give you a chance to reconsider your delete action that would be final otherwise (No going back!), -rf for a forceful removal of an entire directory tree, and '-v' to verbosely explain what's being done.
- file TARGET - learn some information about the target file.
Note: Linux is very liberal about you giving file and directory names, so by necessity it's very strict about referencing those names in commands. The test.txt and Test.txt are two different files and have to be referenced with the correct case. See the multitude of Linux tutorials and command cheat sheets for more details. For instance basic commands cheat sheet.
To be continued...