Found 2065 Articles for Operating System

How to run a crontab job every week on Sunday?

Mukul Latiyan
Updated on 30-Jul-2021 09:11:47

596 Views

In order to create a crontab job to run every Sunday, we first need to explore and understand what a crontab job is.A crontab is nothing but a list of commands that we can run during a cron job. A cron job is a utility that schedules automatic execution of commands at specific times.We can start a cron job with the help of bash script by following the commands shown below −crontab -eThis will open a file which you can edit, insert the cron job shell script in the above file and then close that file.Just insert the code shown ... Read More

How to resume a partially transferred file over ssh on Linux?

Mukul Latiyan
Updated on 30-Jul-2021 09:10:50

677 Views

There is always a scenario where we sometimes encounter the transfer of files to be broken because of some reason. The reasons could be different, unless it is not that you explicitly closed the particular connection or process, it can be recovered.It should also be noted that the scp command doesn’t have a resume option, and the only option is to simply start copying the files from the beginning and overwrite the existing files. The process of doing this again and again because of the ssh disconnection can be very annoying and time consuming.Linux does provide us with a command ... Read More

How to replace spaces in file names using bash script on Linux?

Mukul Latiyan
Updated on 30-Jul-2021 09:09:51

434 Views

Consider a case in which one directory on my local machine looks something like this −immukul@192 dir1 % ls -ltr total 0 -rw-r--r-- 1 immukul staff 0 Jul 3 20:44 sample code.txt -rw-r--r-- 1 immukul staff 0 Jul 3 20:44 sample code with love.txtIn the above directory named dir1, there are two .txt files present and both these files have spaces in between the words in their name, and we need to replace these spaces using a bash script on Linux.In order to achieve what we want, we must first be aware of the fact that we can traverse the ... Read More

How to quickly sum all the numbers in a file on Linux?

Mukul Latiyan
Updated on 30-Jul-2021 09:08:55

5K+ Views

Consider that we have a file named bar that contains different numbers inside it. The bar file looks something like thisimmukul@192 linux-questions-code % cat bar 11 12 13We need to get the sum of all the numbers present in the above file.There are plenty of approaches and solutions that we can consider that involve different commands and keywords. Let’s consider some of these possible solutions one by one.The most basic approach is to open the file and read the contents and then calculate the sum of all the numbers by making use of the do while loop.Bash Scriptsum=0 while read ... Read More

How to prevent a background process from being stopped after closing SSH client in Linux?

Mukul Latiyan
Updated on 30-Jul-2021 09:06:58

775 Views

A background process in Linux is a process that is running independently of the shell. It provides us the privilege to leave the terminal window, and it will still be executing in the background without any interaction from the users.Nginx and Apache web servers are the most common examples of the background processes that are used to serve images and dynamic content.In Linux, we can start a process in the background by just appending the symbol &  after it.Consider the example shown below −sleep 10000 &In the above command, we make use of the sleep statement that will run for ... Read More

How to preserve colouring after piping grep to grep in Linux?

Mukul Latiyan
Updated on 30-Jul-2021 09:05:57

183 Views

In order to be able to preserve colouring after using the pipe in between the grep togrep command, we must first be aware of what the 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 file is referred to as the regular expression.Syntaxgrep [options] pattern [files]While there ... Read More

How to perform grep operation on all files in a directory?

Mukul Latiyan
Updated on 30-Jul-2021 09:04:32

2K+ 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 match two strings that are present in one line with grep in Linux?

Mukul Latiyan
Updated on 30-Jul-2021 09:03:21

900 Views

In order to be able to grep two strings that exists on the same line in Linux command line, we must first 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 file is referred to as the regular expression.Syntaxgrep [options] pattern [files]While there are ... Read More

How to list running screen sessions on Linux?

Mukul Latiyan
Updated on 30-Jul-2021 09:02:15

2K+ Views

Screen or sometimes also known as GNU Screen, is a terminal multiplexer. What it means is that it allows you the privilege to start a screen session and then open any number of windows inside that session.It might also be interesting to note that a process that is running in Screen will continue to run even when their window is not visible anymore.Installing Linux ScreenIn order to install the screen package if it is not already present on your Linux distribution, you can run any of the suitable commands shown below for your machine.For Ubuntu and Debiansudo apt update sudo ... Read More

How to list down all the available commands and aliases on Linux?

Mukul Latiyan
Updated on 30-Jul-2021 09:01:18

9K+ Views

Linux provides us with a huge amount of commands along with their aliases that we can make use of. Although these commands serve different purposes we can still make use of all these commands anywhere we like in the terminal.There are different ways with which we can interact with Linux commands. When it comes to listing all the available commands to the terminal we also have different approaches, either we can write a shell script by ourselves or we can use a shell library function that does that for us.Let’s consider the first approaches where I'll make use of a ... Read More

Advertisements