Archiving and compressing files in Linux

Archiving and compressing are two different concepts. Archiving is basically collecting files in a single package and a popular tool for that is called tar. Compressing is actually reducing file size by means of an algorithm and popular ones include bzip2 and gzip. I will talk about those, but first I would like to talk about another tool for creating archives: cpio. cpio The cpio command can be used to create a backup of the /home/ directory for instance: ...

September 17, 2016 · 3 min

More admin commands for users in Linux

This post is a collection of commands basically, I hope it works a reference for me and other people who pass by. To delete users, we have deluser and userdel. For me, it was really weird learning that we have two commands with similar names that basically do the same thing. I present some examples below. # removes user and home directory $ deluser -r user $ userdel user # remover user from group $ deluser user group # deleting a group $ deluser --group group Creating or deleting groups, adding a user to them or changing primary group: ...

September 17, 2016 · 2 min

Administrating Linux users with the chage Command

When a system administrator wants see when a user last changed a password or wants to force a user to change it, there is a really nice command to come to the rescue: chage. I created a user called aluno and I started to check for its information: $ sudo chage -l aluno Last password change : Sep 16, 2016 Password expires : never Password inactive : never Account expires : never Minimum number of days between password change : 0 Maximum number of days between password change : 99999 Number of days of warning before password expires : 7 As we see, the user password was last changed on Sep 16, 2016 and it never expires nor gets inactive. This can be easily changed by using the command chage -M number_of_days and then checking the user info again: ...

September 16, 2016 · 3 min

30 days of code in Go: Day 10 - Binary Numbers

The challenge for today is interesting, but I keep wondering if I could do it more efficiently. Let me know in the comments if you have any suggestion after reading my solution. The problem is counting the maximum number of consecutive binary ones in an integer. It is easier to understand with an example: Consider the number 25 represented in base 10 Its representation in binary is 11001 The max number of consecutive ones we can see is 2 What I did was shifting to the right and checking the least significant bit until every single bit of it was checked. The solution is available below. ...

September 16, 2016 · 1 min

30 days of code in Go: Day 9 - Recursion

Hi there! Here I am coding again. For those of you readers who may not know what recursion is, I have a brief explanation: a function is called a recursive function when it calls itself. A very nice example is the factorial, which is also what I am going to code today. For the factorial of $N$, $f(N)$, we can state that $f(N) = N\times f(N-1)$. What we see is that the function is represented by itself, but with other argument and it can keep this going up to a certain point for which we know the answer like $f(1)=f(0)=1$. Given this introduction, I will code. ...

September 15, 2016 · 1 min

30 days of code in Go: Day 8 - Dictionaries and Maps

Hi there! The task of today will be coding a phone book. The program reads an integer $N$ that represents the number of people in the phone book. After that, it reads the $N$ entries from standard output and generates the dictionary/map. For newbies: dictionaries are the same as maps. Java usually calls the structure with (key, value) pairs as a map, while Python calls it a dictionary. After having the phone book generated, the program will read an unknown number of names. The fact that we can query as many names as we want means that the program needs to check for an end of file before leaving, which is basically trying to read until the user cancels the program. Well, other options would be typing a special quit command, but that’s not the case for this problem. ...

September 14, 2016 · 3 min

30 days of code in Go: Day 7 - Arrays

Hi there! A couple days ago I wrote a post about a simple array sum in Go and I said I didn’t need an array in memory to do the sum, but just an integer that would store the inputs the user gave the program. This time, I will really need an array. The goal is to read an array $A$ of $N$ elements and print $A$ elements in reverse order. Surely I could put everything in a file and then read it backwards, but as I don’t even know how to use files in Go at the moment, I will be creating an array in memory and then printing it backwards to the screen. My solution is just below. ...

September 13, 2016 · 2 min

30 days of code in Go: Day 6 - Let's review

Some challenges require us to review basic concepts to make them work. This one is no different, but the main purpose of it is to be a review! The goal is to separate the characters of a string. The even-indexed characters will form a string and the odd-indexed characters will form another. These two strings must be printed to the screen with a space between them. Not hard, but an important review. Solution below. ...

September 12, 2016 · 2 min

30 days of code in Go: Day 5 - Loops

Hi there! Welcome to Day 5 of 30 days of code in Go! One interesting thing about loops in Go is that there is only one looping construct: for. This challenge will receive an integer input $N$ and it will print results of the form $N\times i = \mathrm{result}$, where $1 \le i \le 10$. By the way, there was a loop on the last day of code, but it was actually part of the given code. The one for today will be quite similar. ...

September 11, 2016 · 1 min

30 days of code in Go: Day 4 - Class vs Instance

Here I am again for the 30 Days of Code in Go. This is Saturday, but that doesn’t mean I will not code =). First of all, before starting to code I was thinking about the theme: classes. I was wondering if Go had support for it and I found some interesting material to read. First I read Why Go’s structs are superior to class-based inheritance and I found out the the inheritance model of Go is different from that of Java. Basically, you do not actually specify which class implements an interface, but the compiler. A class can implement several interfaces, not being limited to one super-class like in Java or C++. Another materials I read were Go by Example Structs, methods and interfaces. I am not so well versed on the syntax, but it is not hard to grasp it and start coding. Nevertheless, HackerRank was good to me and gave some starter code and I just implemented the methods. ...

September 10, 2016 · 2 min