How to make a shell script executable Linux CLI

This is a quick reference guide on how to make a shell script executable on Linux Based Operating Systems.

1. chmod +x

root@FTP:~# ./shell.sh
-bash: ./shell.sh: Permission denied
root@FTP:~# chmod +x shell.sh
root@FTP:~# ./shell.sh

If you are new to the world of Linux, an avid Linux enthusiast or a student why not try our 0.99p per month Linux VPS.

Simply click on the screen shot below to find out more or navigate to https://piggybank.cloud

Thank you for reading and please feel free to leave any feedback.

How to add a user to a group Linux CLI

This is a quick reference guide on how to check your network interfaces on Linux Based Operating Systems.

1. ifconfig -a

root@FTP1:~# addgroup ftpgroup user1
addgroup: The user `ftpgroup' does not exist.
root@FTP1:~# adduser user1 ftpgroup
Adding user `user1' to group `ftpgroup' ...
Adding user user1 to group ftpgroup
Done.
root@FTP1:~# adduser user2 ftpgroup
Adding user `user2' to group `ftpgroup' ...
Adding user user2 to group ftpgroup
Done.

If you are new to the world of Linux, an avid Linux enthusiast or a student why not try our 0.99p per month Linux VPS.

Simply click on the screen shot below to find out more or navigate to https://piggybank.cloud

Thank you for reading and please feel free to leave any feedback.

How to change group ownership of a file Linux CLI

This is a quick reference guide on how to change group ownership of a file on Linux Based Operating Systems.

1. Change group ownership of a file using chgrp command

[root@vps1 ~]# chgrp root file1
[root@vps1 ~]# ls -l file1
-rw-r--r-- 1 root root 0 Jun  4 11:06 file1
[root@vps1 ~]# chgrp vpsuser file1
[root@vps1 ~]# ls -l file1
-rw-r--r-- 1 root vpsuser 0 Jun  4 11:06 file1

2. Check the file permission using ls -l

root@vps:~# ls -l file1
-rwxr-x--x 1 root root 0 Jun  3 08:17 file1

A dash (-) indicates that the file is a regular file.

The letter (d) indicates that the file is a directory as per below:

A letter (l) preceding indicates a special file type called a symlink. A symlink is a pointer to another location in the file system.

drwxr-xr-x 3 root root       4096 Oct 18  2018 ufw

The first three letters above refer to the permission of the user so in this case rwx, so read, write, and execute.

The next three letters is for group r-x, so read and execute, but not write as indicated by the dash.

The next three letters is for other r-x, so read and execute, but not write as indicated by the dash. (so the same as group in this example)

The number 3 in this example after the permissions indicates the number of files or sub-directories contained within this particular directory.

The first name after the number (directory and file number) in the example below is the user or file owner. “vpsuser”

The second name refers to the files group. “group1”

-rwxr-x--x 1 vpsuser group1 0 Jun  3 08:17 file1
root@vps:~#

The remainder of the file details are the size of the file, the date and time that the file was created or last modified, and the file name.

If you are new to the world of Linux, an avid Linux enthusiast or a student why not try our 0.99p per month Linux VPS.

Simply click on the screen shot below to find out more or navigate to https://piggybank.cloud

Thank you for reading and please feel free to leave any feedback.

How to show interface statistics using netstat -i command Linux CLI

This is a quick reference on how to show interface statistics using the netstat -i command on Linux Based Operating Systems.

1. netstat -i

root@GNS3-Server:~# netstat -i
Kernel Interface table
Iface   MTU Met   RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
docker0    1500 0         0      0      0 0             0      0      0      0 BMU
eth0       1500 0       572      0      0 0           359      0      0      0 BMRU
eth1       1500 0        43      0      0 0            37      0      0      0 BMRU
lo        65536 0      3172      0      0 0          3172      0      0      0 LRU
tun1194    1500 0         0      0      0 0             0      0      0      0 MOPRU
virbr0     1500 0         0      0      0 0             0      0      0      0 BMU
root@GNS3-Server:~#

If you are new to the world of Linux, an avid Linux enthusiast or a student why not try our 0.99p per month Linux VPS.

Simply click on the screen shot below to find out more or navigate to https://piggybank.cloud

Thank you for reading and please feel free to leave any feedback.

How to show established tcp connections using the netstat command Linux CLI

This is a quick reference on how to show established tcp connections using the netstat command on Linux Based Operating Systems.

1. netstat

root@GNS3-Server:~# netstat
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 172.16.253.1:3080       172.16.253.1:43486      ESTABLISHED
tcp        0      0 172.16.253.1:43486      172.16.253.1:3080       ESTABLISHED
tcp        0      0 10.0.125.10:ssh         90.240.10.190:59675     ESTABLISHED

If you are new to the world of Linux, an avid Linux enthusiast or a student why not try our 0.99p per month Linux VPS.

Simply click on the screen shot below to find out more or navigate to https://piggybank.cloud

Thank you for reading and please feel free to leave any feedback.

How to check what ports are listening using the netstat -l command Linux CLI

This is a quick reference on how to check what ports are listening using the netstat – l command on Linux Based Operating Systems.

1. netstat -l

Proto refers to network protocol either tcp or udp, local address you will see the port that is currently listening and under state it will advise that the port is listening (LISTEN).

root@GNS3-Server:/tmp# netstat -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 *:3080                  *:*                     LISTEN
tcp        0      0 *:http                  *:*                     LISTEN
tcp        0      0 192.168.122.1:domain    *:*                     LISTEN
tcp        0      0 *:ssh                   *:*                     LISTEN
tcp        0      0 *:8003                  *:*                     LISTEN
tcp6       0      0 [::]:http               [::]:*                  LISTEN
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN

If you are new to the world of Linux, an avid Linux enthusiast or a student why not try our 0.99p per month Linux VPS.

Simply click on the screen shot below to find out more or navigate to https://piggybank.cloud

Thank you for reading and please feel free to leave any feedback.

How to view files and logs using the head command Linux CLI

This is a quick reference on how to view files and logs using the head command on Linux Based Operating Systems.

The head command is a good way to check the first part of a file or the first logs recorded in a log file.

1. head

Will print the first 10 lines of a file

root@VPS2:/var/log# head syslog
Jun  6 15:26:53 VPS2 systemd[1]: Stopped Network Service.
Jun  6 15:26:53 VPS2 systemd-udevd[376]: Network interface NamePolicy= disabled on kernel command line, ignoring.
Jun  6 15:26:53 VPS2 systemd[1]: Starting Network Service...
Jun  6 15:26:53 VPS2 systemd-networkd[2958]: eth1: Gained IPv6LL
Jun  6 15:26:53 VPS2 systemd-networkd[2958]: eth0: Gained IPv6LL
Jun  6 15:26:53 VPS2 systemd-networkd[2958]: Enumeration completed
Jun  6 15:26:53 VPS2 systemd[1]: Started Network Service.
Jun  6 15:26:53 VPS2 systemd-networkd[2958]: eth1: Link is not managed by us
Jun  6 15:26:53 VPS2 systemd-networkd[2958]: lo: Link is not managed by us
Jun  6 15:26:53 VPS2 systemd-networkd[2958]: eth0: Configured
root@VPS2:/var/log#

2. head -n

You can specify the number lines printed by using -n option.

root@VPS2:/var/log# head -n 5 syslog
Jun  6 15:26:53 VPS2 systemd-networkd[2958]: Enumeration completed
Jun  6 15:26:53 VPS2 systemd[1]: Started Network Service.
Jun  6 15:26:53 VPS2 systemd-networkd[2958]: eth1: Link is not managed by us
Jun  6 15:26:53 VPS2 systemd-networkd[2958]: lo: Link is not managed by us
Jun  6 15:26:53 VPS2 systemd-networkd[2958]: eth0: Configured

If you are new to the world of Linux, an avid Linux enthusiast or a student why not try our 0.99p per month Linux VPS.

Simply click on the screen shot below to find out more or navigate to https://piggybank.cloud

Thank you for reading and please feel free to leave any feedback.