Rate this article :
This article was useful to you ?
Yes
No
Vous avez noté 0 étoile(s)
Sommaire
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.
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$
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
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 vendorCommon 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 appThis list shows for each line in order :
- 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)).. 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 appOther 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.
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
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.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.
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
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.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
Copying a single file:
cp original.txt copy.txt
This will copy original.txt to the same directory under the name copy.txt.
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.
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.
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
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.-r option when copying folders to make sure you don't include unwanted files or subfolders.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.
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
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].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
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.Rename a file:
mv old_name.txt new_name.txtThis changes the name of the file old_name.txt to new_name.txt in the same directory.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
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.-i option to avoid accidentally overwriting important files.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.
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
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
Deleting a single file:
rm file.txtThis deletes the file file .txt from the file system, without asking for confirmation.Delete several files:
rm file1.txt file2.txt file3.txtDeletes the files file1.txt, file2. txt and file3.txt.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.
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
rm, especially when using the -r and -f options. The wrong command can lead to the irreversible loss of important data.-i option first to make sure what is being deleted, or to list the files with ls before passing them to rm.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.
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
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
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.
Delete several empty directories:
rmdir dir1 dir2 dir3
Deletes directories dir1, dir2 and dir3, provided they are all empty.
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
rmdir, it is often a good idea to check the contents of directories with the ls command to make sure they are really empty.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.
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
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.
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.
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
mkdir followed by the name of the directory you want to create.mkdir new_folderThis 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
Create several directories with a single command:
mkdir folder1 folder2 folder3
This will create three directories in the current directory.
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
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.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.
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
Users: Permissions can be set for three types of user:
Permissions: There are three types of permissions:
Basic syntax
chmod can be used in two main ways: using symbolic or numeric (octal) notation.
chmod u+w fileadds write permission to the owner of the file.chmod g-r fileremoves read permission from the group.chmod o=rx filesets permissions for others to read and execute only.Each number represents a set of permissions:
Permissions are added to form a number for each type of user (owner, group, other). For example :
chmod 755 file
Examples of use
Give all users the right to execute a script:
chmod +x script.sh
This adds execution permission for the owner, group and others.
Set specific permissions for a file:
chmod 644 file.txtUse 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
chmod -R: Changing permissions recursively can have significant effects, especially if applied incorrectly.chmod is an essential tool for managing permissions, ensuring the security and smooth operation of file systems.
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
grep searches for lines containing a specified pattern in one or more files and displays the results on the screen.grep can use complex regular expressions for advanced searches, allowing great flexibility in defining search patterns.Basic syntax
grep [options] pattern [file...]
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
Find a simple string in a file:
grep "example" file.txt
displays all the lines in file.txt containing the word "example".
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.Searches for a string, ignoring case:
grep -i "example" file.txtSearches for"example","Example","EXAMPLE", etc., in file.txt.Display files containing a pattern without displaying the corresponding lines:
grep -l "example" *.txtLists all .txt files containing the word"example".Count the number of lines containing the pattern:
grep -c "example" fichier.txtDisplays 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.
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 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]
find uses the current directory.find command.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" -deleteExamples of use
.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..tmp files in /tmp:find /tmp -type f -name "*.tmp" -deletefind /path/ -mtime -7 -lsUsage advice
-delete and -exec, as they can irreversibly modify or delete files.-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.
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
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
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.
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.
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
alias with no arguments.unalias followed by the alias name.unalias nameUsage 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.
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
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.txtUser 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.

Common commands in Nano
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.
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
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.txtThis 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.txtInserts"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.txtModifies
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.
You now know how to :
🎉 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 ?
Yes
No
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?