Here is an article that will be completed as I discovered. It condenses a little more than a hundred commands that it is useful to know under Linux, whether on a desktop / laptop or a server, keep them at hand, they will always be useful! Keep in mind that this post can in no way replace the famous “man”, it is rather a cookbook commands that come back the most.

Basic commands, file browsing

ls
List files in a folder. Options: -afor hidden files, -lfor detailed list, -hfor sizes in “human readable” units. Very convenient the option -Rat a glance to view the subfolders.
cd
Change directory, the command allows to navigate in the tree. For example, cd /var/loggo to the logs folder, wherever you are, since you have set the start slash, which indicates that it is an absolute address. However, cd myfile/imagesgoing into the directory imagesof myfilewhich is the place where one is already situated. Since there is no initial slash, this is a relative address, so we add this path to the one in which we are already.
du
Disk usage, specifies the disk space that each file or folder takes (the option -hallows to obtain the sizes in “human readable”), while the option --max-depth=x(or -d), very useful also, allows to limit the detail to A sub-folder level. --max-depth=1Will therefore only return the size of the current directories. This command is especially handy when it ls -ldoes not give us the size of a folder.
pwd
Print working directory. This command simply displays the absolute path of the folder in which you are located,

<span class="typ">Wesharethis $ </span><span class="pln">pwd
 </span><span class="pun">/ </span><span class="pln">etc </span><span class="pun">/ </span><span class="pln">apache2</span>
ssh
Secure shell. Allows you to connect to the shell of a remote computer and execute commands there.

<span class="pln">ssh login @ ip or name_h </span><span class="pun">O </span><span class="pln">you</span>

And that’s all, to disconnect, it will be exit, and all commands usually usable in a terminal are also used via ssh. A very practical option of ssh is the tunneling which allows for example to thwart the firewalls by the installation of a proxy socks. If some ports are blocked and prevent you from using a particular service or accessing a particular site (on vacation in China?), The solution is to redirect everything to a local port and leave the remote machine – who is not behind a fire part – access unauthorized resources. We will redirect all our traffic to a predefined port (in this case 2017), through our SSH connection.

<span class="pln">Ssh </span><span class="pun">- </span><span class="pln">D 2017</span> <span class="pln">login @ ip_server_distant</span>

The last step for this to work is for your outbound traffic to be redirected to port 2017. You can configure it in your browser and all connections on your computer in network preferences.

clear
Cleans your terminal window by relegating all the text to the top (thus accessible with a scroll) and thus leaving you facing a clean window. Very useful from time to time to see more clearly. The keyboard shortcut ctrlldoes the same.
ctrl + r
Very very convenient, allows to make a search in the history of the orders. Usually, you go back in the commands already typed with the up arrow, well with ctrlr, you can make a search in this history, make ctrlr, then type a tip of the command you want to search, magic!
for
This is certainly the most complex command this section, especially if you do not program. forIs a loop instruction. A loop allows to execute an action several times, on all the elements of a variable. For example, we can very easily rename all files in a directory to replace spaces with hyphens.

<span class="com"># For all elements in the current directory </span><span class="com"># the instruction in place the corresponding elements in the variable oldname </span><span class="kwd">for </span><span class="pln">oldname </span><span class="kwd">in </span><span class="pun">* </span><span class="com"># do executes the loop action </span><span class="kwd">do </span><span class="com"># use here sed to rename, </span><span class="com"># use of the command Is explained later in the article </span><span class="pln">
  newname </span><span class="pun">= </span><span class="str">`echo $ oldname | </span><span class="str">Sed -e 's / / _ / g'`</span>

 


  
  

  <span class="com"># Invokes the mv command to replace the old name with the new </span><span class="pln">
  mv </span><span class="str">"$ oldname" </span><span class="str">"$ newname" </span><span class="kwd">done</span> 

Operation on files

cat
Read the contents of a text file cat myfile.txt
less
Similar to catbut displays the file page by page. So it’s more convenient for long files.
head
Displays the header of a file, the option -nallows you to specify the number of lines to display.
tail
Similar to headbut relates to the “tail” of the file, in other words, this command only displays the end. A very appreciable option -ffor follow, allows to update in real time the display of the end of the file, which is very useful to follow the evolution of a log file for example;
touch
Create a file. Just do it  file_name. As Franckito specifies in the comments the touchprimary purpose is to modify the timestamp of a file. If you do touchon a file that already exists, it will refresh its dates of last access and modification.
mkdir
Create a folder, the operation is the same as that of the command touch.mkdir Folder_Name
Copy, make a copy of a file. The option -Rallows you to make copies of entire folders.

<span class="pln">Cp original_file copy of the file

</span><span class="com"># You can also place the copy directly in another folder </span><span class="pln">
cp file_original folder_name </span><span class="pun">/ </span><span class="pln">copy_of_file</span>
mv
Move, allows you to move files / folders. The mv command is used in exactly the same way as the command cp. In addition, this command also allows you to rename files and folders simply by changing their name.

<span class="pln">Mv my_file my_file_new_name</span>
rm
Remove, delete files. rm file_name. The option -fforces the deletion, the option -iasks for a confirmation before deletion, finally the option -rallows the deletion of the files.
rmdir
Remove directory, deletes a folder only if it is empty.
ln
Link, create a link between two files. The option -screates a symbolic link.

<span class="com"># Create a hard link</span><span class="pln">
Ln file1 file2

</span><span class="com"># Create a symbolic link </span><span class="pln">
ln </span><span class="pun">- </span><span class="pln">s file1 link_to_file1</span>
wc
Word count, lets you count the number of lines, words, and characters in a text file. The options are -lfor line (number of lines), -wword (number of words) and -mnumber of letters. There is also the option -cto have the file size in bits. To use it, you simply provide as parameter the address of the text file:

<span class="typ">Wesharethis $ </span><span class="pln">wc </span><span class="pun">- </span><span class="pln">l test </span><span class="pun">. </span><span class="pln">Rtf 
       </span><span class="lit">33 </span><span class="pln">test </span><span class="pun">. </span><span class="pln">rtf</span>

wcAlso makes it easy to know how many files / folders you have in a given directory, just redirect the output of a lsworm wcls | wcand you’re done!

sort
Sort a text file in alphabetical order. The option -rallows to perform a reverse sort, ie anti-alphabetical or decreasing for the numbers, and the option -Rallows a random sort, it is the mode shuffle what;) One will not forget either The option -uthat eliminates duplicates. Finally the option -oallows to create a new file with the sorted results:

<span class="pln">fate </span><span class="pun">- </span><span class="pln">o Sorted_file </span><span class="pun">. </span><span class="pln">Txt file_in_brothel </span><span class="pun">. </span><span class="pln">txt</span>
uniq
The command uniqallows to duplicate a file. Simply pass it as parameter the address of the file to be duplicated and the name of the new file to be created.

<span class="pln">Only duplicates </span><span class="pun">. </span><span class="pln">Txt </span><span class="kwd">no </span><span class="pun">- </span><span class="pln">duplicates </span><span class="pun">. </span><span class="pln">txt</span>
cut
Cut into a text file. To cut all lines in a given number of characters, use the option -ccut -c 2Will retain only the first two characters. We can also give an interval:, cut -c 2-4then we will keep only the characters two to four. Example, “unconstitutionally” will be transformed into “ntic”. It is also possible to use delimiters to cut text, with options -dand -f. Files in .csv formats separate the various fields, columns, by semicolons ;. In a file where we would have three fields, the name, the first name and the city, if we want to extract the city,cut -d ; -f 3-d-f
tar
tarIs the archive utility. It allows you to group files and folders into a single archive. The interesting options are: tar -cvf(create, verbose, file) allows to create an archive, to display all the details of the process (verbose mode) and to put everything in a folder. Example:

<span class="pln">tar </span><span class="pun">- </span><span class="pln">cvf New_archive </span><span class="pun">. </span><span class="pln">Tar My_file_has_to_archive</span>

Inverse process, to “undo” an archive, one uses the options -xvf(eXtract, verbose, file) tar -xvf archive.tar. The options are -tfused to display the contents of an archive without opening it. It is also possible to compress and decompress on-the-fly the archives tar, it is necessary to add to this the option -zwhen creating or opening the archive tar -zcvf compress.tar.gz compress/.

gzip
Can compress a tar archive in zip format. gunzip archive.tar.gz, Then use the command gunzipto unzip it.
bzip2
Works exactly the same way as gzipbut compresses to format bzip. To decompress the archive, the equivalent of gunzipis here bunzip2.
zcat zmore zless
zcatzmoreAnd zlessperform the same functions catmoreand lessyet to be applied to compressed files.
iconv
Allows you to change the encoding of a file. Option -fto specify the original encoding and option -tfor the destination encoding. By default, iconvreturns everything on the standard output, so if you want to directly send the results to a file, just make a small redirect:

<span class="pln">Iconv </span><span class="pun">- </span><span class="pln">f UTF </span><span class="pun">- </span><span class="lit">8 </span><span class="pun">- </span><span class="pln">t UTF </span><span class="pun">- </span><span class="lit">17 </span><span class="pln">file </span><span class="pun">. </span><span class="pln">Txt </span><span class="pun">>> </span><span class="kwd">new </span><span class="pun">- </span><span class="pln">encoding </span><span class="pun">. </span><span class="pln">txt</span>
wget
Copies a remote file to the computer. wget http://www.site.org/rep/01/file.txt.
scp
Aims to fulfill the same function as the copy command cp, but it allows to copy the files in a secure way through the network; That is, between remote hosts. As with cpthe option, you -rcan copy an entire directory. scp Sample_file login@Ip_or_ address: destination address.

<span class="pln">Scp test </span><span class="pun">. </span><span class="pln">Txt wesharethis @ 192 </span><span class="pun">. </span><span class="lit">168.0 </span><span class="pun">. </span><span class="lit">128 </span><span class="pun">: ~ / </span><span class="pln">transfer

</span><span class="com"># And to retrieve a file from a remote host </span><span class="pln">
scp wesharethis @ 192 </span><span class="pun">. </span><span class="lit">168.0 </span><span class="pun">. </span><span class="lit">128 </span><span class="pun">: ~ </span><span class="str">/movie.mkv ~ /</span>
rsync
It is a utility that allows to synchronize files. Very useful for backup. These are the options -arvI use. -aRetains rights etc, -rallows recursion and -vfor verbose mode. A small example of saving my workplace  photos:

<span class="pln">Rsync </span><span class="pun">- </span><span class="pln">arv photo backup_photo</span>

It is useful to specify that if you delete files in the source folder, rsyncdo not pass the deletion to the backup folder if you do not append the option to it --delete. In case you do not want to completely delete the files, it is possible to place them in a separate folder, options: --backup --backup-dir=Small example for the form?

<span class="pln">Rsync </span><span class="pun">- </span><span class="pln">arv photo </span><span class="pun">~ </span><span class="str">/ backup_photo --delete --backup --backup-dir = ~ / </span><span class="pln">backup_photo </span><span class="pun">/ </span><span class="kwd">delete</span>

Of course, it is possible to make a remote backup.

<span class="pln">Rsync </span><span class="pun">- </span><span class="pln">arv photo wesharethis @ myserver </span><span class="pun">: ~ / </span><span class="pln">backup_photo </span><span class="pun">- </span><span class="kwd">delete</span>

In the case of a remote backup, it may be very advantageous to enable compression, thus rsynccompressing files transparently during transfer. This magic option has a small name -zlike zip.

Last thing, in case your server does not listen on port 22 in ssh, option -e, example for an ssh on port 443 -e 'ssh -p 443'.

file
Determines the type of a file regardless of its extension. It is enough to provide him with parameter the file to be evaluated.
split
Cut a file into smaller files (-l specify a number of lines, -b specify a size in bytes (follow the size of K, M, G, T to define a different unit). split -l 300 test.txt, Or 1MB files split -b 1000000 my_file.
<a title="Buzut – La commande sed pour les nazes" href="https://wesharethis.com/wiki/sed-command-nazes/">sed</a>
In commands that manipulate text, sedis undoubtedly one of the most powerful. Replacing according to a regular expression, erasing some expression where line according to a given keyword … Only disadvantage, which says power also says complexity. sedIs not explained in two lines and that is why We devoted a whole article to it. Is it worth it !
awk
awkIs a programming language on its own. This command allows the search of strings and the execution of actions according to the found patterns. Of a formidable power, it is also quite complex. So I redirect you to our tutorial here
locate
This command allows to locate a file on the hard disk. locate myfile.txt. The command locateis very fast because it finds the file by consulting a database. It does not scan the hard disk directly in search of the file in question. The disadvantage of this method is that if the file is very recent, it may not yet be indexed, and locatewill then be of no help to you. You can force the update of the database with the command sudo updatedb. You can also turn to the command find.
grep
Allows you to search by regular expressions. In its simplest form, it grepwill display the row containing a keyword (with the option to -odisplay only the matching expression), from a file or another command. For example, if you want to display all ssh process, it will filter the command ps auxgrep: ps aux | grep sshgrepAlso allows to search in the contents of files. An example from my article on the disinfection of a WordPress where one looks for any .phppotentially infected file :

<span class="com"># Option -l to match only certain types of files (here the .php) </span><span class="com"># option -r for recursion (search in subfolders) </span><span class="com"># option -E for extended REGEXP syntax </span><span class="pln">
grep </span><span class="pun">- </span><span class="pln">include </span><span class="str">"* .php " </span><span class="pun">- </span><span class="pln">rlE </span><span class="str">'viagra | pharma | Tadacip | eval | base64_decode | socket_shutdown | socket_close | socket_clear_error | fopen | curl' </span><span class="pln">www </span><span class="pun">/</span>

find
The control findis much more powerful than locateit is, but it is also much slower as it traverses the disc as the search progresses. Its syntax is as follows find /Search_address/ element_to_find. This syntax is only a base. findAllows to search according to a size or date of last access, but also to perform actions on the found files, to call a command etc. A man page to read so …

Knowing the date of last access is very practical and powerful, some examples:

<span class="com"># The easiest to find a file whose name is known </span><span class="com"># find all .htaccess in / var / www </span><span class="pln">
find </span><span class="pun">/ </span><span class="kwd">var </span><span class="pun">/ </span><span class="pln">www </span><span class="pun">- </span><span class="pln">name </span><span class="str">".htaccess"</span>


<span class="com"># List files in www by date of last modification </span><span class="pln">
find </span><span class="pun">/ </span><span class="pln">www </span><span class="pun">- </span><span class="pln">type f </span><span class="pun">- </span><span class="pln">printf </span><span class="str">'% TY-% Tm-% Td% TT% p \ n' </span><span class="pun">| </span><span class="pln">Out </span><span class="pun">- </span><span class="pln">r</span> 

<span class="com"># We can be more precise by displaying the modified files in the x (here 50) last minutes </span><span class="pln">
find </span><span class="pun">/ </span><span class="pln">target_directory </span><span class="pun">- </span><span class="pln">type f </span><span class="pun">- </span><span class="pln">mmin </span><span class="pun">- </span><span class="lit">50</span>

<span class="com"># Or the last 24 hours </span><span class="pln">
find </span><span class="pun">/ </span><span class="pln">target_directory </span><span class="pun">- </span><span class="pln">type f </span><span class="pun">- </span><span class="pln">mtime </span><span class="pun">- </span><span class="lit">24</span>

<span class="com"># You can finally choose an interval (between yesterday and the day before yesterday) </span><span class="pln">
find </span><span class="pun">/ </span><span class="pln">target_directory </span><span class="pun">- </span><span class="pln">type f </span><span class="pun">- </span><span class="pln">mtime </span><span class="pun">- </span><span class="lit">48 </span><span class="pun">! </span><span class="pun">- </span><span class="pln">mtime </span><span class="pun">- </span><span class="lit">24</span>  

<span class="com"># Last but not least, move files that have more than 24 hours (or changed more than 24h) </span><span class="pln">
find </span><span class="pun">/ </span><span class="pln">target_directory </span><span class="pun">- </span><span class="pln">type f </span><span class="pun">- </span><span class="pln">mtime </span><span class="pun">- </span><span class="lit">24</span>

You will most certainly notice that we are using here mtimefor the last m odification. There is also :

  • mmin For the minutes,
  • atimeand aminfor the last has ccess,
  • ctimeand cminfor the last c hange.

You can read this article and this post to fully understand the differences and implications change time and modification time.

Redirect flow

>
Return the result to a file (if it exists, it will be overwritten).
>>
Return the result to a file (if it already exists, add the result to the end) there are two outputs: 1 the normal output, 2 the error output.
2>
Create a file for errors. 2>>Also exists.
2>&1
merges the two outputs in a single file eg: ./Script_of_the_error.sh > file.log 2>&1.
<
Take an input file. Ex cat < file.txt.
<<
Input the keyboard as you go. This allows us to pass data directly to a command without the need to create a file. Let’s say we want to sort first names alphabetically. We will invoke the command sort, but instead of creating a text file and then having it reordered sort, we will directly submit the names to them by typing them in:

<span class="com"># Place a keyword after the "<<" which is used to delimit the input data. </span><span class="com">#This keyword is quite arbitrary </span><span class="com">#one press "enter" after each first name to separate the different data </span><span class="pln">
sort </span><span class="pun"><< </span><span class="pln">STOP 
 </span><span class="pun">> </span><span class="pln">antoine
 </span><span class="pun">> </span><span class="pln">clement
 </span><span class="pun">> </span><span class="pln">quentin
 </span><span class="pun">> </span><span class="pln">jordan
 </span><span class="pun">> </span><span class="pln">mathilde
 </span><span class="pun">> </span><span class="pln">clementine
 </span><span class="pun">> </span><span class="pln">elena
 </span><span class="pun">> </span><span class="pln">helena
 </span><span class="pun">> </span><span class="pln">stone
 </span><span class="pun">> </span><span class="pln">STOP</span>

<span class="pln">
antoine
clement
clementine
elena
helena
jordan
mathilde
Pierre
quentin</span>
|
Redirect the result of one command to another. Ex sort prenoms.txt | uniq.

Multitasking and background program

&
& put at the end of a command to start another without waiting for the end of the first eg cp video.avi /users/wesharethis/desktop/copy-video.avi &. This command also allows to place the command in the background and immediately restores access to the shell.
nohup
Starts the program and keeps it even after the console is closed. Outputs 1 & 2 are redirected to nohup.out. Example:

<span class="pln">Nohup ffmpeg </span><span class="pun">- </span><span class="pln">i video </span><span class="pun">- </span><span class="pln">source </span><span class="pun">. </span><span class="pln">mkv </span><span class="pun">- </span><span class="pln">vcodec libx264 </span><span class="pun">- </span><span class="pln">preset slow video </span><span class="pun">- </span><span class="pln">re-encoded </span><span class="pun">. </span><span class="pln">mp4</span>
ctrl + z
Pause the current process.
bg
Pass the process that is paused in the background.
fg
Resume a process in the foreground (if several rotate at the same time, fg %n°).
at
Program a task to execute at a later time ex: at 18:22or at now + 5hoursthen ctlrd.
atq
List pending jobs.
atrm
Delete jobs.
sleep
This command is used to pause the execution of two commands. Example: touch gt.txt && sleep 10 && rm gt.txt
The break is expressed in seconds by default, though you can change this by following the number by one: mhor drespectively the minutes, hours and days.
crontab
Crontab is actually a command that allows you to read and edit a file called the “crontab”.
e
Modify the crontab.
l
Display the current crontab.
r
Delete your crontab. Attention, the removal is immediate and without confirmation!
screen
Multiplexer of terminals. Under this somewhat barbaric term actually hides a kind of virtual terminal. You are at work, you open a terminal and you name it, you launch a task (a script that will reencoding several GB of videos for example, which takes time), and you disconnect, you arrive at your home, you reopen Your terminal and find your task as if everything had remained open in front of you.

<span class="com"># Create a screen </span><span class="pln">
screen </span><span class="pun">- </span><span class="pln">S </span><span class="pln">screen </span><span class="pln">name

</span><span class="com"># To detach it (it means that it is no longer displayed but remains active), </span><span class="com"># ctrl a then d</span>


<span class="com"># To attach to a detached </span><span class="pln">
screen </span><span class="com">, </span><span class="pln">screen </span><span class="pun">- </span><span class="pln">r screen_name

</span><span class="com"># To list open screens </span><span class="pln">
screen </span><span class="pun">- </span><span class="pln">ls

</span><span class="com"># To exit / close a screen, such as to close a terminal -> exit</span>

<span class="com"># It is not possible to attach to a non-detached screen </span><span class="com"># (screen not detached in a terminal to which one tries to attach itself from another one) </span><span class="com"># we can however share a screen, </span><span class="com"># we see then all Commands typed in either terminal </span><span class="com"># to connect to a non-detached </span><span class="pln">
screen screen </span><span class="pun">- </span><span class="pln">x screen_name</span>



You will sometimes want to go back in the screen of the screen, to do this, you have to pass in copy mode with the ctrl+ keys athen [. You can then navigate with the directional arrows. Finally to exit this mode ctrlathen esc.

Rights, groups and users

sudo
Execute a command as root.
sudo su
Pass root and remain so.
chmod
Change the rights on a file or folder (option -Rfor recursion in all the file and subfolder of the folder on which it is applied).
adduser
Add a user.
passwd
Change the password of a user | Ex passwd roger.
deluser
Delete a user (option --remove-hometo delete all its files).
addgroup
create a group.
usermod
Modifies a user (options: -lto change the name, -gto assign a group -Gto him , to assign to him several groups (separated by commas), -ain addition to -gor -G, to add new groups instead of redefining all) Wesharethis the user, without removing the groups to which he belonged before: usermod -aG video wesharethis.
delgroup
Delete a group.
groups
Checks in which groups a user is groups myuser.
chown
Changes the owner of a file / folder (can only be used as root) -R option for recursion.
chgrp
Changes the group owning a file (equivalent to chown user:group).
passwd
Although it is not technically a command, it seems to me important to know the structure of the file /etc/passwd. This includes all users of the system and their information.

<span class="com"># For example sensu user </span><span class="com"># 1: 2: 3: 4: 5: 6: 7 </span><span class="pln">
sensu </span><span class="pun">: </span><span class="pln">x </span><span class="pun">: </span><span class="lit">999 </span><span class="pun">: </span><span class="lit">999 </span><span class="pun">: </span><span class="typ">Sensu </span><span class="typ">Monitoring </span><span class="typ">Framework </span><span class="pun">: </span><span class="str">/ opt / </span><span class="pln">sensu </span><span class="pun">: </span><span class="str">/ bin / </span><span class="kwd">false</span>
  1. Username,
  2. Password (x means that the mdp is encrypted in the file /etc/shadow,
  3. The id of the user (0 is for root and ids from 1 to 99 are reserved for predefined accounts),
  4. The id of the group as defined in /etc/group,
  5. Field of comment,
  6. The home directory of the user,
  7. The default shell ( /bin/falseand /usr/sbin/nologinmean that the user has no shell).

System

w
Who is connected and does what.
who
Which is connected.
date
Gives the time.
ntpdate
Synchronizes the time with an ntp server. The server must be specified when ordering ntpdate pool.ntp.org. Also, think that the NTP port (123 in UDP) must be open on your machine.
uptime
Time since starting + load (average load 1 – 5 – 15 min).
free
Indicates the allocation of the ram and the remaining free memory.
vmstat
Info ram, swap, cpu.
proc/meminfo
The file /proc/meminfocontains a lot of memory information. Just show it out with it cat /proc/meminfo.
tload
Displays the CPU load as a graph.
ps -ef
View all the processes launched. Alternatively, one can use the BSD syntax ps aux.
ps -ejH
Show process to tree.
ps -u
list the process launched by a given user eg ps -u wesharethis.
top
The real-time system activity: load, RAM, SWAP process … tophas the advantage of being installed almost everywhere.
htop
It is an improved version of top, a little more graphic, the info is clearer and it is possible to sort / order the display according to certain criteria.
glances
similar to topand htopglancesis the dash of your machine as it met in a glance all the important metrics: CPU, load, RAM, swap, i / o discs, filling the disk. This is the work of  Nicolargo and its tool is now integrated into the repositories of the latest versions Debian & co.
atop
We talked about above topand htop, but there is also atopthat is very useful when you have to do a more detailed diagnosis. Generally, We use htopas a replacement for top as it is more ergonomic and readable, but when something goes wrong on the server, direction atop! To approach serenely the beast, I advise you to read this article in our knowledgeable base, admirable of clarity.
iotop
In the line of *top, here is iotopwhat, as the name implies, allows to have a real time view of the disk I / O.
swapoff
swapoff -aAllows to disable the swap while its counterpart swapon -aallows to activate the swap (s). The execution of this swapoff -a && swapon -aallows to force the purge of the swap.
kill
Kill a process (will ask for its PID).
kill -9
Force to leave.
killall
Leaves all instances of a program.
reboot
Restart the operating system.
shutdown
Program a restart or stop.
poweroff
Although quite similar to shutdown as it allows to shut down the system, poweroff also allows according to the arguments that are passed to him, to reboot or to change runlevel. You can also see this thread [in] that explains the differences between poweroffand shutdown.
halt
Allows “shutdown” of the system. I put stop in quotes because the system may remain powered with this command (as past options and default settings of the system). Look at the differences between shutdown and halt  .
last
History of connections.
df
Filling discs (the option -hallows to obtain the sizes in “human readable”).
mount
Allows to mount the device of a file system under a local directory. For example, to mount the partition /dev/sdb1to the mount point /homemount /dev/sdb1 /home/. Conversely, we use umountto disassemble the volume.
fdisk
Allows you to manage partitions. Displays the partition table if the option is used -l. To create or modify partitions, use the interactive mode fdisk /dev/sdxor /dev/sdxthe path to your disk. Then, the option mwill list all the possible commands, let you guide! You can take a look at the article on Linux partitioning to find out what types of partitions create and why.
parted
Similar to fdiskpartedsupports GPT partition. The option -ldisplays the partition table.
fsck
This utility allows you to check and repair the file system.
dd
The tool allows you to perform operations on the disks, such as erasing them , for example, dd if=/dev/zero of=/dev/sdcor cloning a disk ; Ex dd if=/dev/sda1 of=/dev/sdb1 bs=64K conv=noerror,sync.
ddrescue
When faced with a damaged hard drive, it is better to try to clone it ddrescuethan with dd. The first is indeed dedicated to this use. It can perform a first pass to recover the maximum data by ignoring the damaged sectors, and then in a second pass it will attempt to recover the damaged data. The doc Archlinux many details the recovery process.
smartctl
smartctlDisplays the smart information on a disk. smartctl -a /dev/sdaDisplays all the information about sda. The Wikipedia file about SMART provides a good explanation of the different data and their interpretation.
/proc/mdsat/
File that contains information about your software RAID. It can display this information by making a catcat /proc/mdstat. Read the article on the various levels of RAID (integrated simulator) to find the RAID that corresponds to you. You can also consult this wiki  to orient yourself in the jungle of the information delivered by mdadm..
mdadm
This command allows you to get information about the RAID soft and to parameterize them (to remove a disk from the array, to add one, to rebuild it in case of failing disk …). For example mdadm --detail /dev/md0will give all the details related to an array. Note that this command is quite close to the option --examine, but it is applied to a disk that is part of a raid --examine /dev/sd*and not to the raid volume. This command is very rich and serves many functions, I let you refer to the manpage for more details. You can also find valuable information about the linux raid wiki.
lsof
List open files, lists open files. As noted by MagiCrazy in the comments, this command can be very useful to see which file blocks the disassembly of a filesystem for example.
hostname
Displays the host name of the machine according to what is written in the file /etc/hostname.
uname
Information about the system and the gear.
lsb_release
lsb_release -a Gives all information about the distrib.
lshw
Gives a detailed list of system hardware such as ram configuration, firmware version, motherboard configuration … With the option -shortyou will get a more digestible output. The option is -c networkalso useful to know the name of a network interface still not configured with the systemD naming standard .
lsblk
List all block devices (hard disk).
lspci
Lists all PCI devices.
lsusb
Lists all USB devices.
/proc/version
File that contains kernel info. One can view its content with catcat /proc/version.
/proc/cupuinfo
File that contains information about the processor. One can view its content with catcat /proc/cupuinfo.
sysctl
This command allows you to view and configure kernel parameters (hot). Very handy with a shot of grepsysctl -awill give you all the kernel settings. The option -pis also interesting because it allows to reload the parameters either from /etc/sysctl.confdefault or from a file passed as parameter.
dmidecode
Reads bios info.
dmesg
Displays messages from the kernel buffer.
apt-cache
Management of packages. Two options are very useful apt-cache search package_name, allows you to search for a package, and apt-cache show, allows to get details about a package.
apt-get
Management of packages. The most updatecommonly used commands are (update packages and packages upgrade), installapt-get intall trick-to-installto install new software and its dependencies), purge(allows to uninstall a package more “Clean” that remove because it also deletes the configuration files).
apt
Appeared fairly recently, aptis described in his man as the front-end users for more interactive use of other specialized tools such as apt-getor apt-cache. It offers on the whole the same possibilities as apt-get. I retain a very special command: apt list --upgradablewhich allows to list the packets that will be updated if have done one upgrade(with aptor apt-get).
aptitude
This is another packet utility. Newer than apt-get, it is installed in parallel of it on Ubuntu and Debian. Prefer it to apt-get. It is generally used as apt-get but is more efficient.
add-apt-repository
add-apt-repositoryMakes it possible to add alternative deposits to official deposits. This is very useful because official repositories often lag behind software releases released by developers and some software programs are even missing. So, for example, by adding developer repositories, you can benefit from the latest versions just by using apt-getor aptitude, without compiling!

For example, FFMPEG had been removed from Ubuntu’s official repositories (reinstated in version 15.04) in favor of Libav, its fork. To enjoy the latest versions of FFMPEG without having to manually compile each time:

<span class="pln">Sudo add </span><span class="pun">- </span><span class="pln">apt </span><span class="pun">- </span><span class="pln">repository </span><span class="pln">ppa </span><span class="pun">: </span><span class="pln">kirillshkrogalev </span><span class="pun">/ </span><span class="pln">ffmpeg </span><span class="pun">- </span><span class="kwd">next</span>

<span class="com"># We update our packet list </span><span class="pln">
sudo apt </span><span class="pun">- </span><span class="kwd">get </span><span class="pln">update

</span><span class="com"># If ffmpeg is not installed install </span><span class="pln">
sudo apt </span><span class="pun">- </span><span class="kwd">get </span><span class="pln">install ffmpeg

</span><span class="com"># If it is already installed, </span><span class="com"># an upgrade will update it </span><span class="pln">
sudo apt </span><span class="pun">- </span><span class="kwd">get </span><span class="pln">upgrade</span>

Last tip, it is not a specific command, but a combination of commands that make it possible to search a deposit on the system:

<span class="pln">Grep </span><span class="pun">^ </span><span class="str">/ etc / </span><span class="pln">apt </span><span class="pun">/ </span><span class="pln">sources </span><span class="pun">. </span><span class="pln">List </span><span class="pun">/ </span><span class="pln">etc </span><span class="pun">/ </span><span class="pln">apt </span><span class="pun">/ </span><span class="pln">sources </span><span class="pun">. </span><span class="pln">List </span><span class="pun">. </span><span class="pln">D </span><span class="com">/ * | </span><span class="com">Grep name_of_ppa</span>
apt-key
This command is often coupled with the addition of repositories since it allows to manage the cryptographic keys by validating the authenticity. We will use it most often apt-key advto add new keys, Askubuntu details the usage very well. apt-key listAllows to list all the keys installed and allows to delete a key.apt-key del
apt-cache madison
Another convenient command, apt-cache madison name_of_packetdisplays the various repositories linked to a given packet and the current versions of each.
dpkg
Info on installed packages (options to list all packages, uninstall etc) ex: list of installed packages dpkg --get-selections. The option -lalso provides an exhaustive list and a short description of each packet, which can be very convenient. It is sometimes observed that a large number of packages are marked to be uninstalled with the tag deinstall, to remove everything at once:

<span class="pln">Dpkg </span><span class="pun">- </span><span class="pln">purge </span><span class="str">`dpkg --get-selections | Grep deinstall | Cut -f1`</span>
Update kernel
If your partition /bootis independent and not very large, it is likely that after a certain time you will have to do a bit of cleaning, otherwise the space needed to update the kernel is insufficient. We must therefore remove the old nuclei, to do this:

<span class="pln">Apt </span><span class="pun">- </span><span class="kwd">get </span><span class="pln">purge $ </span><span class="pun">( </span><span class="pln">dpkg </span><span class="pun">- </span><span class="pln">l linux </span><span class="pun">- { </span><span class="pln">image </span><span class="pun">, </span><span class="pln">headers </span><span class="pun">} - </span><span class="str">"[0-9] *" </span><span class="pun">| </span><span class="pln">awk </span><span class="str">'/ ii / {print $ 2}' </span><span class="pun">|</span>  <span class="pln"> grep </span><span class="pun">- </span><span class="pln">ve </span><span class="str">"$ (uname -r | sed -r '' / - [az] + // ') " </span><span class="pun">)</span>

Now you only have the kernel currently in use, and you can now do your update without any problems. You will find more details about this command on this askubuntu thread.

service
This command is used to manage services. Start, stop, list system services etc. For example, to restart nginx after a change in the config file, we will do service nginx restart(note that reloadenough in some cases). The service --status-allconvenient command allows you to list all the services available on the system.

The parameter is statusoften very useful since it gives information about a particular service, especially if it is active or not. Example service nginx status.

It is also possible to activate or deactivate the automatic start of services to the boot, for this, one must trade the command service for the native command systemctl. Take apache2 for example:

    <span class="com"># Enable / disable a service</span><span class="pln">
    Systemctl enable apache2
    Systemctl disable apache2

    </span><span class="com"># Check if a service is launched at boot </span><span class="pln">
    systemctl </span><span class="kwd">is </span><span class="pun">- </span><span class="pln">enabled apache2</span>
make
Makes it possible to compile a program whose sources are held. In general we do ./configure[start with --helpto see the different compilation options] (starts the configuration script which checks the presence of all the dependencies, and writes the makefile file that contains the compilation commands) make, and Finally make install(it installs the software).
update-rc.d
update-rc.dCan be used to configure automatic start-up or shutdown at start-up or runlevel. We give as argument the name of the service and the action (remove or default for the addition) update-rc.d -f apache2 remove-fMakes it possible to force the deletion of the symbolic link even if the name still exists. You can also put a startup script in the directory /etc/init.dor fill it with the file /etc/rc.local(which itself has a symbolic link in /etc/init.d).
/etc/passwd
File that contains the various user accounts of the machine (which includes the accounts used by the software ex: www-data for Apache). It can display information with catcat /etc/passwd.
cat /etc/group
File that contains the user groups of the machine (which includes the groups used by the software eg www-data for Apache). It can display information with catcat /etc/group.
which
Locating a command ex:

<span class="pln">Which cat
 </span><span class="pun">/ </span><span class="pln">bin </span><span class="pun">/ </span><span class="pln">cat</span>
whereis
Locate a binary file.

Web

Web wants to say everything and say nothing at the same time, especially since we are already talking about a server. However, this section is particularly relevant to commands related to web servers. We obviously think of Apache2 immediately but others could be added.

a2ensite
Activate an vhostApache:a2ensite wesharethis
a2dissite
Disable an vhostApache:a2dissite wesharethis
a2enmod
Enable an Apache module: a2enmod rewrite
a2dismod
Disable an Apache module: a2dismod rewrite
a2enconf
On the same model as for vhost and modules, a2enconfand a2disconfallow to activate or deactivate configurations. For example, when no explicit information about the file of access.loga virtual host, Apache log all in a dedicated file: other_vhosts_access.log. If we would not want to eg access logs, you can disable this configuration: a2disconf other-vhosts-access-log.
apache2ctl
apache2ctlOn the one hand, acts as an init script (which is not very useful since the command is usually used service). And secondly to control the Apache process and retrieve information about it. apache2ctl -SIs quite useful since it allows to see how apache interprets our Vhost, the option -Mlists the Apache modules activated. Finally, the option -helpwill tell you more about the other available commands!
curl
curlAllows, like wget, to retrieve a file from a url, but if it deserves its place here is that it allows much more. It is indeed the Swiss knife of HTTP. It will be used to test queries in different formats, to analyzeHEADERS etc.

<span class="com"># Query get classic </span><span class="pln">
curl https </span><span class="pun">: </span><span class="com">//wesharethis.com</span>

<span class="com"># Display headers </span><span class="pln">
curl https </span><span class="pun">: </span><span class="com">//wesharethis.com  -D -</span>

<span class="com"># Make a request of type X (HEAD, POST, PUT, PATCH, DELETE ...) </span><span class="pln">
curl </span><span class="pun">- </span><span class="pln">X HEAD https </span><span class="pun">: </span><span class="com">//wesharethis.com</span>

<span class="com"># Pass parameters in form data </span><span class="pln">
curl </span><span class="com">format </span><span class="pun">- </span><span class="pln">X POST </span><span class="pun">- </span><span class="pln">data </span><span class="str">"email=my@mail.com&passwd=azerty" </span><span class="pln">https </span><span class="pun">: </span><span class="com">//mysite.com/login</span>

<span class="com"># Same request with parameters in request payload, JSON. (here we add a header) </span><span class="pln">
curl </span><span class="pun">- </span><span class="pln">H </span><span class="str">"Content-Type: application / json" </span><span class="pun">- </span><span class="pln">X POST </span><span class="pun">- </span><span class="pln">data </span><span class="str">{ "email", "my@mail.com" "passwd", "QWERTY"} ' </span><span class="pln">https </span><span class="pun">: </span><span class="com">//mysite.com/login</span>

Network Management

iftop
In the same vein as top, iftop is used to monitor all network connections. Caution, iftop requires root privileges to be run. If you are not root, consider doing it sudo.
speedometer
A bit more graphic than iftopspeedometermonitor the traffic of your inputs / outputs, monitor the progress of a download, know how long it will take to transfer a file or know the speed of your system.
exim4
Exim is an MTA that allows to send emails from the server. Without it (or another MTA) the function mail()of php or other languages ​​will not be effective. There are others, but this one is robust, secure, modular and requires few resources. Its installation is very simple, I explain in this article on logging.
ifconfig
This most indispensable command allows to obtain information and to configure the network interfaces. Used without argument, it provides information about network interfaces. But it also allows to modify the configuration. For example, to change a mac address, use the command ifconfig $INTERFACE ether $MAC. So to change the mac address of the ethernet card, it will usually be ifconfig eth0 ether 5E:FF:56:A2:AF:15. Note however that this command, although still functional, is deprecated in favor of the command ipbelow.
ip
This command displays and manipulates routing and interfaces. It is often used to link or remove an ip to an interface:

<span class="com"># List all addresses</span><span class="pln">
Ip addr

</span><span class="com"># Only list information ipv6 </span><span class="pln">
ip </span><span class="pun">- </span><span class="lit">6 </span><span class="pln">addr

</span><span class="com"># List a particular interface</span><span class="pln">
Ip addr show dev em2

</span><span class="com"># Add an ipv4 </span><span class="pln">
ip </span><span class="com">address </span><span class="pln">addr add </span><span class="lit">192.168 </span><span class="pun">. </span><span class="lit">0.7 </span><span class="pln">dev eth0

</span><span class="com"># Delete an ipv4 </span><span class="pln">
ip addr </span><span class="kwd">del </span><span class="lit">192.168 </span><span class="pun">. </span><span class="lit">0.7 </span><span class="pln">dev eth0</span> 

<span class="com"># For the v6, use the argument -6 </span><span class="pln">
ip </span><span class="pun">- </span><span class="lit">6 </span><span class="pln">addr </span><span class="kwd">del </span><span class="lit">2574 </span><span class="pun">: </span><span class="lit">104 </span><span class="pun">:: </span><span class="pln">b08b </span><span class="pun">: </span><span class="pln">c107 dev eth0</span>
ping
Allows to ping a client to see if it is online or if it responds to ping, ex ping google.com. The option -callows to specify the number of pings to send before the command stops (it thus takes as an argument an integer example :), ping -c 8 google.comthe option -fallows to flood, that is to say that the network card will send As much ping as it is able to send per second.
traceroute
Traces the route of a packet, router by router, to its destination. You can use an ip or a domain name indifferently.

<span class="pln">Traceroute to google </span><span class="pun">. </span><span class="pln">com </span><span class="pun">( </span><span class="lit">173 194 </span><span class="pun">. </span><span class="lit">67113 </span><span class="pun">,) </span><span class="lit">64 </span><span class="pln">hops max </span><span class="pun">, </span><span class="lit">52 </span><span class="kwd">byte </span><span class="pln">packets
  </span><span class="lit">1 </span><span class="pln">  fast3504 </span><span class="pun">( </span><span class="lit">192.168 </span><span class="pun">. </span><span class="lit">1254 </span><span class="pun">) </span><span class="lit">12.108 </span><span class="pln">ms   </span><span class="lit">1.239 </span><span class="pln">ms   </span><span class="lit">1.217 </span><span class="pln">ms
  </span><span class="lit">2 </span><span class="pln">  sl869 </span><span class="pun">- </span><span class="pln">h01 </span><span class="pun">- </span><span class="lit">31 </span><span class="pun">- </span><span class="lit">38 </span><span class="pun">- </span><span class="lit">37 </span><span class="pun">- </span><span class="lit">254.dsl </span><span class="pun">. </span><span class="pln">Sta </span><span class="pun">. </span><span class="pln">Abo </span><span class="pun">. </span><span class="pln">Bbox </span><span class="pun">. com</span> <span class="pun">( </span><span class="lit">42.58 </span><span class="pun">. </span><span class="lit">37 254 </span><span class="pun">) </span><span class="lit">33 504 </span><span class="pln">ms   </span><span class="lit">32. </span><span class="pln">771 ms   </span><span class="lit">40.120 </span><span class="pln">ms
  </span><span class="lit">3 </span><span class="lit">173.la63.bsr01 </span><span class="pun">- </span><span class="pln">lyo </span><span class="pun">. </span><span class="pln">Net </span><span class="pun">. </span><span class="pln">Bbox </span><span class="pun">. com</span> <span class="pun">( </span><span class="lit">194,158 </span><span class="pun">. </span><span class="lit">110 189 </span><span class="pun">) </span><span class="lit">32 684 </span><span class="pln">ms   </span><span class="lit">31 828 </span><span class="pln">ms   </span><span class="lit">31 238 </span><span class="pln">ms
  </span><span class="lit">4 </span><span class="pln">  BE19 </span><span class="pun">. </span><span class="pln">Cbr01 </span><span class="pun">- </span><span class="pln">cro </span><span class="pun">. </span><span class="pln">Net </span><span class="pun">. </span><span class="pln">Bbox </span><span class="pun">. com</span> <span class="pun">( </span><span class="lit">212,194 </span><span class="pun">. </span><span class="lit">171.16 </span><span class="pun">) </span><span class="lit">41 761 </span><span class="pln">ms   </span><span class="lit">41 636 </span><span class="pln">ms   </span><span class="lit">40 140 </span><span class="pln">ms
  </span><span class="lit">5 </span><span class="pln">  be1 </span><span class="pun">. </span><span class="pln">Cbr01 </span><span class="pun">- </span><span class="pln">ntr </span><span class="pun">. </span><span class="pln">Net </span><span class="pun">. </span><span class="pln">Bbox </span><span class="pun">. com</span> <span class="pun">( </span><span class="lit">212 194 </span><span class="pun">. </span><span class="lit">171.1 </span><span class="pun">) </span><span class="lit">45.495 </span><span class="pln">ms   </span><span class="lit">42 217 </span><span class="pln">ms   </span><span class="lit">40 052 </span><span class="pln">ms
  </span><span class="lit">6 </span><span class="pun">* </span><span class="pun">* </span><span class="pun">*</span>
dig ndd
Check a match dns. You can directly specify the ip of the dns server to query, for example dig @8.8.8.8 wesharethis.com.

<span class="typ"><code>wesharethis</code> </span><span class="pun">: ~ Wesharethis</span><span class="typ"> $ </span><span class="pln">dig </span><span class="pun">@ </span><span class="lit">8.8 </span><span class="pun">. </span><span class="lit">8.8 Wesharethis</span> <span class="pun">. com</span> <span class="pun">; </span><span class="pun"><< >> </span><span class="typ">DiG </span><span class="lit">9.6 </span><span class="pun">- </span><span class="pln">ESV </span><span class="pun">- </span><span class="pln">R4 </span><span class="pun">- </span><span class="pln">P3 </span><span class="pun"><< >> </span><span class="pun">@ </span><span class="lit">8.8 </span><span class="pun">. </span><span class="lit">8.8 wesharethis.com</span> <span class="pun">; </span><span class="pun">( </span><span class="lit">1 </span><span class="pln">server found </span><span class="pun">) </span><span class="pun">;; </span><span class="kwd">Global </span><span class="pln">options </span><span class="pun">: </span><span class="pun">+ </span><span class="pln">cmd </span><span class="pun">;; </span><span class="typ">Got </span><span class="pln">answer </span><span class="pun">: </span><span class="pun">;; </span><span class="pun">- >> </span><span class="pln">HEADER </span><span class="pun"><< - </span><span class="pln">opcode </span><span class="pun">: </span><span class="pln">QUERY </span><span class="pun">, </span><span class="pln">status </span><span class="pun">: </span><span class="pln">NOERROR </span><span class="pun">, </span><span class="pln">id </span><span class="pun">: </span><span class="lit">2660 </span><span class="pun">;; </span><span class="pln">Flags </span><span class="pun">: </span><span class="pln">qr rd ra </span><span class="pun">; </span><span class="pln">QUERY </span><span class="pun">:</span> <span class="pun">;; </span><span class="pln">QUESTION SECTION </span><span class="pun">: </span><span class="pun">; Wesharethis</span> <span class="pun">. com</span> <span class="pun">. </span><span class="pln"> IN A</span> <span class="pun">;; </span><span class="pln">ANSWER SECTION </span><span class="pun">: </span><span class="pln"> wesharethis </span><span class="pun">. com</span> <span class="pun">. </span><span class="lit">43200 </span><span class="pln"> IN A </span><span class="lit">213.186 </span><span class="pun">. </span><span class="lit">33.4</span> <span class="pun">;; </span><span class="typ">Query </span><span class="pln">time </span><span class="pun">: </span><span class="lit">155 </span><span class="pln">msec </span><span class="pun">;; </span><span class="pln">SERVER </span><span class="pun">: </span><span class="lit">8.8 </span><span class="pun">. </span><span class="lit">8.8 </span><span class="com"># 53 (8.8.8.8) </span><span class="pun">; </span><span class="pln">WHEN </span><span class="pun">: </span><span class="typ">Fri </span><span class="typ">Jul </span><span class="lit">27 </span><span class="lit">09 </span><span class="pun">: </span><span class="lit">01 </span><span class="pun">: </span><span class="lit">06 </span><span class="lit">2017 </span><span class="pun">;; </span><span class="pln">MSG SIZE rcvd </span><span class="pun">: </span><span class="lit">42</span>
host
Allows to check the reverse. You enter an ip address and the command returns you the associated domain name.
nslookup
A bit in the same genre as dig, nslookupprovided info on the domain name passed in argument, ip address, DSN response type … Example:nslookup wesharethis.com .

<span class="typ">Wesharethis </span><span class="pun">: ~ Wesharethis</span><span class="typ"> $ </span><span class="pln">nslookup Wesharethis </span><span class="pun">. com</span>
 <span class="typ">Server </span><span class="pun">: </span><span class="lit">212.27 </span><span class="pun">. </span><span class="lit">40.240 </span><span class="typ">Address </span><span class="pun">: </span><span class="lit">212.27 </span><span class="pun">. </span><span class="lit">40.240 </span><span class="com"># 53</span> 		
	

<span class="typ">Non </span><span class="pun">- </span><span class="pln">authoritative answer </span><span class="pun">: </span><span class="typ">Name </span><span class="pun">: </span>	wesharethis <span class="pun">. </span><span class="pln">En
 </span><span class="typ">Address </span><span class="pun">: </span><span class="lit">213.186 </span><span class="pun">. </span><span class="lit">33.4</span>
route
This command of an unparalleled practicality allows you to view the roads, but also, by specifying a few arguments, to modify the roads. To add a default route: route add default addr ipand to remove a default route: route delete default.
arp -an
This command displays the current arp table. That is, the correspondence between ip and mac addresses on your network.
<a title="wesharethis – Nmap par l'exercice" href="https://wesharethis.com/2017/08/nmap-looking-wifi-squatters/">nmap</a>
nmapIs a tool that scans network and network ports of a machine to see which ones are open and detect any faults on the machines. It also detects machines connected to the network and much more. I made a small note on nmap, which remains a reference tool in the world of computer security.

netstat

This is a piece, and going around it would take (at least) an entire article. Anyway this command is very handy to get a glimpse of what’s going on on the network. We will therefore see directly some combinations of parameters that often come up.

-nr
For the routing table (returns to the same as route).
-i
Gives statistics on the various network interfaces.
-s
I personally use it very rarely, but it’s a summary of all the network stats, so it can be useful from time to time.
-uta
List all open connections ( ufor udp tfor tcp and ato display all connections (all)), you have to play with the parameters to filter all that!
-nap
Alternative to -uta(easier to remember for its meaning anglosaxone), this command gives a result that I find more readable. It displays all the connections ( a) with addresses in numeric format ( n) and gives the corresponding PID ( p).
-peanuts
In the easy-to-remember genre, we have here the combination of good arguments! It will give a slightly more detailed result than -napit adds UDP and TCP with detail ( -efor extended) and statistics ( -s) for all connections.
-ltupn
Still a variant that allows us to view all the services that are listening on ports (so all connections open). All connections tcp -tand udp -u, tuned -lwith the corresponding programs -pand incidentally we ask not to resolve the protocol name with -n.
-l
Allows to display all the listening connections (listen), one will have netstat -ltfor all the tcp conexions in listening.
-n
Can also be useful because it can display addresses in digital format instead of attempting to determine the symbolic host, port, or user name.
-p
Displays the name and PID of the processes that own the connections.

netstatIs the history command to list the connections. However, it has been depreciated in favor of sswhich is more modern and more efficient, especially in the presence of many connections. Most options are the same, so you will not be lost. If necessary, a small stroke man sscan not hurt.

Specific to OSX

We move away a bit from our original subject, but we are still in the useful commands to know in a terminal. 3/4 of the time, the linux commands run under mac, but the Apple OS has a few commands that are unique to it. Some are very practical, so I list here the one I already had the opportunity to use.

ipconfig
ipconfig getpacket interfaceGives information about the ip configuration, such as ip address, dns server ip, subdomain mask, dhcp message … Other commands exist with ipconfig, butgetpacket in my opinion is the most interesting, I will not speak So here not others. A small example:

<span class="typ">Wesharethis </span><span class="pun">:</span> <span class="typ"> Wesharethis $ </span><span class="pln">ipconfig getpacket en1
op </span><span class="pun"> = </span><span class="pln">BOOTREPLY
Htype </span><span class="pun">= </span><span class="lit">1 </span><span class="pln">
flags </span><span class="pun">= </span><span class="lit">0 </span><span class="pln">
hlen </span><span class="pun">= </span><span class="lit">6 </span><span class="pln">
hops </span><span class="pun">= </span><span class="lit">0 </span><span class="pln">
xid </span><span class="pun">= </span><span class="lit">3667777839 </span><span class="pln">
secs </span><span class="pun">= </span><span class="lit">0 </span><span class="pln">
ciaddr </span><span class="pun">= </span><span class="lit">0.0 </span><span class="pun">. </span><span class="lit">0.0 </span><span class="pln">
yiaddr </span><span class="pun">= </span><span class="lit">192.168 </span><span class="pun">. </span><span class="lit">0.1 </span><span class="pln">
siaddr </span><span class="pun">= </span><span class="lit">0.0 </span><span class="pun">. </span><span class="lit">0.0 </span><span class="pln">
giaddr </span><span class="pun">= </span><span class="lit">0.0 </span><span class="pun">. </span><span class="lit">0.0 </span><span class="pln">
chaddr </span><span class="pun">= </span><span class="lit">5E </span><span class="pun">: </span><span class="pln">FF </span><span class="pun">: </span><span class="lit">56 </span><span class="pun">: </span><span class="pln">A2 </span><span class="pun">: </span><span class="pln">AF </span><span class="pun">: </span><span class="lit">15 </span><span class="pln">
sname </span><span class="pun">= </span><span class="pln"> 
file </span><span class="pun">= </span><span class="pln"> 
options </span><span class="pun">: </span><span class="typ">Options </span><span class="pln">count </span><span class="kwd">is </span><span class="lit">7 </span><span class="pln">
dhcp_message_type </span><span class="pun">( </span><span class="pln">uint8 </span><span class="pun">): </span><span class="pln">ACK </span><span class="lit">0x5 </span><span class="pln">
server_identifier </span><span class="pun">( </span><span class="pln">ip </span><span class="pun">): </span><span class="lit">192.168 </span><span class="pun">. </span><span class="lit">0254 </span><span class="pln">
lease_time </span><span class="pun">( </span><span class="pln">uint32 </span><span class="pun">) </span><span class="lit">0xd2f00 </span><span class="pln">
subnet_mask </span><span class="pun">( </span><span class="pln">IP </span><span class="pun">): </span><span class="lit">255.255 </span><span class="pun">. </span><span class="lit">255.0 </span><span class="pln">
router </span><span class="pun">( </span><span class="pln">ip_mult </span><span class="pun">): </span><span class="pun">{ </span><span class="lit">192.168 </span><span class="pun">. </span><span class="lit">0.254 </span><span class="pun">} </span><span class="pln">
domain_name_server </span><span class="pun">( </span><span class="pln">ip_mult </span><span class="pun">): </span><span class="pun">{ </span><span class="lit">212.27 </span><span class="pun">. </span><span class="lit">40.241 </span><span class="pun">, </span><span class="lit">212.27 </span><span class="pun">. </span><span class="lit">40.</span>           
       
networksetup
As the name suggests, networksetupallows you to configure the OSX network aspect. The order is very very complete. DNS config example is obtained like this: networksetup getdnsservers ethernet | airport. Similarly, to configure DNS networksetup setdnsservers ethernet | airport dns1 [dns2].
Author

Am a tech geek.. Do you wanna know more about me..? My contents will do tell you.

Pin It