Introduction to Linux

If you like it, share it

Linux is a Unix-like computer operating system assembled under the model of free and open-source software development and distribution.
The defining component of Linux is the Linux kernel an operating system kernel first released on September 17, 1991 by Linus Torvalds.

Up to now there is a loot of version of Linux.
Only for give you some names, there are: UBUNTU, MANDRIVIA, FEDORA, openSUSE, DEBIAN, etc.

To choose what Linux to use on your PC, is important read the characteristics of each one.
There are “basic” Linux that work on the old PC because request few resource (RAM and HD).
Also there are some Linux with an advanced graphics interface that request a modern PC.

Different prompt depending on whether you are referring to a command given by a normal user or by the administrator.
The dollar $ represents an action of a normal user, while the # symbol represents an action of the root user.

The most important Linux commands are summarized below
I remember you that the command below must be used in the Linux Console, is similar to the old DOS commands, but much higher performance

  • Release of LINUX in use
    uname -a
    uname -r

  • What is the Name of LINUX that you use
    cat /etc/issue
    lsb_release -a

  • Superuser mode
    sometime is necessary use the command: sudo su

  • Disk space
    df -h -T
    It tells us the disk space (or SD on embedded systems) and the usage of it.

  • Size of the RAM
    free -m
    It tell us the size of the RAM and the usage of it.

  • PC HW version
    inxi -Fi
    cat /proc/cpuinfo
    or for complete HW
    lshw | more
    hwinfo | more
    hwinfo –short | more
    For more info see here (in Italian language)

  • Show the USB device connected to your PC

  • Name of the Ethernet controller
    ifconfig -a
    The n.1 is the name of the Ethernet controller (enx00e04c681519).
    This strange name is because on the PC tested we use an external USB to Ethernet controller.
    Normally if the Internet controller is in the PC the name will be: eth0, eth1, etc.
    The n.2 is the name of the WiFi – Wireless Ethernet controller (wlp1s0).
  • MTU – Maximum Transmission Unit is reported in the point n.2 of the image before. MTU is important for avoid the packet fragmentation, see here.

  • Active process in real time
    For exit press: ctrl + C

  • Active process and the relative PID
    ps aux
    ps -ef | grep python
    It tell us the active PYTHON process.
    Below an example, in the red box there are the PID numbers.

  • Terminate the active process
    kill <process_number (Num.PID)>

    If the process is not generated by you, for kill it use the command:
    sudo kill Num.PID
    If the process is hard to terminate, use the command:
    sudo kill -9 Num.PID

  • Show the tree process

  • Show the contents of the directory where you are
    ls -l
    ls -alp
    It similar to ls -l but plus it show the hide files.

    Examples of ls -l

    0123456789 A B       C      D     E           F
    drwxrwxr-x 2 enrico enrico 4096   gen 6 2013 CNC
    -rw-rw-r– 1 enrico enrico 307018 set 22 00:07 C:\nppdf32Log\debuglog.txt

    From left to right, below, the explanation of the result.
    owner – fields 1, 2 and 3
    users – fields 4, 5 and 6
    other users – field 7, 8 and 9
    0) it tell us if is a file or a directory (d)
    1…9) it tell us the permission and means:
    r reading
    w writing
    x execution
    not assigned

    The permission are groupped for:
    1,2,3) permissions assigned to the owner
    4,5,6) permissions assigned to the group
    7,8,9) permissions assigned to all the users

    A) indicates the number of connections to the component while for folders indicates the number of extra blocks.
    B) it is the name of the owner of the file or the directory.
    C) is the group membership
    D) dimensions
    E) date and time of creation or last modification

  • Change the permission on file
    In the example below we gave all, all permissions.
    chmod a=rwx <file_name>

    a = all
    u = owner
    g = group
    o = other user

    r = read
    w = write
    x = execution

    chmod -R <permission> <directory>

    It is used to change the directory permission and also the permission on all the files that are in the directory.
    The example below gives to all, all permissions:
    chmod -R 777 <directory>

  • Change the proprietary of the file
    chown <owner or group> <file_name>

  • Copy file
    cp <source_file> <destination_file>

  • Copy directory
    cp -R <source_directory> <destination_directory>

  • Delete the file
    rm <file_name>

  • Delete the directory
    rm -r <directory_name>

  • Move file or directory
    mv <name1> <name2>
    <name1> <name2> is file or directory, it is possible that before use this command is necessary login as super user: sudo mv <name1> <name2>

  • Display text files, copy, etc.
    Display text files on screen.
    Copy text files.
    Combine text files.
    Create new text files.
    To display text file use the command: cat <file_name>

  • Scheduler
    This is a scheduler that allows you to run commands at scheduled times or to repeat it with fixed intervals.
    See here:
    and here.
    To see my example look here.

  • Nano editor
    nano <file_name>
    It allows us to modify the specified file using the nano editor.

  • Install the packages
    sudo apt-get install <package>
    It is used to install the packages.
    sudo apt-get install gedit
    Install gedit

  • What package are installed in your distribution of linux ?
    dpkg -l

  • Remove the packages
    sudo apt-get remove <package>

  • Similar to apt-get  remove, but also remove the configuration files related to the package.
    sudo apt-get purge <package>

  • Update the packages
    sudo apt-get update
    It allows us to update the packages in our system.
    If a package requires the installation or removal of new dependencies the package will not be updated by the update command.
    To effect these changes will also have to use upgrade command (see below).

  • Upgrading new packages that require installation or removal of new dependencies.
    sudo apt-get upgrade
    It ‘a good idea to give commands in the sequence show below:
    sudo apt-get update
    and then
    sudo apt-get upgrade

  • Removes the files are no longer used in our system
    sudo apt-get clean
    sudo apt-get autoremove

  • Find a packages that contain the specified word
    sudo apt-cache search <word>

  • Show the information regarding the package
    sudo apt-cache show <package>

  • Show the dependencies that are necessary for a package
    sudo apt-cache depends <package>

  • Show the version, the reverse depends and the dependencies of a package
    sudo apt-cache showpkg <package>
    sudo apt-cache showpkg nano
    Package: nano
    2.2.6-1 (/var/lib/apt/lists/mirrordirector.raspbian.org_raspbian_dists_wheezy_main_binary-armhf_Packages) (/var/lib/dpkg/status)
    Description Language:
    File: /var/lib/apt/lists/mirrordirector.raspbian.org_raspbian_dists_wheezy_main_binary-armhf_Packages
    MD5: b7e1d8c3d831118724cfe8ea3996b595

    Reverse Depends:

    2.2.6-1 – libc6 (2 2.4) libncursesw5 (2 5.6+20070908) libtinfo5 (0 (null)) dpkg (18 1.15.4) install-info (0 (null)) spell (0 (null)) pico (0 (null)) alpine-pico (1 2.00+dfsg-5) pico (0 (null))
    2.2.6-1 – editor
    Reverse Provides:

  • Show the Internet interface
    It is used to show the Internet interface, the WiFi interface is wlan0.
    pi@rpi1 ~ $ ifconfig
    eth0   Link encap:Ethernet  HWaddr b8:27:eb:8c:eb:ac
              UP BROADCAST MULTICAST  MTU:1500  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

    lo        Link encap:Local Loopback
              inet addr:  Mask:
              UP LOOPBACK RUNNING  MTU:65536  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

    wlan0     Link encap:Ethernet  HWaddr 08:10:77:bc:17:d5
              inet addr:  Bcast:  Mask:
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:2572 errors:0 dropped:5 overruns:0 frame:0
              TX packets:345 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:273360 (266.9 KiB)  TX bytes:56323 (55.0 KiB)

  • iwconfig command is similar to ifconfig command, but is dedicated to the Linux wireless interfaces
    pi@rpi1 ~ $ iwconfig
    wlan0     IEEE 802.11bg  ESSID:”Vodafone-26666521″  Nickname:”<WIFI@REALTEK>”
              Mode:Managed  Frequency:2.437 GHz  Access Point: 00:24:89:C5:FB:38  
              Bit Rate:54 Mb/s   Sensitivity:0/0
              Retry:off   RTS thr:off   Fragment thr:off
              Power Management:off
              Link Quality=100/100  Signal level=100/100  Noise level=0/100
              Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
              Tx excessive retries:0  Invalid misc:0   Missed beacon:0

    lo        no wireless extensions.

    eth0      no wireless extensions.

  • See link quality continuously on screen
    cat /proc/net/wireless
    watch -n 1 cat /proc/net/wireless

  • For find the IP of the PC, or of the SmartPhone, or of the RaspBerry Pi, etc, connected to your LAN network, open a terminal (on a PC) and use the command:
    If nmap is not present on your PC, instal it using this command:
    sudo apt-get install nmap
    nmap -sP
    obviously change the:
    and use the IP address for your Access Point or Router.
    You receive an answer from the nmap command, similar to the image below.
    Starting Nmap 5.21 ( ) at 2013-12-27 01:53 CET
    Nmap scan report for vodafone.station (
    Host is up (0.00094s latency).
    Nmap scan report for fritz.repeater.station (
    Host is up (0.015s latency).
    Nmap scan report for rpi1.station (
    Host is up (0.0014s latency).
    Nmap scan report for enricohp.station (
    Host is up (0.0026s latency).
    Nmap scan report for enrico-MM061.station (
    Host is up (0.00028s latency).
    Nmap scan report for DCS-930L-DestroCortile.station (
    Host is up (0.0017s latency).
    Nmap scan report for DCS-930L-Pedonale.station (
    Host is up (0.0016s latency).
    Nmap scan report for DCS-930L-SinistroCortile.station (
    Host is up (0.0023s latency).
    Nmap done: 255 IP addresses (8 hosts up) scanned in 3.33 seconds

    • If you need to know the ports open on an IP address use the syntax below:
      nmap -p0-5000
      of course, change the:
      with an appropriate IP address that you find in your IP Network
      The: 0-5000
      is the port range that in the example I scanned.

    • Scanning Operating system on target IP, use the command below:
      sudo nmap -O
      of course, change the:
      with an appropriate IP address that you find in your IP Network

    • For more detail concerning the use of nmap see the link below.

  • Convert package from RPM to DEB and vice versaFor do the conversion is necessary use alien.
    If alien is not present on your distribution install it by this command:
    sudo aptitude install alien

    Convert file from RPM to DEB
    sudo alien <package.rpm>
    –Convert file from DEB to RPM
    sudo alien -r <package.deb>

  • Redirection of standard input
    Sometime is userful redirect the standard input from a file or peripherals, for do this the general syntax is:
    “command” < “file of peripherals or that you want”
    for example:
    sort < list.txt
    Displays the contents of the list.txt file after reordering it.

  • Standard output redirection
    Sometime is userful redirect the output of a command in a file, for do this the general syntax is:
    “command” > “file of peripherals or that you want”
    for example:
    ls -alp > list.txt
    send the result of ls -alp command in a file named list.txt
    If you need do again the same command but update in the same file the results, use the double >>, see the example below
    ls -alp >> list.txt

  • Redirect the output of a command in input to another command (Pipeline)
    The general syntax is below:
    “programma1” | “programma2”
    ls -alp | sort