How can I manage my hosting with Web Terminal?

Procédure

The Web Terminal available on your LWS panel account allows you to perform several actions on the command line. These command lines allow you to interact with your hosting and can, in some cases, help you manage your hosting.

This documentation explains how you can use the web terminal to interact with your hosting.

Prior to this documentation, we invite you to access your hosting's web terminal.

Moving between folders using the cd command

The cd command (which stands for "change directory") is used to change the current directory in which the user is located in the terminal.

Basic use

  • To move to a specific directory, you use cd followed by the directory path. For example, to move to a directory called Documents, type :

    cd Documents

    This will change the current directory to Documents, provided that this directory exists in the current directory.

  • To return to the home directory, simply type :

    cd

    or

    cd ~
  • To go up one level in the directory hierarchy (to the parent directory), use :

    cd .

Relative and absolute paths

  • Relative path: This is a path relative to the current directory. For example, if you are in /home/username and want to go to /home/username/Documents, you can simply type

    cd Documents
  • Absolute path: This is a path that starts at the root of the file system (indicated by an initial / ). For example, no matter where you are in the file system, you can go directly to /etc by typing :

    cd /etc

Advanced uses

  • You can combine paths to go directly to a sub-folder in another directory without having to change directories several times. For example: cd /var/www/html

    cd /var/www/html
  • The cd - command takes you back to the last directory you were in before the last cd. This is useful for quickly switching between two directories.

Tips

  • Use the Tab key to auto-complete directory names, which can help you avoid typos and speed up navigation.

  • Inverted commas can be used to manage directory names containing spaces:

    cd "Holiday Photos"

The cd command is fundamental for navigating the file system when using a command line interface.

Examples:

test2215341@webdbXX:~/htdocs$ cd app test2215341@webdbXX:~/htdocs/app$ cd .. test2215341@webdbXX:~/htdocs$ cd images bash: cd: images: No such file or directory test2215341@webdbXX:~/htdocs$ cd var/cache/prod test2215341@webdbXX:~/htdocs/var/cache/prod$ 
  • In our example, on the first line, we are located in the "htdocs" folder and we are asked to move to the "app" folder located in the "htdocs" folder using the"cd app" command.
  • In the second line, we find ourselves in the "app" folder and want to return to the parent "htdocs" folder, to do this we need to run the command"cd .."
  • On the third line, we're back in the "htdocs" folder and want to move to the "images" folder.
  • The fourth line shows that there is no "images" folder in the "htdocs" folder.
  • Finally, in the fifth line, we move directly to the 'prod' folder contained in the 'cache' folder contained in the 'var' folder, itself contained in the 'htdocs' folder where we are. It is therefore possible to go directly to a sub-folder deep in the hierarchy without going through each level by applying the command"cd var/cache/prod".

Displaying the contents of a folder with ls

The ls command is one of the most frequently used commands. It is used to list the files and folders contained in a directory. Here is a detailed explanation of how it works and its various options:

Basic function

  • With no arguments, ls displays the files and folders in the current directory, without the hidden files (those whose names begin with a dot).
    test2215341@webdbXX:~/htdocs$ ls INSTALL.txt bin default_index.html index.php override themes webservice LICENSES cache docs init.php pdf tools Makefile classes download js phpinfolws.php translations admin908smaiui composer.lock error500.html localization phpstan.neon.dist upload app config images.inc.php mails robots.txt var autoload.php controllers img modules src vendor

Common options

  • -a or --all: Displays all files, including hidden files.
    test2215341@webdbXX:~/htdocs$ ls -a . admin908smaiui composer.lock error500.html localization phpstan.neon.dist upload .. app config images.inc.php mails robots.txt var .htaccess autoload.php controllers img modules src vendor INSTALL.txt bin default_index.html index.php override themes webservice LICENSES cache docs init.php pdf tools Makefile classes download js phpinfolws.php translations
  • -l: Uses a long format for display, which includes detailed information such as permissions, number of links, owner, group, size, and date last modified.
    test2215341@webdbXX:~/htdocs$ ls -l total 465 -rw-r--r-- 1 test2215341 test2215341 5127 Dec 13 2023 INSTALL.txt -rw-r--r-- 1 test2215341 test2215341 186018 Dec 13 2023 LICENSES -rw-r--r-- 1 test2215341 test2215341 88 Dec 13 2023 Makefile drwxr-xr-x 8 test2215341 test2215341 28 Jul 11 09:04 admin908smaiui drwxr-xr-x 5 test2215341 test2215341 8 Jul 11 09:04 app

    This list shows for each line in order :

    • Permissions: This field shows the permissions of the file or folder. It begins with a character indicating the type (for example, - for a file and d for a folder), followed by three groups of three characters representing the permissions of the owner, the group, and other users respectively (read (r), write (w), execute (x)).
    • Number of links: This number indicates how many hard links point to the element. For folders, this includes sub-folders and the folder itself.
    • Owner: The name of the user who owns the file or folder.
    • Group: The name of the group associated with the file or folder.
    • Size: The size of the file in bytes. For folders, this may be the size of the folder itself, which may vary depending on the file system.
    • Date modified: The date and time of the last modification to the file or folder. The format can vary but generally includes the day, month, time and sometimes the year.
    • Name: The name of the file or folder. Hidden files are indicated by a dot . at the beginning of their name.
  • -h or --human-readable (often used with -l)**: Displays the size of files in human-readable format (K, M, G).
    test2215341@webdbXX:~/htdocs$ ls -lh total 465K -rw-r--r-- 1 test2215341 test2215341 5.1K Dec 13 2023 INSTALL.txt -rw-r--r-- 1 test2215341 test2215341 182K Dec 13 2023 LICENSES -rw-r--r-- 1 test2215341 test2215341 88 Dec 13 2023 Makefile drwxr-xr-x 8 test2215341 test2215341 28 Jul 11 09:04 admin908smaiui drwxr-xr-x 5 test2215341 test2215341 8 Jul 11 09:04 app
  • -t: Sorts files by date modified, from most recent to oldest.
    test2215341@webdbXX:~/htdocs$ ls -lt total 465 -rwxr-xr-x 1 test2215341 test2215341 19 Jul 12 11:12 phpinfolws.php drwxr-xr-x 6 test2215341 test2215341 8 Jul 11 09:10 var drwxr-xr-x 68 test2215341 test2215341 70 Jul 11 09:10 modules -rw-r--r-- 1 test2215341 test2215341 3148 Jul 11 09:10 robots.txt 

Combining options

Options can be combined to refine the display as required. For example:

  • ls -la: Combination of -l and -a, for a detailed display including hidden files.
  • ls -lh: Displays file details with sizes in readable format.
    test2215341@webdbXX:~/htdocs$ ls -lha total 496K drwxr-xr-x 26 test2215341 test2215341 40 Jul 12 11:16 .
    drwxr-xr-x 13 root root 23 Jul 12 07:42 . -rw-r--r-- 1 test2215341 test2215341 3.4K Jul 12 11:16 .htaccess -rw-r--r-- 1 test2215341 test2215341 5.1K Dec 13 2023 INSTALL.txt -rw-r--r-- 1 test2215341 test2215341 182K Dec 13 2023 LICENSES -rw-r--r-- 1 test2215341 test2215341 88 Dec 13 2023 Makefile drwxr-xr-x 8 test2215341 test2215341 28 Jul 11 09:04 admin908smaiui drwxr-xr-x 5 test2215341 test2215341 8 Jul 11 09:04 app

Other useful options

  • -S: Sorts files by size.
  • -d: Lists the directories themselves, not their contents.

The ls command is extremely flexible and can be adapted to a multitude of situations to help users navigate and manage their files efficiently.

Displaying the folder you are currently in with pwd

The pwd command stands for "print working directory". It is used to display the full path of the current directory the user is in.

How it works

When you type pwd in the terminal, the system returns the absolute path of the directory you are currently in. This path always begins with the root / and shows the full path from the root to the current directory.

test2215341@webdbXX:~/htdocs/var/cache/prod$ pwd /home/htdocs/var/cache/prod

Usefulness

  • Orientation: pwd is useful for making sure you are in the right directory before executing commands which could affect files or folders, especially if these commands use relative paths.
  • Scripts: In shell scripts, pwd can be used to obtain the path to the directory where the script is running, which is useful for manipulating files relative to that directory.

pwd is a simple but fundamental command for browsing and managing files.

It allows you to see where you are at all times.

Copying files using the cp command

The cp command is used to copy files and folders from one location to another. This command is very powerful and flexible, offering several options for controlling precisely how files are copied. Here is a detailed explanation of its use and the most common options.

Basic function

  • Basicsyntax: The simplest form of the cp command is cp [source] [destination], where [source] is the path of the file to be copied and [destination] is the path where the file is to be copied.
  • Copy multiple files: You can copy multiple files to a folder by specifying multiple sources and a folder destination, for example, cp file1.txt file2.txt /path/to/destination/.

Common options

  • -r: Required for copying directories. It allows all sub-folders and files in the source folder to be copied recursively.
  • -i: Requires confirmation before overwriting an existing file. If a file in the destination has the same name as the file to be copied, cp will ask if you want to overwrite the file.
  • -u: Copies only when the source is more recent than the destination or when the destination does not exist.
  • -v: Displays a description of what is being copied. This can help you keep track of what the command is doing.

Examples of use

  1. Copying a single file:

    cp original.txt copy.txt

    This will copy original.txt to the same directory under the name copy.txt.

  2. Copy a folder recursively:

    cp -r folder1/ newfolder/

    This will copy all the contents of folder1 into newfolder, creating newfolder if it does not already exist.

  3. Copy with confirmation to avoid overwriting:

    test2215341@webdbXX:~/htdocs$ cp -i index.php themes/ cp: overwrite 'themes/index.php'?

    If index.php already exists in themes, cp will ask if you want to overwrite the file. You will be asked to answer yes or no, depending on your choice.

  4. Copy while displaying details (verbose mode):

    test2215341@webdbXX:~/htdocs$ cp -v index.php themes/ 'index.php' -> 'themes/index.php'

    This will display a message detailing the file being copied.

Points to consider

  • The cp command does not copy symbolic links recursively by default; it copies the files to which they point. To copy the links themselves, use the -d option.
  • Be careful with the -r option when copying folders to make sure you don't include unwanted files or subfolders.
  • The permissions of copied files can be changed depending on the permissions of the user running the cp command and the system's umask settings.

The cp command is essential for file management in a command line environment and offers considerable flexibility in manipulating files and directories.

Moving files using the mv command

The mv command is used to move or rename files and folders. This command is essential for managing the organisation of files in the file system without the need to create an additional copy.

Basic function

  • Move files: mv [source] [destination] moves the file or folder from [source] to [destination]. If [destination] is an existing folder name, [source] is moved to this folder. If [destination] does not exist, the [source] file or folder is renamed to [destination].
  • Renaming files: If you use mv to move a file into the same directory and give it a new name, this is equivalent to renaming it.

Common options

  • -i: Requires confirmation before overwriting an existing file at the destination. If a file at the destination has the same name as the source file, mv will ask if you want to overwrite the file.
  • -u: Moves files only if the source is newer than the destination or if the destination does not exist.
  • -v: Displays details of current operations, useful for tracking what is being moved or renamed.

Examples of use

  1. Move a file to another directory:

    mv file.txt /path/to/destination/
    This moves file.txt from the current directory to /path/to/destination/. If destination is a folder, file.txt is moved inside this folder.
  2. Rename a file:

    mv old_name.txt new_name.txt
    This changes the name of the file old_name.txt to new_name.txt in the same directory.
  3. Move several files to a folder:

    mv file1.txt file2.txt /path/to/destination/
    Moves file1.txt and file2.txt to the specified folder.

Points to consider

  • Unlike the cp command, mv does not create a copy of the file, it relocates the file or folder, which is generally faster, especially for large files, as there is no duplication of data.
  • Use the -i option to avoid accidentally overwriting important files.
  • If you use mv on files located on different volumes or partitions, the command may take longer because it has to copy the data and then delete the original.

The mv command is an important tool for managing files and folders, allowing you to change the way files are organised in an efficient and rational way.

Deleting items using the rm command

The rm command is used to delete files and directories. It is powerful and should be used with care because, unlike many graphical environments, there is generally no recycle bin or easy way to recover files once they have been deleted.

Basic function

  • Delete files: The basic syntax is rm [options] file..., where file... represents one or more files to be deleted. Without options, rm simply deletes the specified file(s).

Common options

  • -r: Deletes directories and their contents recursively. This option is required to delete folders which themselves contain files or other folders.
  • -f: Forces the deletion of files, ignoring non-existent files and deleting without asking for confirmation. Often used in conjunction with -r to delete complete directories without interruption.
  • -i: Requires confirmation before deleting each file. This can help prevent files being accidentally deleted.

Examples of use

  1. Deleting a single file:

    rm file.txt
    This deletes the file file .txt from the file system, without asking for confirmation.
  2. Delete several files:

    rm file1.txt file2.txt file3.txt
    Deletes the files file1.txt, file2. txt and file3.txt.
  3. Delete a directory and its contents:

    rm -r folder/

    Deletes the folder named folder and all its contents, including other subfolders and files it contains.

  4. Deleting files interactively:

    test2215341@webdbXX:~/htdocs$ rm -i error500.html autoload.php rm: remove regular file 'error500.html'? yes rm: remove regular file 'autoload.php'? no

    Asks for confirmation before deleting each file, which is useful if you're not sure whether you want to delete certain files.

Points to consider

  • Be very careful with rm, especially when using the -r and -f options. The wrong command can lead to the irreversible loss of important data.
  • Security: It is often advisable to use the -i option first to make sure what is being deleted, or to list the files with ls before passing them to rm.
  • No easy recovery: Unlike operating systems with graphical interfaces, files deleted by rm generally do not go through a recycle bin and are difficult to recover without specialist data recovery tools.

The rm command is an essential but potentially dangerous tool in the command arsenal and should be used with caution to avoid accidental data loss.

Deleting an empty folder using the rmdir command

The rmdir command is used to delete empty directories. It is designed to be a safe command by only allowing the deletion of directories that are already empty, thus avoiding the accidental deletion of files or sub-directories.

Basic function

  • Deleting empty directories: The basic syntax of rmdir is rmdir [options] directory..., where directory... represents one or more directories you wish to delete.

Common options

  • --ignore-fail-on-non-empty: This option causes rmdir not to display an error message if a directory is not empty. The command still fails, but silently.
  • -p: Deletes each directory in the specified chain, but only if they are empty. For example, rmdir -p a/b/c will attempt to delete c, b, and a successively, provided they are empty.

Examples of use

  1. Delete a simple empty directory:

    rmdir empty_folder

    This deletes the empty_folder directory if it is empty. If the directory contains files or sub-directories, the command will fail with an error message.

  2. Delete several empty directories:

    rmdir dir1 dir2 dir3

    Deletes directories dir1, dir2 and dir3, provided they are all empty.

  3. Delete a chain of empty director ies:

    rmdir -p a/b/c

    If c, b, and a are nested empty directories, this command will delete them all, starting with c, then b, and finally a if all are successively empty.

Points to consider

  • Pre-check: Before using rmdir, it is often a good idea to check the contents of directories with the ls command to make sure they are really empty.
  • Limited use: rmdir is only useful for deleting empty directories. For directories containing files or other directories, you must either empty them first manually or use rm -r to delete them recursively, but with care.

The rmdir command is specifically designed to prevent accidental deletion of data, making it less risky than rm -r for directories, but also less flexible if you need to manage directories containing files.

Concatenate multiple files into a single file using the cat command

The cat command (short for concatenate) is used to display the contents of files, concatenate them, and redirect them to other output or files. It's simple but incredibly powerful and versatile for text or data processing.

Basic functions

  1. Display the contents of a file: To view the contents of a file directly in the terminal, you can use cat followed by the file name.

    test2215341@webdbXX:~/htdocs$ cat robots.txt User-agent: * # Allow Directives Allow: */modules/*.css Allow: */modules/*.js Allow: /js/jquery/* # Private pages Disallow: /*?order= Disallow: /*?tag=   

    This will display the contents of robot.txt in the terminal.

  2. Concatenate several files: cat can be used to display the contents of several files in succession.

    cat file1.txt file2.txt file3.txt

    This will display the contents of file1.txt, followed by file2.txt, then file3.txt in the terminal.

Common options

  • -n: Numbers all output lines, which can be useful for reviewing code or modifying configuration files.
  • -b: Numbers only non-empty lines.
  • -s: Reduces several consecutive empty lines to a single empty line.
  • -E: Displays a $ at the end of each line, which is useful for viewing line endings in text files.
  • -T: Displays tabs as ^I, which can be useful for viewing tabs in text files.

Example of concatenation and redirection

To combine several files into one and view the result:

cat file1.txt file2.txt > combined.txt

This concatenates file1. txt and file2.txt, and redirects the result to combined.txt.

cat is a basic but extremely useful tool in the Unix/Linux command arsenal, being used both for simple file manipulation tasks and as a component in more complex data processing processes.

Creating a folder with the mkdir command

The mkdir command (short for make directory) is used to create new directories. It is an essential tool for organising and managing files in the file system.

Basic function

  • Create a simple directory: To create a new directory, use mkdir followed by the name of the directory you want to create.
    mkdir new_folder
    This creates a directory called new_folder in the current directory
    .

Common options

  • -p: This option is used to create multiple parent directories that do not already exist. For example, if you want to create a directory path such as a/b/c and a and b do not exist, mkdir -p a/b/c will create all the necessary directories.
  • -m: Allows you to set the permissions of the directory when it is created. For example, to create a directory with specific permissions, you could use mkdir -m 755 folder.

Examples of use

  1. Create several directories with a single command:

    mkdir folder1 folder2 folder3

    This will create three directories in the current directory.

  2. Use the -p option to create a directory structure:

    mkdir -p projects/2023/july

    This will create the projects directory, with a 2023 sub-directory, and a July sub-sub-directory, even if none of these directories exist.

Usage advice

  • Checking before creation: mkdir does not check whether a directory already exists by default. If you try to create a directory that already exists without using additional options, you will receive an error message.
  • Use with scripts: mkdir is often used in scripts to ensure that the necessary directory structure exists before writing files or performing other operations.

In summary, mkdir is a simple command for creating directories, enabling users to structure and organise their workspaces and data efficiently.

Managing file/folder permissions with chmod

The chmod command (short for change mode) is used to change file and directory access permissions. This command controls who can read, write or execute a given file or directory.

Key concepts

  1. Users: Permissions can be set for three types of user:

    • u - Owner (user)
    • g - Group
    • o - Others
    • a - All, i.e. owner, group and others
  2. Permissions: There are three types of permissions:

    • r - Read
    • w - Write
    • x - Execute

Basic syntax

chmod can be used in two main ways: using symbolic or numeric (octal) notation.

Symbolic notation

  • Add permissions
    chmod u+w file
    adds write permission to the owner of the file.
  • Remove permissions
    chmod g-r file
    removes read permission from the group.
  • Set specific permissions
    chmod o=rx file
    sets permissions for others to read and execute only.

Numeric notation (octal)

Each number represents a set of permissions:

  • 0: no permissions
  • 1: execute
  • 2: Write
  • 3: Read and write
  • 4: Read
  • 5: Read and execute
  • 6: Reading and writing
  • 7: Read, write and execute

Permissions are added to form a number for each type of user (owner, group, other). For example :

chmod 755 file 
  • Owner: 7 (read, write, execute)
  • Group: 5 (read, execute)
  • Other: 5 (read, execute)

Examples of use

  1. Give all users the right to execute a script:

    chmod +x script.sh

    This adds execution permission for the owner, group and others.

  2. Set specific permissions for a file:

    chmod 644 file.txt
    • Owner: read and write
    • Group and others: read only
  3. Use options to recursively change the permissions of a directory and its contents:

    chmod -R 755 folder/
    This applies permission 755 to all files and subdirectories in folder/.

Usage advice

  • Caution with chmod -R: Changing permissions recursively can have significant effects, especially if applied incorrectly.
  • Security permissions: Executable files and scripts, especially in shared environments, must be managed with care to avoid security problems.

chmod is an essential tool for managing permissions, ensuring the security and smooth operation of file systems.

Searching for a character string in a specified file with grep

The grep (Global Regular Expression Print) command is a powerful and versatile command used to search for text in files based on regular expressions or simple character strings. It is commonly used to filter the contents of files or streams according to specific patterns.

Basic functions

  • Text search: grep searches for lines containing a specified pattern in one or more files and displays the results on the screen.
  • Using regular expressions: grep can use complex regular expressions for advanced searches, allowing great flexibility in defining search patterns.

Basic syntax

grep [options] pattern [file...]
  • pattern: the text or regular expression you are looking for.
  • file... one or more files in which to search. If no file is specified, grep reads the standard input.

Common options

  • -i: Ignores case (upper/lower case) when searching.
  • -v: Inverts the search pattern, displaying lines that do not contain the pattern.
  • -n: Displays the line number of each matching line in the file.
  • -r: Performs a recursive search in all folders and sub-folders.
  • -l: Displays only the names of files containing the pattern, without showing the corresponding lines.
  • -c: Counts the number of lines that match the pattern.
  • -E: Interprets the pattern as an extended regular expression (ERE), allowing richer regular expression syntax to be used.

Examples of use

  1. Find a simple string in a file:

    grep "example" file.txt

    displays all the lines in file.txt containing the word "example".

  2. Recursive search for a string in all the files in a directory:

    grep -r "example" /path/of/folder/
    Searches for"example" in all files in the specified folder and its subfolders.
  3. Searches for a string, ignoring case:

    grep -i "example" file.txt
    Searches for"example","Example","EXAMPLE", etc., in file.txt.
  4. Display files containing a pattern without displaying the corresponding lines:

    grep -l "example" *.txt
    Lists all .txt files containing the word"example".
  5. Count the number of lines containing the pattern:

    grep -c "example" fichier.txt
    Displays the number of lines containing "example" in fichier.txt.

In summary, grep is an essential tool for text searching and data filtering, used for both simple scripting tasks and complex analyses.

Finding a file with find

The find command is a tool used to search for files and directories in a file tree according to various criteria such as file name, size, type, date modified, permissions and many other criteria.

Basic functions

  • Find files and directories: find locates files and directories based on a set of specified conditions, making it extremely useful for file management and automated scripts.

Basic syntax

find [path...] [options] [expression]
  • path... Specifies the starting directory for the search. If no path is given, find uses the current directory.
  • options: Modifies the behaviour of the find command.
  • expression: Defines tests (such as comparing file names), actions (such as printing file names), and logical operators (such as AND, OR, and NOT) that determine how find searches for files.

Common options and expressions

  • -name: Finds files whose name matches the specified pattern. Patterns can include wildcards such as * and ?.
    find /path/ -name "*.txt"
  • -type: Searches for items of a specific type, such as f for files or d for directories.
    find /path/ -type d
  • -size: Searches for files by size. For example, +50M for files larger than 50 megabytes, -10k for files smaller than 10 kilobytes.
    find /chemin/ -size +50M
  • -mtime, -atime, -ctime: Search for files modified (mtime), accessed (atime), or whose metadata has changed (ctime) n days ago.
    find /chemin/ -mtime -7
  • -perm: Searches for files based on their permissions.
    find /chemin/ -perm 644
  • -exec: Executes a command on each file found.
    find /chemin/ -type f -exec chmod 644 {} \;
  • -delete: Deletes files matching the specified criteria.
    find /path/ -name "*.tmp" -delete

Examples of use

  1. Find all the .jpg files in the /home/user/images directory and its sub-directories:
    find /home/user/images -type f -name "*.jpg"
    -delete : Deletes all the .jpg files in the /home/user/images directory and itssub-directories.
  2. Find and delete all .tmp files in /tmp:
    find /tmp -type f -name "*.tmp" -delete
  3. Find files modified in the last 7 days and list them:
    find /path/ -mtime -7 -ls

Usage advice

  • Be careful with commands such as -delete and -exec, as they can irreversibly modify or delete files.
  • Use -print, -ls, or -exec ls -ld {} + to display the results in a way that helps you understand the files found.

The find command is useful for managing large quantities of files and automating maintenance or file management tasks on complex file systems.

Shortcut management with aliases

The alias command is used to create shortcuts for terminal commands. An alias replaces a long or complex command with a shorter, easier-to-remember version. It's a useful tool for customising the command line environment, reducing typing and speeding up workflow.

Basic functions

  • Create an alias: You can create an alias using the following syntax:
    alias name='command'
    Where name is the name of the alias you wish to use, and command is the complete command that this alias should execute.

Examples of use

  1. Aliases for browsing: If you frequently access a particular directory, you can create an alias to simplify the command.

    alias docs='cd /home/user/Documents'.

    Then, by simply typing docs, you will be moved to /home/user/Documents.

  2. Alias for updating the system: On a Linux system using apt, you could create an alias for the update commands.

    alias update='sudo apt update && sudo apt upgrade'".

    Type update to run the update commands.

  3. Aliases for complex commands: For a command involving several tools and options, an alias can simplify input.

    alias findsrc='find . -name "*.c" -print'
    This allows you to search for all the C source files in the current directory simply by using findsrc.

Common options

  • List all existing aliases: To see all the aliases defined in the current session, simply type alias with no arguments.
  • Delete an alias: To delete an alias, use unalias followed by the alias name.
    unalias name

Usage tips

  • Persistence: Aliases defined in a terminal session are temporary and disappear when the terminal is closed. To make aliases permanent, you need to add them to your shell configuration file (such as .bashrc, .zshrc, etc.).

    echo "alias docs='cd /home/user/Documents'" >> ~/.bashrc

    Then reload the configuration file with source ~/.bashrc.

  • Avoiding conflicts: Be careful not to name an alias with the same name as an existing command, unless this is done intentionally to override the default behaviour of that command.

The alias command is an effective way of simplifying and customising the use of the command line, making it easier to remember and execute frequently used commands.

Visual text editor with nano

The nano command launches Nano, a console-mode text editor for Unix, Linux and macOS systems. It is designed to be simple and easy to use, making it a popular alternative to more complex editors such as Vim or Emacs. Nano is often recommended for beginners because of its simplicity and intuitive interface.

Basic functions

  • Opening and editing files: To open a file in Nano, simply type nano followed by the file name. If the file does not exist, Nano will create a new file with that name when you save it.
    nano file.txt
    
     

User interface

Nano's interface displays the contents of the file at the top of the terminal window. At the bottom, a status bar shows information about the file (such as line numbers) and a menu bar with keyboard shortcuts for the most commonly used commands. These shortcuts are displayed as ^G (Ctrl+G) which means you need to press Ctrl and G simultaneously to access help.

How can I manage my hosting with Web Terminal?

Common commands in Nano

  • Ctrl+O (or ^O): Saves the file. After pressing this key combination, Nano will ask you to confirm or change the name under which the file is to be saved.
  • Ctrl+X (or ^X): Exits the editor. If any changes have not been saved, Nano will ask if you want to save them.
  • Ctrl+K (or ^K): Cuts the entire line where the cursor is.
  • Ctrl+U (or ^U): Pastes the line that was previously cut.
  • Ctrl+G (or ^G): Opens Nano Help, which displays a guide to commands and keyboard shortcuts.
  • Ctrl+W (or ^W): Starts a search in the file. You can type the string you want to search for and press Enter. Use Ctrl+W again to search for the next occurrence.

Launch options

  • -m: Activates mouse support, allowing you to place the cursor and scroll with the mouse.
  • -c: Permanently displays the cursor position in the status bar.
  • -l: Displays line numbers on the left of the screen, useful for editing code or configuration files.

Typical use

Nano is frequently used to edit configuration files, write simple scripts or make quick changes to files. Its ease of use and availability on virtually all Linux distributions make it very accessible for basic text editing tasks.

In short, Nano is a lightweight, easy-to-use text editor, ideal for those who prefer a straightforward approach to configuring and editing files from the command line.

Text transformation with sed

The sed (Stream Editor) command is a great tool for manipulating text. It is used to perform complex text transformations, including inserting, deleting, finding and replacing specific strings in data streams or files.

Basic functions

  • Inline text manipulation: sed acts on the data stream line by line, applies specified transformations to each line, and displays the result on the screen, making it ideal for working in command pipelines and shell scripts.

Basic syntax

sed [options] script [input-file...]
  • script: a series of sed commands that define how to modify text.
  • input-file: input file(s) on which the commands will be executed. If no file is specified, sed reads the standard input text.

Common sed commands

  • Substitution: the most common form of sed command. The syntax is s/pattern/replacement/flags.

    sed 's/old/new/' file.txt
    This replaces the first occurrence of the word"old" with"new" in each line of file.txt.
  • Delete: deletes lines that match a pattern.

    sed '/pattern/d' fichier.
    txt Deletes all lines containing"pattern".
  • Insert and append: i to insert text before a line and a to append after.

    sed '3i\Text to insert' file.txt
    Inserts"Text to insert" before line 3.

Common options

  • -e: Used to specify multiple scripts to run sequentially.
    sed -e 's/red/blue/' -e 's/green/yellow/' file.txt

  • -n: By default, sed prints each line of the file after processing it. The -n option changes this behaviour so that sed only prints modified or specified lines.
  • -i (be careful with this option): Modifies the input file in place (i.e. saves the changes in the original file). Some implementations of sed require a suffix to create a backup of the original file.
    sed -i '.bak' 's/old/new/' fichier.txt

    Modifies file.txt directly, creating a backup copy file.txt.bak.

In short, sed is an essential tool. Its power lies in its ability to perform complex text transformations efficiently and automatically.

Conclusion

You now know how to :

  • Use the Web Terminal to interact with your hosting.
  • Navigate directories with the cd command.
  • List the contents of folders with ls.
  • Check your current working directory with pwd.
  • Copy files with cp.
  • Move or rename files with mv.
  • Delete items with rm or rmdir for empty folders.
  • Concatenate files with cat.
  • Create folders with mkdir.
  • Manage permissions with chmod.
  • Search for strings with grep.
  • Finding files with find.
  • Creating aliases to simplify your commands.
  • Editing text files with nano.
  • Transforming text with sed.

🎉 Thank you for reading this carefully! If you have any questions or would like to share your experience with these commands, please don't hesitate to leave a comment. Your feedback is invaluable to us. 💬

Rate this article :

This article was useful to you ?

Article utileYes

Article non utileNo

Vous souhaitez nous laisser un commentaire concernant cet article ?

Si cela concerne une erreur dans la documentation ou un manque d'informations, n'hésitez pas à nous en faire part depuis le formulaire.

Pour toute question non liée à cette documentation ou problème technique sur l'un de vos services, contactez le support commercial ou le support technique

MerciMerci ! N'hésitez pas à poser des questions sur nos documentations si vous souhaitez plus d'informations et nous aider à les améliorer.


Vous avez noté 0 étoile(s)

Similar articles

1mn reading

How do I connect to the Web Terminal with LWS Panel? (ssh web console)

4mn reading

How can I use GIT with the Web terminal on my LWS shared hosting?

2mn reading

How to change the PHP version of the LWS Panel Web Terminal

0mn reading

What can I do on my WordPress site using the Web Terminal?


Ask the LWS team and its community a question