Spiral Transparent Funding and Utiliware

When Exit to Community first came out, I thought, oh, this is intriguing but what if we didn’t start with a VC approach to begin with? What if it isn’t about an exit but begins with an onramp to…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Basic Shell Scripting Tutorial for Beginners

Shell is a program that functions as a communication bridge between the user and the kernel. The kernel is the core of an operating system that interacts with hardware and is used for memory management, task scheduling, and file management. Shell scripting is writing commands for the shell to execute. Here is a diagram that explains the relationship between the user, shell, and kernel

This article will discuss the basic commands in shell scripting, including how to create a new file, copy a file, rename a file, delete a file, create a new directory, move files to a directory, and delete a directory.

Before starting this discussion, there are 2 main things to know, namely the pwd and ls command. The print working directory (pwd) command is used to display the name of the directory you are currently in, while the ls command is used to display files and folders contained in the directory.

To create a file without any content, use the touch command followed by the file name and extension of the file.

Suppose you want to create a file named practice1 with txt format, then you can type:

Besides using the touch command, you can also use the cat command to create a new file and write its contents directly.

If you have finished writing the contents of a file, press Ctrl+D to exit and save. This is an example of using the cat command:

You can also use the vim command to create a new file and write its contents. In addition, the vim command can also be used to write the contents of the file that was created using the touch command.

After writing the vim command, you will be asked to write the contents of the file.

After writing the contents of the file, press Esc on the keyboard until the INSERT text disappears, then type ‘: wq’ (write quit) to exit and save the file contents.

Copying a file can be done by typing the cp command followed by typing the file name you want to copy and the destination file.

For example, I want to copy the contents of the intialfile.txt file to the copyfile.txt file:

The contents of both files will be the same.

Renaming files can be done using the mv command followed by writing the old file name and the new name that you want.

For example, I want to rename the file practice1.txt to renamefile.txt:

The last line shows that there is no file called practice1.txt because it has been renamed to renamefile.txt.

Deleting a file can be done using the rm command followed by the name of the file you want to delete.

For example, I want to delete the renamefile.txt file:

In the last line, it can be seen that there is no file named renamefile.txt.

To create a new directory, you can use the mkdir command followed by the directory name.

For example, I will create a new directory named newdirectory:

To create a subdirectory without opening the directory first, you can use the mkdir -p command followed by the subdirectory name and the directory name.

To move a file to a directory can be done using the mv command followed by the name of the file to be moved and the name of the directory.

Copying a directory can be done using the cp -r command followed by the name of the directory to be copied and the name of the destination directory.

Renaming a directory can be done using the mv command followed by the old directory name and the new directory name.

For example, I want to rename newdirectory to renamedirectory:

Deleting an empty directory can be done with the rmdir and rm -d commands followed by the name of the directory to be deleted.

For example, I want to delete an empty directory named renamedirectory:

To delete a directory that has content in it, use the rm -r command followed by the name of the directory to delete.

For example, I want to delete the copydirectory:

Those are the basic commands that can be used in Shell Script. If you have any questions regarding this tutorial, feel free to ask me in the comments below. Hope this is useful.

Add a comment

Related posts:

Operation Enduring Digitarti

Today we learn just how far Billy Jones is willing to go in order to control the literary world. Or was that literal world… I’ve got to do it, he thought, I’ve got to make them think Operation…

They need us

A country that was established to provide a place to its people to live with freedom and provide them opportunities so that they can prosper. On its 73rd independence day, Pakistan is still very far…

How the Tower Tarot Made Me Feel Last Night

I was shaken awake last night from an onslaught of unpleasant thoughts. Sensations, fearsome and frustrating, caused me to bump and shiver in my lying place. The covers were a mess, wet (not what you…