Linux and things you probably didn’t know

Tram Ho

If you are also a programmer, you are no stranger to the Linux operating system.

So do you like the terminal window? I like it because it feels so cool to use the terminal.

From that interest, I came up with the idea for this article. Nothing is too sublime, but I think it’s quite necessary.

Let’s find out together

1. File management

This is the basic directory structure of Linux, you must be so familiar.

So do you know what they are for?

  • root: the root directory
  • home: the directory containing the user’s data.
  • boot: the directory containing the kernel of the operating system
  • bin: basic program file directory
  • usr: application directory
  • var: updated data directory
  • dev: directory containing device files
  • etc: directory containing configuration files

Knowing the directory structure will help you know which folders to access when you encounter problems. For example, if we want to configure DNS, hosts, then we will have to configure it in etc

Some file management commands to know:

  • cat <path> : read the file
  • more <path> : read each line
  • tail -<n> <path> : see the last n lines of the file
  • head -<n> <path> : see the first n lines of the file
  • touch <path> : create new file, update old file

Find command

find <folder> <expressions>

Supported expresssions include:

  • File name: -name <query>
  • Permissions: -perm <query>
  • Type: -type <query>
  • Size: -size <query>
  • Time: -atime N, -mtime N, -ctime N
  • To combine multiple conditions, we have the operators: -not, -and, -or.

For example:

Permission to use the file

First, we need to identify, decentralized objects here include 3 types:

  • u: file owner
  • g: Other users of the file group
  • o: Other users


In particular, the mode consists of 3 numbers, corresponding to the rights for the three types of objects mentioned above.

The numbers consist of 3 bits, have a value between 0 and 7 and have the following meanings:

  • 0: Not allowed to exercise any rights
  • 1: Execute
  • 2: Write
  • 3: Write and execute
  • 4: Reading
  • 5: Read and execute
  • 6: Reading and writing
  • 7: Read, write and execute

Commonly used modes include: 555, 644, 755, 777

You can find out more here

I wonder if you usually use mode 777 or not? If so, then surely this paragraph will be necessary for you.

1. Process management

Processes are programs that are being executed on the operating system. Processes will be arranged to share CPU time.

2.1 Several process management commands

  • ps:
    • Show user progress
    • The aux option will allow you to display all running processes.
  • kill <process_id>:
    • End the specified process
    • You can also use killall to end all processes.
    • This command is only executed by the process owner.

  • top – <d> delay
    • Displays the% of process resources in use (including CPU and internal memory). Where d is the number of seconds the command updates.

2.2 Types of commands execution

  • command_1 ; command_2
    • Use characters ; Between commands, the instructions will be executed consecutively and independently from each other. This means that the result of the previous command execution does not affect the execution of the next command.
  • command_1 && command_2
    • Using && between commands will execute the commands in succession and depend on one another. The following command will be executed if the previous command has no errors.
  • command_1 | command_2
    • Character | will allow the output orientation of the previous command to be the input of the next command. This mechanism is called pipe mechanism.
  • command_1 <<file_input>
    • Instead of using the standard keyboard input, you can define the input for a command in a file and use < to redirect the input.
  • command_1 >> <filte_output>
    • Instead of using the standard output as a terminal, you can define the output for the command to the specified file by using >> .

3. Network configuration

You can do a lot of things like:

  • Network connection configuration: NIC, IP, Gateway
  • DNS configuration, host, …

Some configuration files to consider

/etc/init.d/networkStart / stop / restart network services
/etc/resolv.confDNS configuration file, configure DNS servers for domain name resolution.
/ etc / sysconfig / networkGeneral network configuration
/ etc / sysconfig / network-scriptNIC configuration
/ ect / hostsConfigure host name-ip mapping


Network configuration test commands:

ping <host-ip>Check the connection of the machine with the specified ip
ifconfigCheck network configuration
cat /etc/resolve.confSee DNS configuration
hostnameMachine name

Some configuration commands

ifconfig eth0 down or ifdown eth0Turn off NIC
ifconfig eth0 up or ifdown eth0Turn on NIC
/etc/init.d/network stopTurn off network services
/etc/init.d/network restartRestart the network service
ifconfig <NIC-name> <IP> netmark <mark>Set the IP address

I just found out like that. Hopefully the next article, I can provide more useful information. Hope this article has been helpful to you. Thanks and see you again in the next post.

Share the news now

Source : Viblo