Found 2065 Articles for Operating System

Is there a goto statement available in bash on Linux?

Mukul Latiyan
Updated on 31-Jul-2021 12:18:45

1K+ Views

Long story short, Linux’s bash doesn’t have goto statements and no information about the control structures exists in the official documentation. It should also be noted that we can make use of the break and continue statement to achieve the same behaviour that goto statement provides us.A simple behaviour of the goto can be achieved with a few tweaks and using the simple if condition in bash.The script will look something like this# ... Code You want to run here ... if false; then # ... Code You want to skip here ... fi # ... ... Read More

How would I get a cron job to run every 30 minutes on Linux?

Mukul Latiyan
Updated on 31-Jul-2021 12:15:22

780 Views

In order to create a crontab job to run every 30 minutes 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 ... Read More

How to write multiple line strings using Bash with variables on Linux?

Mukul Latiyan
Updated on 31-Jul-2021 12:04:57

3K+ Views

Setting a variable to a single line in bash and then printing it to console is a fairly easy process, but if we want to write multiple line strings using Bash then we have to consider different approaches.In total there are three approaches that we can make use of, all of these are mentioned below with examples.Multiline with We can make use of the symbol to make sure that whatever string we write has a newline in between them. With this approach we can write as many lines as possible, we just need to write the same number of ... Read More

How to use the sub process module with pipes on Linux?

Mukul Latiyan
Updated on 31-Jul-2021 12:04:07

304 Views

In Python, we have the subprocess module that allows us to work with additional processes and makes things easier for us as a developer. While there are other modules available to us that also provide similar functionalities as the subprocess module like the os.spawn(), os.system(), os.popen() and much more, but the reason the subprocess is recommended over all these modules is because of its offering of a high level interface than all the other similar modules mentioned above.In order to be able to use pipes along with the subprocess module we need to understand what the subprocess module does first.ExampleLet’s ... Read More

How to use the sed command to replace a text in files present in a directory and subdirectories?

Mukul Latiyan
Updated on 31-Jul-2021 12:03:34

662 Views

Let’s consider a case where we have two directories, say, d1 and d2 and both these directories contain some files, which may be the same or different. Now we want to make use of the sed command to replace a particular text that might be present in some of the files in either the d1 directory or the d2 directory.In order to do that, we must be familiar with the sed commands, as the sed commands can be used to solve the above problem.Let’s first explore the sed command, which is short for stream editor. This command is used to ... Read More

How to use the grep command to search for a string that has a dot in it?

Mukul Latiyan
Updated on 31-Jul-2021 12:03:01

528 Views

In order to be able to grep a string that has a dot inside it, 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 plenty of different options available ... Read More

How to use chmod recursively on Linux?

Mukul Latiyan
Updated on 02-Aug-2021 06:45:04

278 Views

You might have been in a scenario where you are using a Linux as your main operating system and then you try to create or edit a file and the Linux terminal responds with something like “Permission deny” error. In typical sense, such an error is related to insufficient permissions that your current user is having and can be solved by setting the correct file permissions or changing the owner.In Linux, the files are controlled through the file permissions, ownership and attributes, which in turn makes sure that only authorized users and processes can access files and directories.Before understanding how ... Read More

How to use a pipe with Linux find command?

Mukul Latiyan
Updated on 31-Jul-2021 11:58:30

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 statementfind sample.shOutputsample.shNotice that if the find command is able to locate ... Read More

How to unzip all zipped files in a Linux directory?

Mukul Latiyan
Updated on 31-Jul-2021 11:58:09

2K+ Views

Unzip is the Linux command utility that we will use to unzip all zipped files present in a Linux directory.By default, the unzip utility is not present on most of the Linux distributions and we can install the same with the help of the commands mentioned below.For Ubuntu and Debiansudo apt install unzipFor CentOS and Fedorasudo yum install unzipSyntaxunzip file.zipIn the above syntax we just need to replace the file.zip with the file that we want to unzip.Consider a case where I have a directory named direct1 that looks something like this −immukul@192 direct1 % ls -ltr total 5216 -rwxrwxrwx ... Read More

How to test a weekly crontab job on Linux?

Mukul Latiyan
Updated on 31-Jul-2021 11:57:46

1K+ Views

In order to test a crontab job we first need to explore and understand what a crontab job is.A crontab job 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 below in the ... Read More

Advertisements