Shell Scripting for Linux
Today, I would like to write about Shell Scripting for Linux derived from some references. It started with the definition itself. Shell in a Linux operating systems is like an interface. It is accessed by a terminal to take input (i.e. program, commands, scripts) and gives an output. When terminal is run, the Shell issues a command prompt so users can type input and hit the Enter key to execute.
Now, what is Shell Scripting? It is writing series of commands for the shell to execute. Below are the steps in Shell Script.
Creating a file and its content in Linux
a. Use the cat command [cat > file.txt]
b. Press Enter key
c. Add content
d. Save and exit by press Ctrl+D
e. View the file use cat command [cat file.txt]
Copying the file, then rename the second file
Copy the file called file.doc in the current directory as newfile.doc
$ cp file.doc newfile.doc
$ld -l *.doc
Rename the file to newfile2
$ mv newfile newfile2
Making a new directory, move the second file into the directory
Open the terminal application then use mkdir command to create a new directory name dir1
$ mkdir dir1
Move the file into new directory using mv command. For example, to move the newfile2 from current directory dir1 to another directory dir2.
$ mv newfile2 dir2
Removing the first directory
Remove the non-empty directory dir1 and all the files inside, use the rm command with the -r (recursive) option
$ rm -r dirname