fbpx

Searching a text in a file using grep

Here we’re going to searching a text in a file using grep?

Searching a text in a file using grep, this command will be very much handy when searching in multiple files or folders in unix terminal.

grep is one of the powerful command used for searching in files or folder with the search pattern.

Searching for text in file using grep

Lets see how to search for text or string in files or folders using grep command

Command Usage:
grep [options] "search pattern"[regex] [filename/foldername]
Note: use double quotes for your search string

Options : (Below are frequently used options with grep command)
-i Ignores case
-n Print the line number
-c Count of matched pattern (Will not print the search line, rather it just prints the count)
-r Will search folders for matching text.
-v non-matched lines are printed

Try for yourself:

1) Search for any string and print count
hint: use -c
2) Search entire folder for match pattern with , (This is special symbol)
hint: “\,”
3) Search string by ignoring the case and also search for multiple string in a file
hint: use -v and in search string you need to split using | for multiple search string.

Try for yourself and comment it here https://youtu.be/9pUPUEvJop8

practice to keep FAMILIAR with the commands.

Subscribe to our channel for more videos : https://bit.ly/aryanz-youtube

https://youtu.be/9pUPUEvJop8
Searching a text in a file using grep
~3Minutes: Tutorial

All about Permissions (CHOWN) in Unix – 3Minutes: Tutorial

Here we’re going to talk all about Permissions (CHOWN) in Unix?

When it comes to access for reading,writing or executing files in unix we need to play around with the permissions! So today we are going to talk all about ownership and permissions (chown).

Ownership and Permissions are important thing in unix, when it comes to files and folders access.

Changing ownership of files and folders using chown in unix - ~3Minutes:... youtu.be/Q3Mm4Lzeiyk via @YouTube #3MinTut #3MinutesTutorial #ShortTechTalk #LearningShort #unix #chown permissions and security #aryanz_co_in #balamtin #blog

Changing ownership for files and folders using CHOWN

Command Usage:
chown user:group filename (Changing ownership for user and group)
chown :group filename (Only to the group)
chown user filename (Only the user)
chown user:group foldername -R (For folders and sub directory use -R)
Note: -R to apply the changes to the sub directories and files within the folder.

owner – User who created the file or folder
group – User belong to the group
(groups example: admin, author, sysadmin, root, local, itadmin) – varies from system to system

Try for yourself:
1) Change both owner and group from root to user1 or user1 to root
hint: chown root:root file1.txt
2) Try to change for folder and its sub content (incl. sub directories)
chown root:aryanz_co_in folder1 -R

Try for yourself and comment it here https://youtu.be/Q3Mm4Lzeiyk

practice to keep FAMILIAR with the commands.

Subscribe to our channel for more videos : https://bit.ly/aryanz-youtube

https://youtu.be/Q3Mm4Lzeiyk
Changing ownership of files and folders using chown in unix - ~3Minutes:... youtu.be/Q3Mm4Lzeiyk via @YouTube #3MinTut #3MinutesTutorial #ShortTechTalk #LearningShort #unix #chown permissions and security #aryanz_co_in #balamtin #blog
~3Minutes: Tutorial

All about Permissions in Unix terminal

Here we’re going to talk all about Permissions in Unix terminal?

When it comes to reading, writing or executing files in unix we need to play around with the permissions! So today we are going to talk all about permissions in unix terminal (chmod).

Permissions are important thing in unix, when it comes to files and folders access.

How to change directory permissions in Linux

To change directory permissions in Linux, use the following:

chmod +rwx filename to add permissions.
chmod -rwx directoryname to remove permissions.
chmod +x filename to allow executable permissions.
chmod -wx filename to take out write and executable permissions.

Note that “r” is for read, “w” is for write, and “x” is for execute. 

This only changes the permissions for the owner of the file.

The 4 unix permissions categories (read, write and execute)

How to Change Permissions in Numeric Code in Linux – Watch it in below video

You may need to know how to change permissions in numeric code in Linux, so to do this you use numbers instead of “r”, “w”, or “x”.

  • 0 = No Permission
  • 1 = Execute
  • 2 = Write
  • 4 = Read

Basically, you add up the numbers depending on the level of permission you want to give.

example of changing permissions in numeric code in Linux

Permission numbers are:

  • 0 = —
  • 1 = –x
  • 2 = -w-
  • 3 = -wx
  • 4 = r-
  • 5 = r-x
  • 6 = rw-
  • 7 = rwx

For example:

chmod 777 foldername will give read, write, and execute permissions for everyone.

chmod 700 foldername will give read, write, and execute permissions for the user only.

chmod 327 foldername will give write and execute (3) permission for the user, w (2) for the group, and read, write, and execute for the users.

How to Change Directory Permissions in Linux for the Group Owners and Others

The command for changing directory permissions for group owners is similar, but add a “g” for group or “o” for users and “u” for owners:

chmod g+w filename
chmod g-rw filename
chmod o+w filename
chmod o-rwx foldername
example of how to change directory permissions in Linux for group owners and others

To change directory permissions for everyone, use “u” for owners, “g” for group, “o” for users, and “ugo” or “a” (for all).

  • chmod ugo+rwx foldername to give read, write, and execute to everyone.
  • chmod a=r foldername to give only read permission for everyone.

As you can see, there are several options when it comes to permissions. You have the capability to dictate usability among users. While it may be easier to just give all permission to everyone, it may end up biting you in the end. So choose wisely.

https://youtu.be/5n-a1NQXMus
All about Permissions in Unix terminal
~3Minutes: Tutorial

Learn to write your first shell script

Learn to write your first shell script

Learn to write your first shell script to print “Helloworld”?

Come lets Learn to write your first shell script will be the baby step for learning shell programming.

Any programming language or script it be, start it with “Hello world”.

Why start with Hello world?

Writing your first program to print “Hello world”, will allow you to learn the basic setup of the environment, configurations, and more.

https://youtu.be/yxmI8pS2wN0

hello_world.sh

#!/bin/bash
echo "Hello world"

Save the file, then to run open the terminal, and type ./hello_world.sh

PS: You might get permission denied error, due to hello_world.sh file not having execute permission for any users.

Use “chmod +x hello_world.sh” to provide execute permission.

This first line (#!/bin/bash or #!/bin/sh) has a name. It is known as ‘she-bang‘ (shabang). This derives from the concatenation of the tokens sharp (#) and bang (!).

It is also called as sh-bang, hash-bang, pound-bang or hash-pling. In computing, a she-bang is the character sequence consisting of the characters number sign and exclamation mark (#!) at the beginning of a script.
Learn to write your first shell script
~3Minutes: Tutorial

Check disk usage in unix terminal?

How to check disk usage in unix terminal?

Here is how you can check disk usage in unix terminal.

Disk usage is a critical thing in servers, Certain times the web service or server acts weird and it could be disk space being full.

In order to check the disk space we can use “df” command in unix. which will show us the disk/file system, used and available disk quantity. also the mount location of the disk.

We have discussed below listed commands

  1. df – disk usage checking
  2. man – man is nothing but manual, by passing the command as parameter to this command will open the manual for the command in parameter.
https://youtu.be/kqVzUOZMSY0

df command

[email protected]:~$ df -h
df: /run/user/1001/doc: Operation not permitted
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           1.6G  2.1M  1.6G   1% /run
/dev/sda2       723G  111G  575G  17% /
tmpfs           7.8G   87M  7.7G   2% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           4.0M     0  4.0M   0% /sys/fs/cgroup
/dev/sda1       1.5G  199M  1.3G  14% /boot/efi
Check disk usage in unix?
~3Minutes: Tutorial

Check the port used by any process in unix?

Check the port used by any process in unix?

Here we are going to see how to Check the port used by any process in unix?

Check the port used by any process in unix?

Here is how you can check port used by any process in unix terminal.

While developing any webservice or web server you might end up using existing port number and will face issue while starting the server

Before such thing happens, better to check the port is being used by any process already to avoid such conflicts. Its saves us more time.

We have discussed below listed commands

  1. netstat – network utility used for checking the connection of TCP/UDP
  2. ss – Socket statistics, similar to netstat but faster.
  3. sudo – Run any command with root or super user level/mode.
https://youtu.be/kqVzUOZMSY0

netstat command

[email protected]:~/dev/folder1$ sudo netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:33060         0.0.0.0:*               LISTEN      5314/mysqld         
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      5314/mysqld         
udp        0      0 127.0.0.53:53           0.0.0.0:*                           4434/systemd-resolv

ss command

[email protected]:~/dev/folder1$ sudo ss -tulpn
Netid           State            Recv-Q           Send-Q                     Local Address:Port                       Peer Address:Port           Process                                                                                                                                           
udp             UNCONN           0                0                          127.0.0.53%lo:53                              0.0.0.0:*               users:(("systemd-resolve",pid=4434,fd=12))                                                                                                                                                                                                           
tcp             LISTEN           0                70                             127.0.0.1:33060                           0.0.0.0:*               users:(("mysqld",pid=5314,fd=32))                                                                                                                
tcp             LISTEN           0                151                            127.0.0.1:3306                            0.0.0.0:*               users:(("mysqld",pid=5314,fd=34))                                                                                                                                                                                  
Check the port used by any process in unix? - 3Minutes: Tutorial
~3Minutes: Tutorial