Linux and Advanced Operating Sytems (L3 IBIOM / M2.1 BioInforMatique) Linux and Advanced Operating Systems (L3 - IBIOM) (M 2.1 - BioInforMatique) L. Mouchard [email protected]1st Term 2012-2013 [email protected]LITIS EA4108 - Faculty of Sciences 1/27
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Linux and Advanced Operating Sytems (L3 IBIOM / M2.1 BioInforMatique)
Linux and Advanced Operating Sytems (L3 IBIOM / M2.1 BioInforMatique)
References
Main features Multi-tasking/multi-user from the crave
Several remarks
Linux/Unix/MacOS X operating systems are:
multi-tasking OS several programs can be executed simultaneously onthe same computer (even with a single processor);
multi-user OS several users can work simultaneously on the samephysical computer;
file systems these OS partially capitalize on the way they handlefile systems and their associated online commands;
shells these OS partially capitalize on the way they can in-terpret and combine online commands: their nativeinternal interpreters (handling functions, loops andtests) are named shells.
Linux and Advanced Operating Sytems (L3 IBIOM / M2.1 BioInforMatique)
References
Online commands
Why should I use a text terminal rather than a file browser?
Linux strength is mainly based on its ability to handle, parse and processonline commands operating on its file systems;
Linux philosophy 1: keep commands as simple and modular as possible;
Linux philosophy 2: provide a mechanism for gathering simple commands andcreate complex ones;
some examples: create a (series of) directory(ies), rename or move a directory;(simple) parse a file to display all lines containing a pattern, (simple) countthe number of lines in a file, and (complex) gather these two commands forcounting in a file the number of lines that contain a given pattern.
plan the future execution of a given command;
schedule (with a specific periodicity: each night, monday, first Wednesday ofthe month at 4am) the forthcoming executions of a given command.
Linux and Advanced Operating Sytems (L3 IBIOM / M2.1 BioInforMatique)
References
Our very first commands
Command formatcommand [option[s]] [argument[s]]
command command to be executed.spaces are used for separating the command from the pos-sible options and the possible options from the possible ar-guments. Spaces can be either one or several <space>symbols, one or several <tab> symbols or a mix.
[option[s]] Brackets mean optional: zero, one or several options. Onlyfor explanations, they are not supposed to be typed in.
[argument[s]] zero, one or several arguments.If one wants to display the current date, the command date
expects no argument, if a specific format is to be used, thecommand date expects exactly one argument.Similarly, if one wants to copy a file into a directory, thecommand cp expects two arguments, while if one wants tocopy several files into a directory, the command cp expectsprobably more than two arguments.
Linux and Advanced Operating Sytems (L3 IBIOM / M2.1 BioInforMatique)
References
Our very first commands
Environment and help commands
date current datedate +format current date using a specific format
cal [month] [year] calendar [for month] [for year]hostname computer nameuname [options] linux name and versiontty terminal namelogname login nameid user identificationwhoami litteraly: who am I?who list of connected usersfinger user[s] informations on user[s], possibly disactivatedman command[s] manual pages for command[s]whatis command[s] overview of command[s]apropos pattern[s] commands associated to pattern[s]
Linux and Advanced Operating Sytems (L3 IBIOM / M2.1 BioInforMatique)
Files
Types Regular, Directory and Special
Types
ordinary/regular files containing data (text, image, sound, video, libreoffice document)
directory file containing a list of references to subdirectories or/and files: it istechnically speaking a file that contains pairs (filename, inode number).
special all other files, see below.
Special files
link link to another file (sort of shortcut) on the same or a different file system.block file associated to an Input/Output block device (USB stick, internal or
external hard drive...)character file associated to a Input/Output character device (keyboard, screen...).socket file associated to a network-oriented application (providing data exchange
mechanisms)tube file associated to the automatic execution of a command (providing a data
Linux and Advanced Operating Sytems (L3 IBIOM / M2.1 BioInforMatique)
Files
File systems Naming convention
Absolute and relative names, other important notations
/ at the begining of a filename, it is the root of the file system tree.Every absolute name starts with /;
/ within a filename, it separates two directory names.. the current directory, whatever its name is;.. the parent directory, whatever the current directory is: the parent of
/ is /.absolute name path from the root of the file system (/) to the file itself, directory
names are separated by /.relative name path from the working directory to the file itself, directory names are
separated by /.;
Remarks
No major constraint on the length of the filenames;
made of letters, digits and “ ” (some other symbols are accepted but not recom-mended);
Linux and Advanced Operating Sytems (L3 IBIOM / M2.1 BioInforMatique)
Files
File systems Metacharacters (wildcards, jokers)
Filenames and metacharacters (depend on the Shell that is used)
* any (possibly empty) series of characters;? any character, exactly one;{a,d,f} any character in the set: a or d or f;[a-c] any character in the interval: a or b or c;
img?.jpg all files but img10.jpg and img11.jpg;img1?.jpg files img10.jpg and img11.jpg;img1*.jpg files img1.jpg, img10.jpg and img11.jpg;img{3,6}.jpg files img3.jpg and img6.jpg;img[4-6].jpg files img4.jpg, img5.jpg and img6.jpg.
Linux and Advanced Operating Sytems (L3 IBIOM / M2.1 BioInforMatique)
Commands
Directories
Commands operating on directories
pwd print working directory;cd [~] change working directory to default home directorycd ~john change working directory to john’s home directorycd dirname change working directory to dirname
cd - change working directory to previous working directorypushd dirname current working directory is memorized, new working
directory is dirname
popd change working directory to memorized directory
1 - regular file (-), link (l), directory (d), block (b), character (c),pipe (p), socket (s).
2 rw-r--r-- owner (rw-), group (r--) and others (r--).modalities : read (r), write (w), execute (x) nothing (-)
3 1 number of links (the filename has only one filename)4 laurent owner (login name, see /etc/passwd or similar mechanism)5 teaching group (group name, see /etc/group or similar mechanism)6 4938937 size of the file (bytes)7 2012-08-23 02:48 last modification8 chapter01.pdf filename
Linux and Advanced Operating Sytems (L3 IBIOM / M2.1 BioInforMatique)
Commands
File systems
Commands
mount list and properties of active (mounted) file systems;df disk usage for all mounted file systems;df file[s] disk usage for the file systems that contain file[s] ;du file[s] disk usage for file[s];du -s dir[s] disk usage for dir[s];quota size and number of files you can use;stat file[s] inode informations for file[s];
whereis com path to binary, source or manual page for com;which com order in which Linux finds com in its file systems;locate patt commands corresponding to pattern *patt*;find ... files that (for example): are larger than 50MB, older than 2
months, haven’t been accessed for the last 20 days etc (manfind for a complete description).
Linux and Advanced Operating Sytems (L3 IBIOM / M2.1 BioInforMatique)
Commands
Files
Commands operating on files
touch nexist file create an empty file nexist file;touch exist file modify the last access date for file exist file;cp file[s] exist dir copy file[s] into exist dir/file[s];cp src dst copy file src to dst;rm file[s] remove definitely file[s];mv file[s] exist dir move file[s] into exist dir;mv src dst rename file src to dst;
Attention: cp + rm 6= mv
ln src dst hard link between src (existing) and dst (new name forunique physical contents): (dst,inode src) is created inaddition to existing (src,inode src)
ln -s src dst symbolic link between src (existing) and dst (new name).Used for cross-device link: (dst,inode for src) is cre-ated, the inode corresponds to a disk block which containsthe filename (src).
Linux and Advanced Operating Sytems (L3 IBIOM / M2.1 BioInforMatique)
Commands
File content
Displaying the content of a file
cat file[s] whole content;more file[s] one page at a time;less file[s] one page at a time;head -n file[s] only n first lines;tail -n -k file[s] only k last lines;tail -n +k file[s] only from line k till the end;
sort file[s] sort;uniq file[s] remove consecutive duplicates;grep pattern file[s] only the lines containing pattern;cut -c... file[s] only specified characters;cut -d... -f... file[s] only specified fields (-f) with specified separator (-d);
paste file1 file2 gather lines from file1 and file2;join file1 file2 join lines from file1 and file2;split size file split a file into chunks of size Bytes;csplit pattern file split a file according to a given pattern;
gzip file compress file into file.gz (zip or bzip2)gunzip file.gz uncompress file.gz into file (unzip or bunzip2)tar cf file.tar dir archive dir in one unique file (file.tar in our example);tar xf file.tar extract all files contained in archive file.tar.