Basic Linux Administration Skill -Part 2/2

Linu Bajy
3 min readMar 5, 2022

This article is is the continuation of Linux Admin skills Part 1

6. Finding and Reading Logs

There are many types of log files. Few of them listed below :

  • System Logs are used to store files regarding processes from Unix/Linux/Windows System. Path in Terminal : /var/log *Event logs
  • Event log records information about network traffic and usage, such as login attempts, failed password attempts, and application events. (CloudWatch in AWS stores Logs- if configured)
  • Application Logs gives the Logs regarding the application. Path can vary
  • Service logs are used to know information about a service.
sudo systemctl status <service>
sudo systemctl start <service>
sudo systemctl stop <service>

7. Unix Permissions

A file/directory can be owned user (u)/group(g)/other(o). File permissions are required to access information from the file . If you are a root (highest power) user, you will be able to modify permissions.

Consider a file sample.txt . A file has the 3 attributes (user /group/others). Each of these have got 3 types of access modes read r, write w, execute x.

rwxrw-r-- root root 20 Mar1 12:34 sample.txt// User has all 3 permissions (First 3 Characters)
//Group (which a user might be part of )has only read and write permission as you can see (Next set of 3 characters rw-)
//Others has only read permission as you can see (Next set of 3 characters r--)

Inorder to change permission , we use the command

sudo chmod g+x sample.txt
rwxrwxr-- root root 20 Mar1 12:34 sample.txt
//Group gets execute permission

8. Signals in Unix

Signals are software interrupts sent to a program to indicate that an important event has occurred.

kill -l //Gives the list of signals

Some of the possible default actions are −

  • Terminate the process.
  • Ignore the signal.
  • Dump core. This creates a file called core containing the memory image of the process when it received the signal.
  • Stop the process.
  • Continue a stopped process.

Sending signals

kill -signal_number pid <==> Ex: [Ctrl + C (Signal Interrupt) -2]

Trapping signals

When you press the Ctrl+C at your terminal during execution of a shell program, normally that program is immediately terminated, and your command prompt returns. But ,you may end up leaving a bunch of temporary files that won’t get cleaned up.

There are two common uses for trap in shell scripts −

  • Clean up temporary files
  • Ignore signals

As an example of the trap command, the following shows how you can remove some files and then exit if someone tries to abort the program from the terminal −

$ trap "rm -f $WORKDIR/work1$$ $WORKDIR/dataout$$; exit" 2 
#If 2 is signal command received , the above trap should take place and clear files

Ignoring signals :

If the command listed for trap is null, the specified signal will be ignored when received. For example, the command −

$ trap '' 1 2 3 15 # Ignores the following signals

9. Hardlinks and Softlinks

Link is basically a pointer.

  • The contents of the file can also be referred from the link name both softlink and hardlink.

Creating a Softlink is like creating a link to a file.

This can be done using the below command :

ln -s <filename> <softlink_name>ex : ln -s testfile current       # -s indicates that its a softlink
Output : current -> testfile
**The contents of current and testfile will be the same.
  • Any changes made to file testfile, after it is linked, will NOT be reflected to current , unless the new testfile is relinked with current again .
  • The permissions will be different for both softlink and the folder .

A hardlink differs from softlink in 2 ways:

  • The changes in file which is linked will be automatically mirrored to the hardlink created.
  • The file permissions will be the same
ln <filename> <hardlink_name>

Note : All the topics have been only briefly explained and should be analysed deeper . This article only gives you a basic direction onto the topics.

Cheers,

Linu

References:

--

--