Warming up with Unix commands
In this lesson, you will learn some basic commands of the Unix operative system. The operating system (OS) is the system software that manages computer hardware, software resources, and provides common services for computer programs, i.e. allow the communication between hardware and software. In order to use a computer, you need an OS. At this moment you are using a Virtual Machine containing the Ubuntu OS, a Linux distribution, a Unix-like OS. The command used in Linux and Unix they are essentially the same.
If you open a terminal window a prompt will appear where you can type your command. A snapshot of the prompt is shown here below:
You can inspect your environment by typing the following commands:
$> whoami # (my username) $> hostname [-A] # (machine name) $> pwd # (current directory) $> ls [-ltr] # list files and dirs $> ps # running processes $> top # more on running procs $> date # show date and time
As seen above, the command $pwd (present working directory) shows the directory you are presently working on. Now we want to see how to navigate to other directories. This is done by using the command
$cd (change directory) followed by a path.
If we want to move for instance to the folder LabQSM we need to provide its path. A path is the address of a file or a folder.
We can use an absolute path:
or a relative path:
provided that you are already in /home/max. This avoids typing complete paths.
You can then navigate up on level by typing:
and you will be back to the HOME. You can also navigate to multiple directories as e.g.
Finally the command
navigate to the HOME directory independently to the present working directory.
Creating, removing, copying and moving files and directories
A way to create a new file is the following:
$cat > filename
- Enter the content e.g. your name
- Press 'ctrl + d' to return to command prompt.
a file named filename containing a text with your name has been created. You will find it in the list using the
and you can inspect it by typing:
We will see later other ways to create and edit files using the editor named vi.
To create a new directory use the command:
Files and directory are removed using the command
$rm -r dirname
To move a file from a directory to another use the command
$mv filename ./LabQSM/.
the same syntax applies also for moving directory. The same command is used to rename files:
$mv filename newfilename
File and directory can be also copied (duplicated) in the same directory or in other directories:
$cp filename ./LabQSM/. #copy the file in the LabQSM directory with the same name
$cp filename ./LabQSM/newname #copy the file in the LabQSM directory with a new name
$cp -r dirname ./LabQSM/. #copy the directory dirname and all its content in the LabQSM directory
Users, Groups & Permissions
Now let's inspect the content of a directory in details, by typing
you can see the list of the file containing information for each file as the owner, the permissions (who can read, write or execute that file), the dates it was modified, the size etc. Here an example: