Linux / Debian SSH commands

Procédure

List of Linux / Debian commands (valid for most Linux distributions).

Some of these commands are not included in the standard installation of a Linux system. If you want to use a command that is not available by default, you must install it or install the package that contains it.

See: Easy installation and uninstallation of packages


Handling files

List of files

ls ................................... List of files in a directory. ls -l ............................ Also lists properties and attributes. ls -lh ........................... Lists files with size in MB and GB. ls -la ........................... Lists files including hidden system files. ls -la | more .................... Lists files in a directory in paginated form.


Access rights to files or directories

See : Access rights on files or directories


Displays the contents of a file

cat -n file ....................... Displays the contents of a file (-n number all lines). pr -t file ........................ Format text files for printing (-t do not display header and footer). cat file | less ---, cat file | more ---| |--------------> Displays the contents of a file in a paginated way. more file ---------| less file ---------' zcat file -------------, zmore file -------------|---------> Displays the contents of a compressed file (.gz) zless file -------------'


Display

echo text ........................... Displays the text that follows it.   
grep 'text' file ................. Displays the lines of the file containing the text. stat file ......................... Indicates the status of a file. stat -f file .................. Indicates the status of the file system. file ......................... Shows the nature of a file. tail file ......................... Displays the last lines of a file, 10 by default. tail -n 12 file ............... Displays the last 12 lines of a file. head -Nº file ..................... Displays the first (N°) lines of a file. wc file ........................... Indicates the number of words, lines and characters in a file. wc -c file ........................ Displays the size of a file in bytes. touch [-am][-t] file .............. Modify access and modification dates.


Search for files

find /usr -name lilo -print .......... Finds all files with the name lilo in /usr. find /home/toto -name *.jpg -print .. Finds all .jpg images. ---------- ---------- ----- | | | V V `---> Displays the full path to the file. search template path


Copying files

cp -dpR file1 /path/file2 .... Make a copy of file1 to /path/file2, rename. -R .............................. Recursively copies a directory, except for special files. -p .............................. Preserve copy permissions, owner, groups and dates. -d .............................. Preserves symbolic links. -a .............................. Like -dpR.


Move and/or rename files or directories

mv /path/file1 /path/file2 . Move and/or rename files or directories.


Delete files

rm files .......................... Deletes files. rm -r directory ................. Deletes files in a directory recursively. rm *.jpg ......................... Deletes all .jpg files in the current directory.


Links

ln file /path/link .............. Create a link. ln -s directory /path/link ........ Creates a symbolic link.


Compare files

diff [options] file1 file2 ..... Compares files.  
    diff -w file1 file2 ........ Discard empty lines per report. diff -q file1 file2 ........ Reported only if files differ. diff -y file1 file2 ........ Displays the output of two columns. join [options] file1 file2 ..... Displays equal lines.


Split a file

split -b 1445640 mozart.ogg mozart- .. Split a file. ---------- ------- | V | name chosen for the parts V size in bytes of each part cat mozart.* > mozart.ogg ............ Reunite the different parts of a file split with split.


nano - Read, create, edit a text file

nano file ......................... Read, create and edit a text file Ctrl + g ........................ Calls up the help menu. Ctrl + x ........................ Exit nano. Ctrl + o ........................ Write the file to disk. Ctrl + r ........................ Inserts another file in the current context. Ctrl + w ........................ Search for a string or regular expression. Ctrl + y ........................ Move to the previous page. Ctrl + v ........................ Move to the next page. Ctrl + k ........................ Cut the current line to the clipboard. Ctrl + u ........................ Paste the clipboard from the current line. Ctrl + l ........................ Refresh (redraw) the current screen. Ctrl + j ........................ Justify the current paragraph. Ctrl + m ........................ Inserts a line break at the cursor position. Ctrl + _ ........................ Moves to the indicated row and column. Alt + g ......................... Moves to the specified row and column Alt + i ......................... Indent automatically Alt + x ......................... Help mode (toggle) Alt + p ......................... Show whitespace (toggle) Alt + m ......................... Use mouse (toggle).     
     Alt + b ......................... Keep backup copies (toggle) Alt + s ......................... Progressive scrolling (toggle) Alt + h ......................... Smart 'Start' key (toggle) Alt + y ......................... Syntax colouring (toggle) Alt + p ......................... Show whites (toggle).


Compress and Decompress

Compress zip: ...................... zip -r file.zip file ; example: zip -r sinatra.zip ./sinatra/ Decompress zip: .................... unzip file.zip View zip contents: ................. unzip -v file.zip Compress gz: ....................... gzip -r file ; example: gzip -r ./sinatra Decompress gz: ..................... gzip -d file.gz View content gz ................... gzip -c file.gz Compress bz2: ...................... bzip2 file ; example: bzip2 ./sinatra/*.ogg Decompress bz2: .................... bzip2 -d file.bz2 View content bz2: ................. bzip2 -c file.bz2


Note: -r

-r Is recursive in all cases.


zip Compresses files and directories, but gzip or bzip2 only compress files but not directories, so they must be combined with tar.

tar files Compress: ......................... tar -vcf file.tar /file1 /file2 Decompress: ....................... tar -vxf file.tar View contents: .................... tar -vtf file.tar


To combine tar and gzip or bzip2:

tar.gz files (tgz) Compress: ......................... tar -zvcf file.tgz directory Decompress: ....................... tar -zvxf file.tgz View content: .................... tar -zvtf file.tgz tar.bz2 files (tbz2) Compress: ......................... tar -jvcf file.tbz2 directory Decompress: ....................... tar -jvxf file.tbz2 View content: .................... tar -jvtf file.tbz2



Handling directories

Enter a directory

cd directory ........................ Changing directories. 
    cd .. ............................ Return to the previous directory. 
    cd ./.mozilla .................... Enter the Mozilla directory (indicating the relative path). cd /home/toto/.mozilla ........... Enter the Mozilla directory (indicating the full path).


Create and Delete

mkdir directory ..................... Creates a directory. rmdir directory ..................... Deletes an empty directory. rm -r directory ..................... Deletes a directory.


Directory size

du -h directory ..................... Space occupied on disk.



Administration

Scheduled tasks

See : Scheduled tasks


Start, stop and restart services

/etc/init.d/service stop ........ Stop a service/demon. /etc/init.d/service start ....... Start a service/demon. /etc/init.d/service restart .... Restarts a service/demon.


User management

su .............................. Enter the session as root or another user. su user .................. As root, enter as another user. passwd .......................... Change your password. who -a -H ....................... Displays information from connected users. users ........................... Displays information about users connected to the system. id .............................. Displays information about the current user. groups .......................... Displays the groups to which a user belongs. adduser user ..................... Create a new user. adduser user group .............. Adds an existing user to an existing group. adduser --no-create-home user .... Create a user without a home directory. addgroup group ......................... Create a new group. deluser user ..................... Delete a user. deluser user group .............. Removes a user from a group. deluser --remove-home user ....... Removes a user and their home directory. delgroup group ......................... Deletes a group. usermod -l new_user .............. Changes the user's name. usermod -d new_home -m user ...... Changes a user's home directory.       
groupmod -n new_name grupo ............... Change the name of a group.


System

free -m -s 3 ............................ Displays memory usage every 3 seconds. df -h ................................... Size, space used and space available on each disk partition. netstat -napt ........................... Find out which ports our system has opened.


Logs

tail /var/log/syslog .................... Log security messages. tail /var/log/debug ..................... Program debugging information. tail /var/log/messages .................. System information messages. tail /var/log/user.log .................. User information. tail /var/log/auth.log .................. System access (including unsuccessful attempts). last .................................... List of logged in / logged out users. lastb ................................... Displays failed login attempts.


Process

htop Requires installation of the htop package.

ps aux ................................. Displays information about current processes. top .................................... Displays information about current processes. htop ................................... Is a system monitor which can be used to filter processes by memory and/or processor consumption. pstree ................................. Displays processes in a tree. pidof command ......................... Finds the ID of a program that is currently running. killall process ...................... Stop a process. strace command ........................ Displays the system calls generated by a process. fuser -v file ....................... Displays the processes using a file. lsof | less ............................ List of files opened by the process. lsof -c command ................... Lists the files opened by a process. lsof +D /home/paco ................. Lists the processes that use my directory. lsof -i :627 ....................... Shows that a process is found behind port 627. nohup command & ....................... Launches a process continuously in the background. command & ............................. Executes a command in the background. jobs .................................. Lists processes in the background with a job number. fg nº .................................. Moves a process to the foreground. nice -n command priority .............. Executes a command with a priority (default 0). Example: nice -n -10 cdrecord... renice priority PID_process .......... Changes the priority of a running process. sleep 5 command ....................... Delays the execution of a command by 5 seconds.


DNS - test tools

dig .................................... Allows you to query the DNS server of your choice directly and obtain a wide range of information, in addition to name resolution and reverse resolution. nslookup ............................... Like dig, less powerful but still useful. named-checkconf ........................ Checks the syntax of Bind9 configuration files. named-checkzone ........................ Used to check the validity of zone files before reloading the configuration.


Traffic Monitoring

Requires the netdiag and bmon packages to be installed.

trafshow ............................... Displays incoming/outgoing IP traffic for a protocol. bmon ................................... Bandwidth monitoring and rate estimator.



Miscellaneous

Command history

history .............................. Displays a list of commands used by the user. fc -l ................................ Displays a list of the most recently executed commands.


Command line reference

man command ---------------------, command --help ------------------|--> Displays information about the command. 
info command --------------------' help command ........................ Displays information about an internal shell command. apropos [word] ....................... Search the man descriptions. apropos -e [word] ..................... Find the exact word in the man descriptions.


Date and time

cal -my .............................. Displays the calendar. uptime ............................... How long ago the system was started. date ................................. Displays the system date and time. date -u .............................. Displays the UTC date and time.


Others

clear ................................ Clears the screen. reset ................................ Resets the Console. pwd .................................. Displays the current directory. uname -a ............................. Kernel version. hostname ............................. Displays the server name. Ctrl+C ............................... Ends a process. Ctrl+Z ............................... Temporarily suspends a program. Ctrl+S ............................... Stops data transfer to the management console. Ctrl+Q ............................... Resume, restart data transfer. ./script ............................. Execute a shell script. java -jar fichier.jar ................ Run a Java program.


wget - Download manager

wget [options] URL ................... Download manager. -p .............................. Download the site. -r .............................. Recursive. -k .............................. Absolute link conversion. -c .............................. Resume downloading a partially downloaded file. -l6 ............................. Recursion depth (default 5) -A format ....................... Format to be downloaded. -nH ............................. Do not create the localhost directory. 
     --cut-dirs=n .................... Eliminates the number of directories in the hierarchy. Example 1: wget -A zip URL .......... Download all the zip archives of a web site. Example 2: We want to download the nano.pdf manual which is in: http://www.manuales.com/informatica/editores/nano.pdf ---------------- --------- ------ localhost 1º dir 2º dir wget -nH --cut-dirs=2 http://www.manuales.com/informática/editores/nano.pdf Example 3: We want to download the Arocena manual in html format whose page is in: http://usuarios.lycos.es/ortihuela/index.htm wget -r -nH http://usuarios.lycos.es/ortihuela/index.htm

Rate this article :

4/5 | 5 opinion

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

2mn reading

How do I configure the firewall on a dedicated VPS server?

1mn reading

How can I connect as root on a dedicated VPS server with Putty?

0mn reading

SSH - Apt-get command: Installing and uninstalling packages

0mn reading

SSH - Access rights on files or directories (Chmod)


Questions sur l'article
andre Il y a 665 days
je souhaite associer mon vps avec mon nom de domaine
See the
1 answers
Benjamin-LWS - Il y a 662 days

Bonjour,

Afin d'associer votre domaine à votre VPS SSH, suivez les instructions suivantes :

- Accédez à votre Panel LWS lié au VPS

- Cliquer sur l'onglet "Configurer mon domaine"

- Dans cette nouvelle page, ajoutez votre domaine, et cocher si votre domaine est hébergé ou non chez LWS.

(Si votre domaine est hébergé ailleurs, il faudra changer le champ A dans la zone DNS du domaine par l'IP du VPS.)

Si vous souhaitez une assistance lors de la liaison de votre domaine, vous pouvez contacter notre support VPS depuis votre espace client (https://aide.lws.fr/a/268).

Utile ?

Ask the LWS team and its community a question