Found 2065 Articles for Operating System

How to grep a string in a directory and all its subdirectories in Linux?

Mukul Latiyan
Updated on 30-Jul-2021 08:38:12

4K+ Views

The grep command in Linux is used to filter searches in a file for a particular pattern of characters. It is one of the most used Linux utility commands to display the lines that contain the pattern that we are trying to search.Normally, the pattern that we are trying to search in the file is referred to as the regular expression.Syntaxgrep [options] pattern [files]While there are plenty of different options available to us, some of the most used are −-c : It lists only a count of the lines that match a pattern -h : displays the matched lines only. ... Read More

How to get the start time of a long running Linux Process?

Mukul Latiyan
Updated on 30-Jul-2021 08:37:24

627 Views

Whenever we want to get an update about a specific process or different process we make use of the ps command which is short for “Process status” that tells us about the state of the current process and its characteristics and a whole lot more.When clubbed with several flags and commands we can enhance the ps command to output the start time of different processes that are running on a particular Linux machine.The command to print the time of long running processes in increasing order is shown below −For Ubuntu and other Linux based Systems −ps -eo pid , lstart ... Read More

How to get the last dirname/filename in a file path argument in Bash?

Mukul Latiyan
Updated on 30-Jul-2021 08:35:15

880 Views

We make use of the bash files to store different variables that we normally refer to as the environment variables. We can later access these variables easily by just printing them with the help of the echo utility command tha linux provides us with.ExamplePrint the $PATH environment variable.Commandecho $PATHOutputimmukul@192 src % echo $PATH /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin:/Us ers/immukul/.cargo/binNow as we can see that the PATH environment variable is made of different directories, and suppose we want the last file name from the path variable.In that case, we would make use of the base name command utility that Linux provides us with.The base name ... Read More

How to get only the file name using find command on Linux?

Mukul Latiyan
Updated on 30-Jul-2021 08:32:17

1K+ Views

Linux find statement is one of the most widely used statements that allows us to walk a file hierarchy. It is used to mostly find a specific file or directories and we can also append different other Linux statements or flags along with it to enhance or do a complex operation.Let’s explore an example of a find statement to understand it better.In the linux code shown below I am trying to search for a file inside my Downloads folder, and for that I am making use of the find statement.find sample.shOutputsample.shNotice that if the find command is able to locate ... Read More

How to get Linux console window width in Python?

Mukul Latiyan
Updated on 30-Jul-2021 08:31:23

316 Views

In order to get the width and height of the Linux console in Python, there are different modules available that we can make use of. Two of them are the os module and the subprocess module.In the case of the os module, we make use of the popen() method that is used to open a pipe to and from command which will help in retrieving the width and height of the Linux window.Consider the code for the same shown below −import os rowSize, columnSize = os.popen('stty size', 'r').read().split() print(rowSize) print(colSize)Save the above shown code in a file with a ... Read More

How to free Inode usage on Linux?

Mukul Latiyan
Updated on 29-Jul-2021 12:12:38

2K+ Views

The inode (also known as index node) is a data structure that is used to describe the file system object and is usually stored at the file system directory.We can check the size of the different inodes present on our local machine with the help of the following command −df -The above command is known as df command which is a Linux utility command that is used to get the details of the space available on the disk.After running the above command, you can expect an output something like this −immukul@192 ~ % df -i Filesystem 512-blocks Used Available Capacity ... Read More

How to find what group a given user has on Linux?

Mukul Latiyan
Updated on 29-Jul-2021 12:11:37

215 Views

We know that we can print all the users that are present on Linux with the help of the Linux utility command known as compgen.The compgen command is a Linux utility command that is used to list all the commands that can be executed in a Linux terminal, and when used with a -u flag we can simply print all the users present on Linux.Consider the command shown below as reference −compgen -uOutputroot daemon bin sys sync games man lp mail news uucp proxy www-data backup . . .Now if we want to print the total groups that are present ... Read More

How to find the most recent file in a directory on Linux?

Mukul Latiyan
Updated on 29-Jul-2021 12:09:37

2K+ Views

Linux find statement is one of the most widely used statements that allows us to walk a file hierarchy. It is used to mostly find a specific file or directories and we can also append different other Linux statements or flags along with it to enhance or do a complex operation.Let’s explore an example of a find statement to understand it better.In the linux code shown below I am trying to search for a file inside my Downloads folder, and for that I am making use of the find statement.find sample.shOutputsample.shNotice that if the find command is able to locate ... Read More

How to find out which processes are using swap space in Linux?

Mukul Latiyan
Updated on 29-Jul-2021 12:06:46

2K+ Views

Swap space is common in Linux, and it usually is used when the amount of the physical memory(RAM) is full. The idea behind the swap space is that if the operating system needs more memory resources and the RAM doesn’t have any space left, then the pages that are inactive will be moved to the swap space.It should also be noted that while swap space definitely helps out the RAM on a short basis, they should not be considered a replacement for more RAM.Now we know a bit about swap spaces, let’s talk about how we can detect which processes ... Read More

How to find out which process was killed by Linux OOM killer?

Mukul Latiyan
Updated on 29-Jul-2021 11:59:20

676 Views

In order to be able to find out which process was killed by linux OOM killer, we will make use of the grep command that Linux provides us with. But at first we need to understand what a grep command is and how to use it on Linux.The grep command in Linux is used to filter searches in a file for a particular pattern of characters. It is one of the most used Linux utility commands to display the lines that contain the pattern that we are trying to search.Normally, the pattern that we are trying to search in the ... Read More

Advertisements