Linux introduction: Difference between revisions

Jump to navigation Jump to search
Marked this version for translation
(Added translation markup to the page)
(Marked this version for translation)
Line 1: Line 1:
<languages />
<languages />
<translate>
<translate>
<!--T:1-->
This article is aimed at Windows and Mac users that do not have or have very little experience in UNIX environments. It should give you the necessary basics to access the compute servers and being quickly able to use them.  
This article is aimed at Windows and Mac users that do not have or have very little experience in UNIX environments. It should give you the necessary basics to access the compute servers and being quickly able to use them.  


<!--T:2-->
Connections to the servers use the SSH protocol, in text mode. You do not use a graphical interface (GUI) but a ''console''. Note that Windows executables do not run on our servers, at least without using an emulator.
Connections to the servers use the SSH protocol, in text mode. You do not use a graphical interface (GUI) but a ''console''. Note that Windows executables do not run on our servers, at least without using an emulator.


== Obtaining help ==
== Obtaining help == <!--T:3-->
Generally, UNIX commands are documented in the reference manuals that are available on the servers. To access those from a terminal:
Generally, UNIX commands are documented in the reference manuals that are available on the servers. To access those from a terminal:
{{Command|man command}}
{{Command|man command}}
<tt>man</tt> uses <tt>less</tt> (see the section [[#Viewing and editing files|Viewing and editing files]]), and you must press <tt>q</tt> to exit this program.
<tt>man</tt> uses <tt>less</tt> (see the section [[#Viewing and editing files|Viewing and editing files]]), and you must press <tt>q</tt> to exit this program.


<!--T:4-->
To find manual pages pertaining to a certain subject or keyword (for example "sujet"), please enter:
To find manual pages pertaining to a certain subject or keyword (for example "sujet"), please enter:
{{Command|apropos sujet}}
{{Command|apropos sujet}}
By convention, the executables themselves contain some help on how to use them.
By convention, the executables themselves contain some help on how to use them.


<!--T:5-->
Generally, you invoke this help using the command line argument <tt>-h</tt> or <tt>--help</tt>, or in certain cases,  <tt>-help</tt>.
Generally, you invoke this help using the command line argument <tt>-h</tt> or <tt>--help</tt>, or in certain cases,  <tt>-help</tt>.


== Orienting yourself on a system ==
== Orienting yourself on a system == <!--T:6-->
Following your connection, you are directed to your <tt>$HOME</tt> directory (the UNIX word for "folder") for your user account.
Following your connection, you are directed to your <tt>$HOME</tt> directory (the UNIX word for "folder") for your user account.
When your account is created, your <tt>$HOME</tt> only contains a few hidden configuration files that start with a ".", and nothing else.
When your account is created, your <tt>$HOME</tt> only contains a few hidden configuration files that start with a ".", and nothing else.


<!--T:7-->
On a Linux system, you are strongly discouraged to create files or directories that contain names with spaces or special characters, including accents.
On a Linux system, you are strongly discouraged to create files or directories that contain names with spaces or special characters, including accents.


=== Listing directory contents ===
=== Listing directory contents === <!--T:8-->
To list all files in a directory in a terminal, use the <tt>ls</tt> (list) command:
To list all files in a directory in a terminal, use the <tt>ls</tt> (list) command:
{{Command|ls}}
{{Command|ls}}
Line 33: Line 38:
The option <tt>-h</tt> gives the file sizes in human readable format.
The option <tt>-h</tt> gives the file sizes in human readable format.


<!--T:9-->
You can combine options, for example:
You can combine options, for example:
{{Command|ls -alth}}
{{Command|ls -alth}}


=== Navigating the file system ===
=== Navigating the file system === <!--T:10-->
To move about in the file system, use the <tt>cd</tt> command (change directory).
To move about in the file system, use the <tt>cd</tt> command (change directory).


<!--T:11-->
So, to change to <tt>my_directory</tt> you type:
So, to change to <tt>my_directory</tt> you type:
{{Command|cd my_directory}}
{{Command|cd my_directory}}
Line 46: Line 53:
{{Command|cd}}
{{Command|cd}}


=== Creating and removing directories ===
=== Creating and removing directories === <!--T:12-->
To create (make) a directory, use the <tt>mkdir</tt> command:
To create (make) a directory, use the <tt>mkdir</tt> command:
{{Command|mkdir my_directory}}
{{Command|mkdir my_directory}}
Line 53: Line 60:
Deleting a directory like this only works if it is empty.
Deleting a directory like this only works if it is empty.


=== Deleting files ===
=== Deleting files === <!--T:13-->
You can remove files using the <tt>rm</tt> command:
You can remove files using the <tt>rm</tt> command:
{{Command|rm my_file}}
{{Command|rm my_file}}
Line 60: Line 67:
The (potentially dangerous!) <tt>-f</tt> option can be useful to bypass confirmation prompts and to continue the operation after an error.
The (potentially dangerous!) <tt>-f</tt> option can be useful to bypass confirmation prompts and to continue the operation after an error.


=== Copying and renaming files or directories ===
=== Copying and renaming files or directories === <!--T:14-->
To copy a file use the <tt>cp</tt> command:
To copy a file use the <tt>cp</tt> command:
{{Command|cp source_file destination_file}}
{{Command|cp source_file destination_file}}
Line 69: Line 76:
This command also applies to directories. You should then replace <tt>source_file</tt> with <tt>source_directory</tt> and <tt>destination_file</tt> with <tt>destionation_directory</tt>.
This command also applies to directories. You should then replace <tt>source_file</tt> with <tt>source_directory</tt> and <tt>destination_file</tt> with <tt>destionation_directory</tt>.


== File permissions ==
== File permissions == <!--T:15-->
UNIX systems support 3 types of permissions : read (<tt>r</tt>), write (<tt>w</tt>) and execute (<tt>x</tt>). For files, a file should be readable to be read, writable to be modified, and executable to be run (if it's a binary executable or a script). For a directory, read permissions are necessary to list its contents, write permissions enable modification (adding or removing a file) and execute permissions enable changing to it.
UNIX systems support 3 types of permissions : read (<tt>r</tt>), write (<tt>w</tt>) and execute (<tt>x</tt>). For files, a file should be readable to be read, writable to be modified, and executable to be run (if it's a binary executable or a script). For a directory, read permissions are necessary to list its contents, write permissions enable modification (adding or removing a file) and execute permissions enable changing to it.


<!--T:16-->
Permissions apply to 3 different classes of users, the owner (<tt>u</tt>), the group (<tt>g</tt>), and all others or "the world" (<tt>o</tt>). To know which permissions are associated to files and subdirectories of the current directory, use the following command:
Permissions apply to 3 different classes of users, the owner (<tt>u</tt>), the group (<tt>g</tt>), and all others or "the world" (<tt>o</tt>). To know which permissions are associated to files and subdirectories of the current directory, use the following command:
{{Command|ls -la}}
{{Command|ls -la}}


<!--T:17-->
The 10 characters at the beginning of each line show the permissions.
The 10 characters at the beginning of each line show the permissions.
The first character indicates the file type :
The first character indicates the file type :
Line 81: Line 90:
* <tt>l</tt>: a symbolic link
* <tt>l</tt>: a symbolic link


<!--T:18-->
Then, from left to right, this command shows read, write and execute permissions of the owner, the group and other users. Here are some examples :
Then, from left to right, this command shows read, write and execute permissions of the owner, the group and other users. Here are some examples :
* <tt>drwxrwxrwx</tt>: a world-readable and world-writable directory
* <tt>drwxrwxrwx</tt>: a world-readable and world-writable directory
Line 91: Line 101:
* <tt>drwx-wx-wx</tt>: a directory that everybody can enter and modify but where only the owner can list its contents
* <tt>drwx-wx-wx</tt>: a directory that everybody can enter and modify but where only the owner can list its contents


<!--T:19-->
Important note: to be able to read or write in a directory, you need to have execute permissions (<tt>x</tt>) set in all parent directories, all the way up to the file system's root ('''<tt>/</tt>'''). So if your home directory has <tt>drwx------</tt> permissions and contains a subdirectory with <tt>drwxr-xr-x</tt> permissions, other users cannot read the contents of this subdirectory because they do not have access (by the executable bit) to its parent directory.
Important note: to be able to read or write in a directory, you need to have execute permissions (<tt>x</tt>) set in all parent directories, all the way up to the file system's root ('''<tt>/</tt>'''). So if your home directory has <tt>drwx------</tt> permissions and contains a subdirectory with <tt>drwxr-xr-x</tt> permissions, other users cannot read the contents of this subdirectory because they do not have access (by the executable bit) to its parent directory.


<!--T:20-->
After listing the permissions, <tt>ls -la</tt> command gives a number, followed by the file owner's name, the file group's name, its size, last modification date, and name.
After listing the permissions, <tt>ls -la</tt> command gives a number, followed by the file owner's name, the file group's name, its size, last modification date, and name.


<!--T:21-->
The <tt>chmod</tt> command allows you to change file permissions. The simple way to use it is to specify which permissions you wish to add or remove to which type of user. To do this, you specify the list of users (<tt>u</tt> for the owner, <tt>g</tt> for the group, <tt>o</tt> for other users, <tt>a</tt> for all), followed by a <tt>+</tt> to add permissions or <tt>-</tt> to remove permissions, which is then followed by a list of permissions to modify (<tt>r</tt> for read, <tt>w</tt> for write, <tt>x</tt> for execute). Non-specified permissions are not affected. Here are a few examples:
The <tt>chmod</tt> command allows you to change file permissions. The simple way to use it is to specify which permissions you wish to add or remove to which type of user. To do this, you specify the list of users (<tt>u</tt> for the owner, <tt>g</tt> for the group, <tt>o</tt> for other users, <tt>a</tt> for all), followed by a <tt>+</tt> to add permissions or <tt>-</tt> to remove permissions, which is then followed by a list of permissions to modify (<tt>r</tt> for read, <tt>w</tt> for write, <tt>x</tt> for execute). Non-specified permissions are not affected. Here are a few examples:


<!--T:22-->
* Prevent group members and all others to read or modify the file <tt>secret.txt</tt>: {{Command|chmod go-rwx secret.txt}}
* Prevent group members and all others to read or modify the file <tt>secret.txt</tt>: {{Command|chmod go-rwx secret.txt}}
* Allow everybody to read the file <tt>public.txt</tt>: {{Command|chmod a+r public.txt}}
* Allow everybody to read the file <tt>public.txt</tt>: {{Command|chmod a+r public.txt}}
Line 103: Line 117:
* Prevent other users to read or modify your home directory: {{Command|chmod go-rw ~}}
* Prevent other users to read or modify your home directory: {{Command|chmod go-rw ~}}


== Viewing and editing files ==
== Viewing and editing files == <!--T:23-->
=== Viewing a file ===
=== Viewing a file ===
To view a file read-only, use the <tt>less</tt> command:
To view a file read-only, use the <tt>less</tt> command:
Line 111: Line 125:
You can quit <tt>less</tt> by pressing the <tt>q</tt> key.
You can quit <tt>less</tt> by pressing the <tt>q</tt> key.


=== Comparing two files ===
=== Comparing two files === <!--T:24-->
The <tt>diff</tt> command allows you to compare two files:
The <tt>diff</tt> command allows you to compare two files:
{{Command|diff file1 file2}}
{{Command|diff file1 file2}}
The <tt>-y</tt> option shows both files side by side.
The <tt>-y</tt> option shows both files side by side.


=== Searching within a file ===
=== Searching within a file === <!--T:25-->
The <tt>grep</tt> command allows you to look for a given expression in one
The <tt>grep</tt> command allows you to look for a given expression in one
{{Command|grep 'tata' file1}}
{{Command|grep 'tata' file1}}
Line 123: Line 137:
Note that, in Linux, the "<tt>*</tt>" wildcard matches zero or more characters. The "<tt>?</tt>" wilcard matches exactly one character.
Note that, in Linux, the "<tt>*</tt>" wildcard matches zero or more characters. The "<tt>?</tt>" wilcard matches exactly one character.


<!--T:26-->
The text to be searched for can also be variable. For example, to look for
The text to be searched for can also be variable. For example, to look for
the text "number 10 » or "number 11", etc. with any number between 10 and 29,
the text "number 10 » or "number 11", etc. with any number between 10 and 29,
Bureaucrats, cc_docs_admin, cc_staff
2,233

edits

Navigation menu