The tar command can be used to compress or extract one or more files in Linux. A tar file isn't actually a compressed format, instead it is a collection of files within a single file. The tar command can take one or more files, convert them into a tar file and then compress it into a gzip file format. The file created will have the extension tar.gz.
There are a large number of flags that can be used but the main ones for everyday use are.
After a recent update on Ubuntu I found that I was unable to use ssh due to a strange permissions error to do with the ssh config file. This was quite a problem as I wasn't able to push changes to my git server. The error was as follows:
Searching all files in a directory and sub-directories for a particular term is really useful and comes in handy in all sorts of situations. It is available on all Linux systems and the basic syntax is as follows.
grep -r -i pattern directory
The -r flag is used to recursively search underneath the given directory and the -i flag is used to ignore case. The pattern is a normal regular expression, which can be changed to an extended set by using the -E flag.
Following on from the PHP script to print happy birthday I wanted do the same in a bash script. I don't really use bash for much more than stringing together commands so I had to figure out how to do loops and if statements using the simple bash syntax. I also wanted to pass the name of the person as an argument, rather than hard code it into the script. This is what I came up with.
The du (or 'disk usage') command is a Linux command that can print a list of the files within a directory including their sizes and even summarize this information. It is useful if you want to see how large a group of files is and provides more information about directories than the ls command does.