Linux basic commands


Home Page


Below is a summary of the most widely used Linux commands.
In the final part I put references to the internet lists more comprehensive.




Release of LINUX in use

uname -a

or
uname -r

UP




What is the Name of LINUX that you use

cat /etc/issue
or
lsb_release -a

UP




su

By this command is possible enter in Super User mode, sometime is necessary use the command: sudo su
Dopo aver dato il comando su, ci verrą chiesta la password.
The indication that we are Super User is the characther: #
at the end of the prompt line.

example:
root@enrico-MM061:/home/enrico#

For exit from the super user mode use the command: exit


UP




df -h

It tells us the disk space (or SD on embedded systems) and the usage of it.


UP




free -m

It tell us the size of the RAM and the usage of it.


UP




top

It tell us the CPU usage and who using it.
For exit use the command: ctrl+c


UP



-

top
  
It tell us the active process in real time.
       For exit press: ctrl + C

ps aux

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







-
kill

It is used to 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


UP




pstree

It show the tree process.


UP




cat /proc/cpuinfo

It show the HW version


UP



lsusb

It show the USB device connected to your PC



UP



ls -l

It show the contents of the directory where you are.

ls -alp

It similar to ls -l but plus it show the iden 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.

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



UP




chmod

It is used to change the permission on files.
In the example below we gave all, all permissions.
chmod a=rwx <nome_file>


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>


UP




chown <owner or group> <file_name>

It is used to change the proprietary of the files


UP




cp <source_file> <destination_file>

It is used to copy file


UP




rm <file_name>

It is use to delete the file


UP



rm -r <directory_name>

It is use to delete the 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>


UP



cat

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>

UP


-
cron

This is a scheduler that allows you to run commands at scheduled times or to repeat it with fixed intervals.
See here:
http://en.wikipedia.org/wiki/Cron
and here.
To see my example look here.

UP




nano <file_name>

It allows us to modify the specified file using the nano editor.


UP




sudo apt-get install <package>

It is used to install the packages.
EXAMPLE:
sudo apt-get install gedit
Install gedit


sudo apt-get remove
<package>

       Remove the package and all dependencies not used from other packages.


sudo apt-get remove
<package>

       Remove all dependencies not more used from the package.


sudo apt-get purge
<package>

        Similar to apt-get  remove, but also remove the configuration files related to the package.


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).



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

sudo apt-get clean

        Removes the files are no longer used in our system.

sudo apt-get autoremove

        Removes files marked as no longer used

sudo apt-cache search <word>

        It is use for find a packages that contain the specified word

sudo apt-cache show <package>

       This command show the information regarding the package


sudo apt-cache depends
<package>

        This command show the packages that are necessary for a package.
       

sudo apt-cache showpkg <package>

        This command show the version, the reverse depens and the dependecies of a package
        Example:


pi@rpi1 ~/Utility/WiFi $ sudo apt-cache showpkg nano
Package: nano
Versions:
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:
  junior-writing,nano

Dependencies:
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))
Provides:
2.2.6-1 - editor
Reverse Provides:
pi@rpi1 ~/Utility/WiFi $

UP



Manage your WiFi / Network

ifconfig

It is used to show the Internet interface, the WiFi interface si wlan0.
exampe:

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:127.0.0.1  Mask:255.0.0.0
          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:192.168.1.3  Bcast:192.168.1.255  Mask:255.255.255.0
          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

iwconfig command is similar to ifconfig command, but is dedicated to the Linux wireless interfaces.
It is used to manipulate the basic wireless parameters such as ssid, mode, channel, bit rates, encryption key, power and much more.

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.

cat /proc/net/wireless
watch -n 1 cat /proc/net/wireless

See link quality continuously on screen

Wavemon WiFi monitor

sudo apt-get install wavemon
sudo wavemon
wavemon is a monitoring application for wireless network devices

iwlist wlan0 scan

show all informations regarding the WiFi

UP



gparted

It is an utility use to manage the HD, SD card and USB card.
If your system is not installed, you can install it using the command:

        sudo apt-get install gparted

For run it use the command: gparted

LINK:


UP




nmap

If nmap is not present on your PC, instal it using this command:
sudo apt-get install nmap

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:

nmap -sP 192.168.1.1-255

obviously change the: 192.168.1.1
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 ( http://nmap.org ) at 2013-12-27 01:53 CET
Nmap scan report for vodafone.station (192.168.1.1)
Host is up (0.00094s latency).
Nmap scan report for fritz.repeater.station (192.168.1.4)
Host is up (0.015s latency).
Nmap scan report for rpi1.station (192.168.1.5)
Host is up (0.0014s latency).
Nmap scan report for enricohp.station (192.168.1.7)
Host is up (0.0026s latency).
Nmap scan report for enrico-MM061.station (192.168.1.9)
Host is up (0.00028s latency).
Nmap scan report for DCS-930L-DestroCortile.station (192.168.1.10)
Host is up (0.0017s latency).
Nmap scan report for DCS-930L-Pedonale.station (192.168.1.11)
Host is up (0.0016s latency).
Nmap scan report for DCS-930L-SinistroCortile.station (192.168.1.12)
Host is up (0.0023s latency).
Nmap done: 255 IP addresses (8 hosts up) scanned in 3.33 seconds

My RaspBerry Pi name is: rpi1.station and the IP is: 192.168.1.5


If you need to know the ports open on an IP address use the syntax below:

nmap 192.168.1.4 -p0-5000
of course, change the: 192.168.1.4
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 192.168.1.4
of course, change the: 192.168.1.4
with an appropriate IP address that you find in your IP Network


LINK:


UP




sensors


This is not a
command but LINUX application that is launched from a terminal and it tells the CPU temperature.

For install it use the command below:

sudo apt-get install lm-sensors

for run it use the command below:

sensors

ATTENTION: On RaspBerry Pi to know the temperature of the cpu see here.


UP




Serial terminal

I suggest CuteCom and MiniCom, they are available in your Software Center distribution.



UP





Convert package from RPM to DEB and vice versa

For 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>



UP






LINK




UP