Sunday, 8 October 2017



Način na koji Linux upravlja korisnicima koji ga koriste je jako interesantan ali i zanimljiv. Naime, svi korisnici se nalaze u posebnoj datoteci po imenu /etc/passwd koja, osim što sadrži korisnike koji koriste Linux distribuciju, ona sadrži i njihov zadani shell, zatim nobody nalog koji nema ni home direktorij a ni svoj shell, i niz drugih bitnih informacija. O /etc/passwd datoteci vidi na ovom linku više. Administratorske privilegije se mogu izgubit na razne načine, ja sam ih izgubio kreiranjem novog korisnika po imenu 'ubuntugeek' te izbacanjem svog korisničkog naloga 'amar' iz grupe admin. U ovom članku ćete saznati kako resetovati vaše administratorske privilegije uređivanjem /etc/sudoers datoteke u Linux-u. Napomena: Ovaj članak je dio moje intenzivne pripreme za LPIC-1 certifikat. 

Piše: Amar Tufo
8. Oktobar, 2017

Svaki put kada instalirate vašu omiljenu Linux distribuciju bilo to Ubuntu ili Mint, od vas se traži da kreirate vaš korisnički nalog i jedinstvenu lozinku kojom pristupate vašoj distribuciji. Vaše korisničko ime se stora u jedinstvenu datoteku po imenu /etc/passwd koja sadrži niz bitni informacija o korisniku distribucije, dok se lozinka stora u datoteku /etc/shadow. Poželjno je da s vremena na vrijeme mjenjate vaše korisničko ime, grupu kojoj korisnik pripada te lozinku radi sopstvene sigurnosti.

Međutim, treba imati na umu da ovakve korake rade isključivo iskusni Linux korisnici koji znaju da koriste i upravljaju sistemskim datotekama unutar Linux-a. Pogrešno uređivanje /etc/passwd datoteke može dovesti do toga da izgubite administratorske privilegije nad vašim korisničkim nalogom nakon čega ne možete instalirate omiljene programe, ažuriranja niti izvršiti nadogradnju vaše postojeće Linux distribucije. U tome slučaju postoji rješenje a to je uređivanje i resetovanje administratorskih privilegija u /etc/suders datoteci.


Slika 1: sudoers incident 
Izvor slike: /home/amar/Desktop/slika1

Na ovoj slici vidite upravo scenario s kojim sam se susreo nakon čega mi je korisnički nalog jednostavno izgubio administratorske privilegije. Pojednostavljeno, korisnik amar više nije administrator nego obični korisnik. Kako rješiti ovaj problem? Rješenje ovog problema je izvodivo u sljedeća tri koraka: 

Resetovanje Ubuntu-a te prebacivanje u root shell prompt


Slika 2: Ubuntu root shell 
Izvor slike: /home/amar/Desktop/slika2

Vračanje ili resetovanje administratorskih privilegija za moje korisničko ime (amar) zahtjeva uređivanje /etc/sudoers datoteke u omiljenom tekst editoru kao root. Ja sam odabrao nano tekst editor. No, prije nego otvorim datoteku /etc/sudoers, potrebno je u root shell unjeti sljedeću komandu koja izgleda ovako: 

mount -o remount, rw /

Za napomenu: Vaša distribucija je trenutno u modu read only, što znači da je moguće samo pregledati datoteke vaše distribucije ali nije moguće uređivati. Navedena komanda će root file sistem prebaciti iz read only u read and write mode. Nakon ovoga možemo otvoriti datoteku /etc/sudoers za uređivanje.

Uređivanje /etc/sudoers datoteke

Ja sam do sada iznjeo neke glavne stavke ovog članka te sam scenario koji se može desiti i dogodi veom često. Ono što nisam objasnio jeste pitanje: 'Šta  je sudoers uopće?'. Kada unesete u terminal komandu man sudoers ovo je odgovor koji vam man daje.


Slika 3: Sudoers admin polica
Izvor slike: /home/amar/Desktop/slika3

Prostim jezikom, /etc/sudoers datoteka sadrži listu korisnika sa administratorski privilegijama a ona izgleda ovako.


Slika 4: Izgled /etc/sudoers datoteke
Izvor slike: /home/amar/Desktop/slika4

Jedina izmjena u ovoj datoteci je ona koja se tiće grupe %admin. Upravo u ovu grupu moramo dodati korisnika amar kako bismo mu povratili administratorske privilegije. Kod vas je naravno drugi korisnički nalog u pitanju ali su postupci isti i imati će isti efekat. 

Promjena lozinke korisnika amar i dodjela u grupu admin

Obzirom kako je moj nalog amar izgubio privremeno svoje administratorkse privilegije, potrebno je dodjeliti novu lozinku kako bismo uspješno obnovili admin privilegije nad distribucijom. Lozinku mjenjamo komandom passwd. Sintaksa joj je passwd user nakon čega dobijete poruku tipa: 'Current unix password', što izgleda ovako.


Slika 5: Promjena lozinke za nalog amar
Izvor slike: /home/amar/Desktop/slika5

Nakon što promijenite lozniku vašeg korisničkog naloga, lozinka će biti sačuvana u posebnu datoteku /etc/shadow koja čuva enkriptovanu lozniku bilo kojeg Linux korisnika. Posljednji korak je dodavanje korisnika amar u grupu admin kako bismo mu povratili admin privilegije. Takav zadatak možemo izvesti sljedećom komandom:

sudo usermod -G admin amar

Naredna slika pokazuje uspješno obavljenu radnju. U osnovi, komanda usermod se koristi i za izmjenu korisničkih podataka te na kraju dodavanje korisnika u određenu grupu.


Slika 6: Dodavanje korisnika amar u grupu admin te provjera statusa
Izvor slike: /home/amar/Desktop/slika6

Kao što vidite na slici 6, amar je uspješno dodat u grupu admin čime su mu ponovo omogućene administratorske privilegije nad Ubuntu distribucijom. 


Slika 7: amar je ponovo administrator
Izvor slike: /home/amar/Desktop/slika7

Zaključak:

Gubitak administratorskih privilegija nad vašom Linux distribucijom može biti uzrokovan nizom popratnih radnji na koje kao korisnik te na kraju kao administrator ne obraćate previše pažnje. U mom slučaju, ja sam izgubio admin privilegije kreiranjem novog korisnika te zamjena postojećih informacija unutar datoteke /etc/passwd što je kompromitovalo moje admin privilegije nad nalogom amar. Srećom, tri iznesena koraka su sve što je potrebno da se admin privilegije povrate korisniku kojemu su oduzete i to je rješenje ovog problema.

Na kraju, savjetujem da budete jako oprezni prilikom uređivanja konfiguracijskih datoteka (/etc/) jer ukoliko ne znate šta radite možete ugroziti stabilnost vašeg sistema te dovesti do neželjenog gubitka vaših podataka ili do goreg incidenta. Ja se nadam u svakom slučaju da vam je ovaj članak mnogo pomogao i da ste iz njega nešto i naučili. Pa ukoliko iskusite sličan incident, pošaljite mi tekstualni članak o vašem načinu na koji ste ga riješili. Toliko od mene za sada i do narednog čitanja. 

Wednesday, 4 October 2017


Welcome to my second LinuxLab which is a special part of my preparation for LPIC-1. This lab was created according to Linux LPIC-1 Certification Bible where I have recently cover a several chapter including user management in Linux, file permissions, and so on. So, in this article I will focus on four assignments in order to complete this article and to demonstrate how to add a new user, creating a unique user group, setting file permissions and I will show you how to use ssh/sftp protocol in order to extract a report.txt file on your private server and etc. 

Written by: Amar Tufo
4. October, 2017



On the image above you can see the tasks for LinuxLab which we have to solve in this article. I have even planed to make a YouTube tutorial for this LinuxLab but I have decided to write an article and then I shall see about YoutTube part. Let's begin!

Creating a new user!


The first part of this LinuxLab is to create a new Linux user named ubuntugeek with it's home directory and new user group named ubuntustation. There are dozens tutorials available online on how to make a new Linux user as well as new user group. But in this article you need to understand several major things when creating a new user. One in particular is the way you are gonna access the newly created user in Linux; Second is /etc/passwd file which holds all information on user including it's name, group, user id, group id, user home directory, and login shell. Now, here's my sample of /etc/passwd file.


Image 1: /etc/passwd file for user amar
Image source: /home/amar/Desktop/image1

It's very important to understand the /etc/passwd file since information stored in this file are crucial when it comes to user management in Linux as you can use this file to add user manually to your Linux distribution. For more on /etc/passwd file check this link. Here are three key notes on /etc/passwd file. 

root account - this account is known as superuser and it is the most privileged account on a Linux system. It gives you the ability to administer the system by adding new accounts, changhing user passwd, examining log files, installing software and changing file permissions. 

nobody account - this account is used for system services and has no shell or home directory.

the /bin account - contains the home directory of /bin with no shell assignment. 

You can get the same information on the current user by typing the following command like in this sample down bellow. 


grep amar /etc/passwd

Once you type your user name, the output should be as follow:


Image 2: Output of the command grep amar /etc/passwd
Image source: /home/amar/Desktop/image2

In the following table, here's an explanation of the command above to understand what these information are.


Image 3: Explanation of the grep amar /etc/passwd command
Image source: /home/amar/Desktop/image3

The last thing I wanna note here is the user password. Now, Linux store user password in a unique file named /etc/shadow. The x: character you see in the table above represents my encrypted password which is stored in /etc/shadow file. Password is basically showed in a bunch of random letters and numbers which are difficult to read but safe and encrypted. In other hands, you don't want others to know your password. Here's my sample of /etc/shadow file.


Image 4: Output of the command sudo grep amar /etc/shadow 
Image source: /home/amar/Desktop/image4

Creating ubuntugeek user.


The output for your user name will be different than my which is ok. Now, we can start to make our ubuntugeek user with it's user group and home directory. The command you will see here are well tested for the purpose of this article. There are several ways to create a new Linux user and one way that I prefer is via useradd command using the following command syntax:


sudo useradd -m ubuntugeek

Once you type the following command, you should be able to see the newly created ubuntugeek user as on this image down bellow.


Image 5: Accessing newly created user ubuntugeek using su ubuntugeek command
Image source: /home/amar/Desktop/image5

One note: In order to access our ubuntugeek user, in command above I have use -m to tell the Terminal to force create ubuntugeek home directory. Without home directory, we won't be able to access ubuntugeek user neither it's data. Before we make our user group and add ubuntugeek inside it, we need to assign ubuntugeek password. We can do that using the following command: 


sudo passwd ubuntugeek

The output of the following command is as follow:


Image 6: Assigning ubuntugeek password
Image source: /home/amar/Desktop/image6

The name of your user is different than my in the sample above, but it's the same syntax you should follow in order to assign your user password or change an existing password and etc.

Creating group ubuntustation.

User groups are essential part in Linux. Basically it can be described as a collection of multiple users which have default permissions on the system files and etc. Note, that groups need to be manage some how and that's where permissions comes in to play. Permissions are important part of Linux security since they allow Linux System administrator to set the permission for user as root account, groups and others. This way, I can set the permission to read, write and execute certain file or limit other users to write or modify the file, but grant them to read and execute certain file and so on. More on groups, please click the following link. Before I show you how to create ubuntustation group for our ubuntugeek user, I will show you how to view file permissions over the files or directory. The following command is used to see the file permissions.


cd Desktop
cd application
ls -l

In the command above, I have chosen application directory on Desktop which I have listed using the ls -l command. Here's the output.


Image 7: Listing file permissions on the application directory content
Image source: /home/amar/Desktop/image7

Each file has a default permission set assigned to user (root account), groups and others. This default permissions are known by characters such as rwx as shown on image7 above. What they does or mean is important to know because you will work with them a loot. In short, here is a explanation of rwx characters:

read (r) - it allows the file to be viewed or directory content to be listed.

write (w) - it allows you to modify the file or to write to the file.

execute (x) - it allows you to run the file, program or execute a script.

In the image 7 you can clearly see -rwx characters in front of main.cpp file in my application directory. In this case, main.cpp is C++ source code file on which I have set the default permission for user (amar) which is rwx, group can rw but can't execute the file, and others can execute and read the main.cpp file. Here's a command which I have used to set the main.cpp permissions:


chmod u+rwx,g+rw,o-wx main.cpp

The command used in this sample is chmod (change mod). It's this command that allow Linux System administrator to grant access on certain files and directories for user, groups and others or to take them away at will in order to protect the system or user it self. Since this is a LinuxLab, I don't have time to explain chmod and file permissions in detail but if you are interested to know more about this command which I highly recommend, then visit this link.

Finally, let's make our ubuntustation group and to complete this article. The command used to create group is groupadd. Here's the full command.


groupadd ubuntustation

Now, there's nothing special to note or add here to this command. Only thing is that our newest group has been created and we can now add our ubuntugeek user to ubuntustation group using the following command.


sudo usermod -G ubuntustation ubuntugeek

In the command above I have used the usermod command to add ubuntugeek user to ubuntustation. The Terminal command to make sure that we have added ubuntugeek to ubuntustation is the following:


Image 8: Checking that ubuntugeek user is part of ubuntustation group
Image source: /home/amar/Desktop/image8

This is it. We have successfully added our ubuntugeek to ubuntustation group and therefore completed this first part of my LinuxLab. Make sure to read entire article, comment it, share it via social media and please if you note errors while reading this article weather in text or Linux commands used in this article, please comment it down bellow so that I can fix it and update it as soon as possible. Until the next time, I see you soon in part two of my LinuxLab. 

Sunday, 17 September 2017



Prošlo je pune tri sedmice od mog posljednjeg pojavljivanja na svom zvaničnom YouTube kanalu tako da od sada pa nadalje nastojat ću da svaki novi video postavim kako na YouTube tako i na svoj sajt. Eh sada, smatram da vas manje zanima gdje sam bio, a sigurno vas zanima zašto novi video nije objavljen pune tri sedmice? Na ovo pitanje sam odgovorio i u istoimenom videu:'Gdje sam bio i šta ima novo kod mene' koji je upravo objavljen i dostupan za pregled na mom YouTube kanalu a jednostavan odgovor je da sam imao i dalje imam mnogo važnijih obaveza kao što su studije Arheologije koje privodim kraju. 

Piše: Amar Tufo
17. Septembar, 2017



Kao što sam već i u samom uvodu rekao, bio sam odstuan pune tri sedmice, podalje od tastature, YouTube-a i ostalih stvari kojima se mimo svoje struke aktivno bavim. Ove tri protekle sedmice za mene su bile radne pa sam nastojao koliko god sam slobodnog vremena imao da ako ništa popratim aktuelnosti s Linux scene i dešavanja iz svijeta Open Source softwera. U tom pogledu, najviše me dojmila novost oko novog izdanja Ubuntua, najpopularnije Linux distribucije koja će uskoro dobiti izdanje Ubuntu 17.10 kodnog imena 'Artful Aardvark' koji nam dolazi 19. oktobra 2017, javlja ugledni Ubuntu portal OMG! Ubuntu. 

Kako javlja portal OMG! Ubuntu, novi Ubuntu 17.10 dolazi sa predinstaliranim grafičkim okruženjem  GNOME koje će se takođe pojaviti i u novom Ubuntu 18.04 koje će biti naredno LTS izdanje megapopularne Linux distribucije. No, osim vijesti koje su kružile u svijetu Ubuntu-a protekle tri sedmice, dobijao sam i razna pitanja oko novog video iz Arheologije, kada će biti objavljen i koja je tema u pitanju. Odgovor na ovo pitanje sam dao i u ovom svom videu koji je objavljen a tema je Kopan, arheološki lokalitet smješten u Hondurasu, izuzetno važno kulturno - političko sjedište Maja poznato diljem svijeta. Uglavnom, morat ćete se strpiti na neko vrijeme dok obavim adekvatno istraživanje kako bi video bio pripremljen i objavljen.

S druge strane trebam napomenuti kako je u tijeku moja Linux edukacija, intenzivna obuka za LPIC-1 certifikat te sam s te strane uspješno okončao osam sedmica svoje pripreme za Linux System Administratora. U pripremi je i nadolazeći Linux Lab iz Linux User administracije koji se sastoji od četiri praktična zadatka ovim redosljedom:

* Kreiranje novog korisnika
* Kreiranje nove korisničke grupe
* Dodavanje  korisnika u grupu te postavljanje permisije komandom chmod i chown
* Četvrti zadatak je scenarijo koji traži da se koristeći ssh / sftp protokol na šefov računar dostavi aktuelni izvještaj o radu i aktivnosti Linux System administratora u toku dana.

Cijelokupni izvještaji sa Linux edukacije su dostupni na mom sajtu zajedno sa praktičnim laboratorijskim vježbama, testovima te tutorijalima koji su veoma dobro urađeni ali su pripremljeni s pretpostavkom da imate predznanje u korištenju Linux distribucija te da posjedujete minimalno iskustvo u radu s Terminalom prilikom rada s komandama. Pomenuti Linux Lab stiže uskoro kako na moj YouTube kanal tako i na moj sajt  a isti je dio intenzivne pripreme za LPIC-1 test. 

Reference:
___________________________________________

1. Novi Ubuntu 17.10 code name 'Artful Aardvark'

2. Ubuntu 17.10 release date

3. Doper-Tech | Technology for you

Thursday, 24 August 2017


Mnogo je gradova u prošlosti koji su porušeni, napušteni pod nepoznatim okolnostima, razoreni do temelja ili su jednostavno misteriozno nestali sa lica Zemlje a nekoć su bili dom desetinama hiljada stanovnika. Takav je i legendarni Bretonski grad Ys koji je sagrađen u 5. stoljeću na obalama Britanskog zaljeva Dvarnanez a koji je jedne noći jednostavno nestao pod valovima mora. Još se ovaj grad nazivalo Europskom Sodomom i Gomorom a u nastavku ćemo i saznati zašto je to tako te sudbinu ovog grada. 

Autor: Amar Tufo
22. August, 2017

Pogledajte preradu ovog Keltskog mita na mom YouTube kanalu, komentarišite, lajkajte, kritikujte i naravno ostavite <SUBSCRIBE> za još boljeg sadržaja koji stiže na moj sajt ali i na YouTube kanal.


Video: Amar Tufo - Izgubljeni grad Ys

Ys je legendarni Keltski grad kojeg je u petom stoljeću na obalama Britanskog zaljeva Dvarnanez dao sagraditi Gradlon, kralj Korvala. Grad je bio opasan velikim zidinama koje su ga čuvale od mora. Još dok je bio mlad Gradlon se zaljubio u predivnu morsku sirenu koja mu je kasnije rodila kćer po imenu Dahut. Sirena se kasnije vratila natrag svome ocu u more a Gradlon je preuzeo brigu o svojoj kćerci Dahut koja je ubrzo postala najljepša djevojka Kornvala.


Slika 1: Britanski zaljev Dvarnanez - počivalište grada Ys

Vremenom Dahut se osjetila usamljenom i svome ocu predloži da joj sagradi predivan morski grad u kome će ona provoditi svoje dane. Tako i bi te Gradlon u čast svoje kćeri sagradi grad po imenu Ys. Jedna verzija legende kaže da je Gradlon ubrzo nakon što je dobio kćer Dahut, prešao na kršćanstvo i napustio svoju pagansku vjeru. Kako bi ga kaznila za veleizdaju vjere svoga naroda, Gradlonova žena se jedne noći vratila u grad te bacila magične čini na Dahut učinivši od nje najiskvareniju ženu toga grada. 

Dahut je postala sexualno ovisna da je svake noći organizovala pijanke i sexualne orgije do zore koje su se kobno završavale po njene ljubavnike koji su umirali u njenom zagrljaju. 

Jednoga dana se pred kapijama grada pojavio vitez obučen u crveno. Dahut se odmah zaljubila u njega ali nije imala pojma da je to bio đavo kojeg je poslao sam Bog da kazni iskvarene stanovnike ovog grada. Tako je Dahut u neznanju i opijena vitezu dala srebrne ključeve kapija koje su grad čuvale i štitile ga od morskih dubina. 

Samo što je vitez otključao kapije grada, more je počelo nadirati i gutati grad u svoje dubine. Shvativši da je grad u opasnosti, Gradlon uzjaha svog magičnog konja Marvića i poče zajedno sa svojom kćerkom Dahut bježati preko mora.



Slika 2: Gradlon bježi iz Ys-a

No, dok su bježali, Dahut nesretno pade s konja te nestade zajedno s gradom u morskim dubinama. Kasnije je Gredlona posavjetovao sveti Gvenol koji je u tom trenutku boravio u gradu te predvidio propast samog grada, da je Dahut to i zaslužila te uzrokovala propast grada.

Šta je bilo s Dahut?


Slika 3: Dahut nastavlja svoj život kao sirena

Nakon što je pala u more, kako priča kaže, Dahut je postala morska sirena koja svojim predivnim glasom mami nesretne ribare koje s zadovoljstvom ubija. Kada je pučina i mirno more, ribari zaljeva Dvarnanez kažu da iz dubina dopiru zvona porušene crkve i predivno pjevanje nesretne Dahut. 

Što se tiće sudbine grada, kaže se da će se jednoga dana Ys ponovo pojaviti iz morskih dubina ljepši nego ikada a do tada će ga čuvati veliko more.


Reference:

1) The Legend of the city of Ys by Chris Gonnerman [online article]

2) The Encyclopedia of Celtic Mythology and Folklore
     Copyright © 2004 Facts on File, Inc by Patricia Monagham, p494
     
Download link: http://stoa.usp.br/briannaloch/files/2564/13832/The+Encyclopedia+of+Celtic+Mythology+and+Folklore.pdf

Wednesday, 16 August 2017


Welcome again to my NDG Linux Essential adventure, module 7 of my Linux course. Shortly, NDG Linux Essential module 7 cover mostly working with tar, gzip, bzip2, compressing/uncompressing, creating tarball, viewing it's content, extracting it into other directory on your Linux distribution and so on. I have learn so much amazing and important things on working with tarball, creating a backup of your files and directories which could be very handy when you uploading a files to your server or website and so on. Finally, my module ended with exam that consisted of 10 questions which I successfully scored with 10 grade. Here's my final exam of module 7. Oh, I almost forgot. Before you view my exam, I suggest you to jump on my tutorial of working with tarball which you can see down bellow.

Written by: Amar Tufo
16. August 2017


Video tutorial: Working with tarball ~ Amar Tufo

Ok, and here's a test for NDG Linux Essential module 7 of my intensive Linux course which consisting of 10 questions as previous modules. Question have been answered and you can access them via my website.



That's all folks for this week. I hope that this intensive Linux course will help and motivate you as well to get started your own Linux career and preparation for some serious Linux certification such as LPIC-1 which I have started. I see you soon on my YouTube channel and in NDG Linux Essential - week 8 - . Till then, have a nice weekend!

Thursday, 10 August 2017


Last week I have written a short intro for my NDG Linux Essential course - module 7 - and now I can proudly announce that week 7 of my NDG Linux education is successfully completed  and here are some key notes and summary of my NDG Linux Essential - week 7 -. As noted previously in my short intro of module 7, this entire module was very short but cover some skills working with compressing, decompressing, creating .tar archive, working with gzip, bzip and so on. So here are some important notes on working with tarball, creating an tar archive, listing it's content, updating the archive and so on. I should also note that this article includes the final exam for module 7 at the end which you can see down bellow. Ok let's start. . . 

Written by: Amar Tufo
9. August, 2017

The tar utility is widely used by all Linux distributions. Along with being a useful tool for backup, tarball files are also a convenient way to distribute files. They allow a single file download and because compression can be handled with tar they also creates smaller files for download. Tarball files do not have to end with .tar extension, but it's a good practice to do so. Files that are joined and compressed often use the .tar.gz extension. In the following sample I will demonstrate how to create tarball file, how to extract it, see it's content and extract a single file out of tarball.

1# Sample: Creating archive.tar.gz file


                                                             
Image 1: Creating archive.tar.gz for final directory
Image source: /home/amar/Desktop

In this first sample I have created archive.tar.gz tarball as backup for my final directory. In the image1 above, archive contents were listed upon compressing. Short note for the command used above is following:



tar -zcvf archive.tar.gz final/

Once typed this command will compress final directory with all it's content into single tarball in this case archive.tar.gz. If you wonder what -zcvf stands for than here what they are:


tar -zcvf archive.tar.gz final/
*z - tells the tar to use gzip tool
*c - creates an archive
*v - tell me what you are doing
*f - file name

2#Sample: Listing the archive.tar.gz content and extracting it to another directory

Let's assume that you want to view the content of archive.tar.gz before extracting it. Here's the command that will do just that:


tar -tf archive.tar.gz 

Once typed into terminal this command will generate the following output:


Image 2: Listing the content of archive.tar.gz tarball
Image source: /home/amar/Desktop


Now as we have listed our content, let's extract our archive.tar.gz in /tmp directory of my home folder. Here's the command that will accomplish such a task.


tar -xvzf archive.tar.gz -C /home/amar/tmp

Note: -C in this command allow you to give the tar command a path to destination directory in which you are extracting your tarball in this case archive.tar.gz > /home/amar/tmp.

Once you typed this command this is the output you should see. Image 3:


Image 3: Extracting archive.tar.gz into /home/amar/tmp
Image source: home/amar/Desktop

Note that I have extracted the archive.tar.gz content into /home/amar/tmp directory from Desktop as my pwd directory. Keep this in mind that before each extraction of the tarball move the archive into empty directory or the directory/files will be replaced and overwritten. 


Image 4: Successfully extracted archive.tar.gz tarball file into /tmp directory
Image source: /home/amar/tmp

3#Sample: Adding log.txt file into archive.tar.gz and extracting a single file out of archive

Let's assume that you want to add a file into existing archive in this case log.txt file into archive.tar.gz. For this purpose I have created four files on my Desktop namely file1.txt, file2.txt, file3.txt and log.txt. I will now create an archive.tar.gz which will contain only file1.txt, file2.txt and file3.txt using the following command:


tar -cvf archive.tar.gz file1.txt file2.txt file3.txt


Image 5: Creating a new archive.tar.gz 
Image source: /home/amar/Desktop

Now let's update existing archive.tar.gz by adding log.txt into our archive. We can do that using the following command:


tar -rf archive.tar.gz log.txt

Your output should be the same as main if you have type it correctly. See the image 6 down bellow.


Image 6: Updating the existing archive.tar.gz with log.txt file
Image source: /home/amar/Desktop

4#Sample: Extracting log.txt into different directory

Sometimes tarball can be very big in size and you don't need an entire archive. You need only a specific file as Linux System Administrator into let's say /tmp directory. In this sample I'm about to show you how to extract log.txt file from archive.tar.gz file into /tmp directory which is in my home directory.


tar -xvf archive.tar -C /home/amar/tmp log.txt

Note when extracting a single file out of tarball, file is added at the end of command. In other case, the file will be extracted into present working directory. Here are the final results of this command.


Image 7: Extracting log.txt file from archive.tar into /tmp directory
Image source: /home/amar/Desktop

Here's the terminal output for our /tmp directory which holds log.txt file which we extracted from archive.tarball.


Image 8: /tmp directory with log.txt file
Image source: /home/amar/Desktop


This all folks for today. I hope that this article has helped you in understanding the way tar works, how to create an tarball, how to list it's content and how to extract the single tarball file into another directory. Make sure to commend down bellow and share this article. Stay on my site because I lot's of other useful and educational content for you all. We see you soon at NDG Linux Essential week 8, till then have a nice stay at my website.


Tuesday, 1 August 2017


Welcome to my seven week of my NDG Linux Essential adventure. As you know I have recently published my first LPIC Shell Exam, final exam for SHELL chapter compiled after LPIC-1 Certification Bible which I use for LPIC-1 exam preparation alongside NDG Linux Essential course. As noted I have completed successfully LPIC-1 Shell chapter from mentioned book (link is down in description bellow). Now the NDG Linux Essential course - module 7- is covering the following tasks in order to complete it:

> > Compressing files under Linux format such as .tar.gz
> > Decompressing files . . .
> > Archiving . . .

Basically this module is very short but it does include the final 10 question exam in order to complete it. Check the image down bellow:


Image 1: NDG Linux Essential module 7 intro


As you can see, it is very short part of my NDG Linux Adventure and therefore I'm going to expend it using LPIC-1 Certification Bible /special chapter. Stay tuned and have a nice stay at my blog.

Weather

Advertisement

Follow me on Facebook:

Popular Posts