LOCEN Resources Linux

Basics on linux operating system

A guide to Linux (in Italian)

A very good basic guide to Linux terminal commands, with also links to other more detailed guides:
Basic guide to Linux terminal commands

HOW TO INSTALL A PROGRAM UNDER UBUNTU TO MAKE PDF CORRECTIONS

Install "wine" with Synaptink. This allows installing windows program in Linux computers.
Download and unzip the program from following link:
http://www.tracker-software.com/downloads/PDFXVwer.zip?key=629a71f1d1d95...
Go in the unzipped directory (where there is the file: PDFXVwer.exe), open the terminal in such directory, and type the command:
wine PDFXVwer.exe 
Follow all the requests for the Windows like installation of the program.

Basic shell commands for linux

 

In the following Gianluca Baldassarre (a non expert of Linux) is collecting useful commands to use in Linux.

GENERAL INFORMATION

People that can use the computer are:
'Root': normally the owner of the computer, with all rights to read and change (right) its contents.
'User': another user of the computer with limited read/write rights.
'Group': a set of users.
'Other users': ???

Shell can execute commands, listed below. These commands are normal programs. To execute a command, type it in the shell and then press enter.

You can create other programs to executed in the Shell: these are called 'scripts'. Scripts are files containing lists of Shell commands executed in a batch way (i.e., one automatically one after the other) when the script file is executed.

The control of the computer by Shell is so important for people liking Linux as it allows them to use the same knowledge to issue commands to the computer AND to write programs (scripts) to controll it. Plus, via Shell you can control any computer thorugh a simple, basic text inteface.

 

LOGIN, EXIT, PASSWORD CHANGE

'#' or '$': prompt

'login': request of username, e.g. 'gianlucabaldassarre'

'password': request of password, e.g. '123MyPassword321'

'exit': to exit the terminal

'Ctrl+d': to exit the terminal 'passwd': changes the password of the currently logged-in user 

SUPER USER

'sudo' type this before any other command if you want to perform such command as 'super user', so having the possibility of changing anything.

'sudo gedit' for example, to launch gedit (a program to edit txt files) you have the possibility of opening and editing any file opened with such program, i.e. independently of the permissions of the file.

 

HELP ON COMMANDS

'man command_name' help on command_name

 

KEY DIRECTORIES

'/': root directory

'/home': home directory of all users

'/home/gianlucabaldassarre': home directory of user gianlucabaldassarre 

'.': the dot means ''current directory''

'..': indicates upper directory

'/etc'  a critical directory where there are a lot of information related to the system (see below)

'./': means the path related the current directory


BROWSING DIRECTORY/FILES

'pwd': stands for 'print working directory' and prints on screen the path of your current directory from / 

'cd' : 'change directory', moves you to the user directory

'cd .': keeps you at current directory as . indicates current directory

'cd ..': moves to upper directory as '..' indicates upper directory

'cd /': moves you to the root directory

'cd /home/gianlucabaldassarre/documents': moves you to the directory 'documents' 

'cd nomefile\ with\ spaces': allows you to move to file with name 'nomefile with spaces'

'ls': stands for 'list' and lists the directories and files in current directory 

'ls -a': stands for 'list all' and lists also the hidden filese starting with '.' for example '.nomefile'

'ls -t': 'list in time order', lists directories and files in order of time 

'ls -l': stands for 'list long' lists the directories and files with much information, for example returns:
drwxrwxrwx    4  gianlucabaldassarre users     1024   Mar  26  17:35  documents/ 
-rwxrwxrwx    1  gianlucabaldassarre users     2872   Mar  03  12:40  notes.txt 
-rw-rw----      1  gianlucabaldassarre users     1024   Mar  07  12:40  notesbis.txt
That indicates:
'd' '-': mean respectivley directory or file,
'r', 'w', 'x', '-': indicate the rights to respectively 'read', 'write', 'execute', 'do nothing': 3 digits of this type are used for respecively each of the following: 'user', 'group', 'other users'
'4', '1' : the number of 'hard links' (i.e., pointers) contained in the directory or file: these pointers allow to immediately change the path to all sub-contents when the directory is moved.
For a directory in the example, the hard links are (Gianluca: to be checked):
  '/home/gianlucabaldassarre/documents/.': hard link to itself 
  '/home/gianlucabaldassarre/documents/..': hard link to upper directory
  '/home/gianlucabaldassarre/documents/subdir': hard link to sub-directory 'subdir'
  '/home/gianlucabaldassarre/documents/notes3.txt': hard link to file 'notes3.txt' 
For the file, the hard link is only one (Gianluca: to be checked):
  '/home/gianlucabaldassarre/documents/notes3.txt', i.e. the hard link to itself
'gianlucabaldassarre': the owner
'users' : the group of the user
'1024', '2872': the size of the directory/file in bytes
'Mar 26 17:35': the date and time of the last modification of the directory/file
'documents/', 'notes.txt': names of directory/file (notice the / after the directory name) 

 

DIRECTORIES/FILES: CREATING, REMOVING

'mkdir directory_name': creates the directory directory_name

'rm file_name': remove file file_name

'rm -r directory_name' removes directory directory_name and all its contents

'rm -r *'   removes all contents from the current directory: be aware as it is a very powerful, destructive command! Before using it, to see in advance its effect it is advisable to use 'echo -r *'

 

DIRECTORIES/FILES: PERMISSIONS

'chmod 777 filename': assigns all priviledges (rwx: read, write, execute) to all (admi, user, host)

'chmod -R 777 directoryname': -R indicates ''recursive'', i.e. all dictory contents and sub-directories' contents.

Digits 7, 5, and 4 each individually represent the permissions for, in that order: user, group, others.
Each digit is a combination of the numbers 4, 2, 1, where : 4 = "read", 2 = "write", 1 = "execute", 0 = "no permission".
So:
7=4+2+1 (read, write, execute)
5=4+0+1 (read, no write, execute)
4=4+0+0 (read, no write, no execute)
2=0+2+0 (no read, write, no execute)
1=0+0+1 (no read, no write, execute)

VISUALISATION OF FILE CONTENT (THROUGH PROGRAM 'CAT')

 'cat file_name': visualises the content of file filename (like a curious cat : )

'pg': once opened the file with cat, this allows you to move in the file (Gianluca: it does not work in my pc)once in the file, use 'enter', '-', or 'q' to go 1 page down, up, and quit; 'more': as pg, but working with 'space' 'b' 'q'

 

VISUALISATION OF FILE CONTENT (THROUGH PROGRAM 'VI' or 'VIM')

...todo...

 

CHANGE OWNER OF WHOLE DIRECTORY BRANCH 

'sudo chown -R gianlucabaldassarre:gianlucabaldassarre /home/gianlucabaldassarre': I did not understand (ask Francesco), but it is important to use this kind of command to allow the use of home directory (e.g. /home/gianlucabaldassarre) after doing a new installation:

 

INSTALLING PROGRAMS FROM FILES FILE.DEB OR FROM WEB

'dpkg -i  program_name.deb': depacks the packages and installs programme_name, used when you have a '.deb' file of the program in one of your directories (from which you have to launch the command). -i indicates to install the program after unzipping it with dpkg

'dpkg apt-get install program_name' downloads program from web and installs it (equivalent to using Synaptic)

KNOWING WHERE PROGRAMS ARE

'type program_name': if program_name is in the PATH variable (only programs whose path is in PATH variable can be execued from any directory), it searches the path of a program in such PATH variable; you can get just the path with the -p argument

'which program_name': (used by Valerio) searches the path of a program in the PATH variable and returns it, while it returns nothing if it does not find anything (so it can be used to check if a program directory is in the PATH) (from internet: ''note that the command gets confused between environment and dot files'').

'locate -b program_name': searches a program not in PATH; finds anything with name program_name, so it returns a long list, so it is good to qualify as:

'locate -b program_name | fgrep -w bin': locates program_name; howeer, this works only if you have updated the database after installing the program you search; so before using it, use:

'sudo updatedb' which updates the database of where programs are.

'find / -name program_name': an old tool to search files; on some older versions of the systems you may need a -print option supplied to find:

'find / -name program_name -print': that works in such systems (Gianluca: I found this very effective)

'apt-cache policy program_name' checks if a program is installed or not. If it is, it gives info on it. If it is not, it says “Unable to locate package program_name”

KNOWING DEBIAN VERSION ON YOUR COMPUTER

'uname -a':  tells what version of Linux is running in the computer 

'uname -a && cat /etc/*release': tells you more information on the version of Linux that is running in the computer 

'less /etc/debian_version': in Debian, tells you the exact number of its version (e.g., 7.6) 

 

PATH

The system has a ''system variable'' called ''PATH'' containing all paths where the system searches executable files and programs when you lauch them from any directory (in Shell) in the system.

'echo $PATH': to see the content of the environment variable PATH; echo prints something on screen; $ makes echo print the content of the environment variable rather than the variable name.

...TODO... addition of a path to PATH

...TODO... remove a path from PATH (not tested): if you're using BASH Shell, you can do the following if, let's say, you want to remove the directory '/home/wrong/dir/' from your PATH variable: PATH=`echo $PATH | sed -e 's/:\/home\/wrong\/dir\/$//'`

(Found in internet but not tested) Here is a one line code that cleans up the PATH. It does not disturb the order of the PATH, just removes duplicates. Treats ':' and 'empth' PATH gracefully. No special characters used, so does not require escape. Uses '/bin/awk' so it works even when PATH is broken: export PATH="$(echo "$PATH" |/bin/awk 'BEGIN{RS=":";}{sub(sprintf("%c$",10),"");if(A[$0]){}else{A[$0]=1;printf(((NR==1)?"":":")$0)}}')";

 

LISTING PROGRAMS IN .BASHRC, THE FILE EXECUTED WHEN THE USER OPENS A SHELL

.bashrc is a file in which there are all the personalisations related to the user, say gianlucabaldassarre.

.bashrc is a hidden file, so to see it in the file browser (e.g., Thunar) you need to tic 'View-->Show Hidden Files'. The file is for example in this path: /home/gianlucabaldassarre/.bashrc

In .bashrc you have to add the commands to export into PATH (each time) the path of the program you are interested, e.g. by adding this text into .bashrc:
#Addition of Matlab to PATH (# makes of this a comment line)
MATLAB_DIR=/home/gianlucabaldassarre/AProgramsLinux/Matlab
export PATH=$PATH:$MATLAB_DIR/bin
By creating the environment variable MATLAB_DIR you can quickly find the path where Matlab is with the command 'echo $MATLAB_DIR', otherwise he could have skipped this variable and directly use the command:
'export PATH=$PATH:/home/gianlucabaldassarre/AProgramsLinux/Matlab/bin'

Note that the file .bashrc is executed only when you open a shell. To change variables permanently add:
'export PATH=$PATH:/home/gianlucabaldassarre/AProgramsLinux/Matlab/bin'
to your file:
'~/.profile'

 

LAUNCHING PROGRAMS AND SCRIPTS

'program_file': to launch a certain program that is listed in the PATH environment directory

'sudo program_file': to launch some programs as super user: to use especially programs that allow you to change the file system, you need to lauch the programs and scripts as super user. Note that if you simply lauch 'program_file', some linux releases, e.g. Debian, do not tell you anything as if the program does not exist

'./program_file': to launch a program that is not in the PATH, first search the directory where it is (see section above ''knowing where programs are'', in particular use the command 'locate -b program_name | fgrep -w bin'), then go into that directory with 'cd directory_path_and_name', then use the command './program_file' (the './' is needed otherwise the system tries to search whether the program is in PATH)

 

CREATING AND LAUNCHING SCRIPTS

'sudo gedit script.sh': allows you to edit script.sh with gedit.

'./script.sh': executes script.sh,but only if it is located in the directory where you currently are. Indeed, './' is used to say current directory path.

Important notes: after you download a script from internet or email-attachment, or when you change the file, the file permissions are changed and often is no more executable, so give permissions to it before trying to execute it. Also, when you save the script with gedit, often this saves the file with a Windows format, so save again the file with 'save as' form gedit and set the format to 'linux' in the widow-settings that appears.

 

SETTING DUAL SCREEN OF YOUR COMPUTER (ALSO USE THIS TO USE OVERHEAD PROJECTOR FOR SLIDES)

See this website 'https://wiki.debian.org/XStrikeForce/HowToRandR12' for all about 'xrandr', the program that allows you to do all operations on the screens.

'xrandr': to see the type of screens seen by the computer.

'xrandr --output VGA-0 --left-of DVI-0 –primary': set the dual output screens (or similar ones to be found in internet with ''double screen in Debian setup''). Write such command in the personalisation file '/home/gianlucabaldassarre/.bashrc' to make the change permanent. Sometimes this does not start automatically when you open the computer: to trigger the personalisation, just open a shell. Alternatively, you can create a script to lauch by hand, e.g. with this code:
'#!/bin/bashxrandr --output VGA-0 --left-of DVI-0 –primary'

Important: you can set which screen is at the left or at the right; but the important thing is that is xfce the menu' of commands and the open-program bars (which give to a screen the role of primary screen) have to be set to the screen you prefer by hand by right clicking on them and then selecting Properties to tell them which output screen they should use. 

 

OPERATING SYSTEM (OS) UPDATES, SOFTWARE SEARCH IN INTERNET, DOWNLOADS (WITH COMMMAND apt-get OR PROGRAM Synaptic IN LINUX DEBIAN)

You can download software from the internet with the program Synaptic: this is the fundamental progarm of UNIX to manage updates and search software.The standard procedure to download sofware from Shell is as follows (you need to know the name of the program to search, as in Synaptic, so search such name in internet first).

From Shell, to know the available programs related to packname execute:

'sudo apt-cache search pack_name'

From Shell, to install the packs you like, including the dependencies, execute:

'sudo apt-get install pack_name'

To update all sofware:

'sudo apt-cache search updates': to check the available updates

'sudo apt-get update' (or 'sudo apt-get install'?) to actually install the updates.