Basic Tutorial Shell Scripting on UNIX : Ronny Fahrudin

Unix/Linux is an operating system like Windows, iOS, and macOS. Unix is capable of handling activities from multiple users at the same time. Unix is developed by Ken Thompson and Dennis Ritchi started around 1969 at AT&T Bell Labs. In Unix, there is a terminal like a command prompt in windows. That’s terminal is used to shell scripting. So, let’s practice basic scripting in UNIX/Linux. In here we practice about:

  1. Creat file and that's content

  2. Copy file and rename file

  3. Deleting file file

  4. Create directory

  5. Copy and rename the directory

  6. Rename Directory

  7. Remove Directory

1. Creating firstfile.txt and this content

To open a terminal you can press “ Ctrl + T ” your keyboard. In here i want to make file in desktop. So, write “cd Desktop” then enter.

a. ls

to see what folder or file in Desktop you can write “ls” then enter.

b. touch

we can see, in my desktop there file like an autopsy, Block0n-0ff, Caja-Root, Disk Imager Mounter, Guymager, Keyboard changer, Network, the ubiquity. Let’s try to make a file txt. You can write syntax “touch firstfile.txt” then enter. Then see again in the desktop directory with “ls” then enter.

create file.txt

c. cat

So, we can see there is a new file firstfile.txt in desktop. Lets to see to the content of the first file with write syntax “cat firstfile.txt

d. vim

there is no content in firstfile.txt. Then to write content in that’s a file, we have to write syntax “vim firstfile.txt

write content

you will seem like that’s and we’re ready to write content.

canvas to write file.txt

to write in that’s area we have to press “insert” in our keyboard until you see — INSERT — in the bottom. then you ready to write. I try to write “hello, how are you? hope you always find.”

write content

e. :wq

then we have to save that’s content and try to quit. Press “esc” until — insert — doesn’t exist. then write “:wq” enter.

save and quit

So we ready to see in the terminal. Write again “cat firsfile.txt”. Then you will see the content.

That’s all the steps to create the file and this content.

2. Copy and rename the second file

a. cp

The next step is to copy and renames the first file. txt. The command to copying file is “cp name_file name_file_copy”. So, in here we want to copy firstfile.txt, that's the command:

copy file

let’s see what’s the content of firstfile_copy.txt. It’s must same the firstfile.txt content.

validate copying

So, we see that firsfile.txt and firstfile_copy are the same contents. We’re success to duplicate the file. The next, we rename the firstfile_copy.txt become secondfile.txt.

b. mv

to rename file we use command “mv name file namefile_new”. that’s the command:

rename file

we chek again with command cat so that we actually rename the right file.

checking renamed file

Greats, we success to rename the file. Because the content still name and the name file different name with secondfile.txt.

3. Delete file a. rm

when we want to delete the file, we use the command “rm namefile”. So let's see the picture:

list of folder and file

in here we’re want to delete firstfile.txt that’s the command “rm firstfile.txt” then we see the list of folder and file again with “ls” command.

result delete

Now, we can’t see firstfile.txt again.

4. Make New Directory a. mkdir

to make new directory we use command “mkdir name_directory”. and we try to see the new directory with “ls”. see the picture!

make new directory

on that picture, we have a new directory with the name new folder. Then to make a subdirectory in new folder we can use the command “mkdir -p newfolder/newdir1”. Lets’ access the new folder with “cd newfolder” then write “ls” we can see the folder newdir1. that’s the example command in the picture:

make sub directory

5. Copy, Rename Directory a. cp -r

to copy a directory we use command “cp -r name_directory name_dir_to_copy”. In here we copy a directory new folder like above. that’s the command:

copy directory

on the picture above, i write “cp -r new folder newfolder_copy”. we cope new folder becomes a “newfolder_copy”. And we can see we have folder new folder and “newfolder_copy”. It means we succeeded to copy file.

6. Rename Directory a. mv

to rename directory we use again command “mv”. from the name of newfolder become folder_renamed. That’s the example command:

rename file

then we check again with ls. we can’t see newfolder_copy, but find folder_renamed. It’s mean we succeeded rename file.

7. Remove Directory a. rm -r

to remove directory we use command “rm -r name_directory”. Then we chek again with “ls”. This is the example picture below.

remove directory

we can’t find a new folder in the list. So, we success deleting directory.

For more information on UNIX and other languages visit: Ronny Fahrudin's Blog

Previous
Previous

Everything you need to start Python: Favouragbejule

Next
Next

Data Science Tutorial for Beginners