Reading:
Useful Ubuntu commands

Useful Ubuntu commands

Metamug
Useful Ubuntu commands

File size

ls -l --block-size=M

Above command will give you a long format listing (needed to actually see the file size) and round file sizes up to the nearest MiB.

ls -lh

Here h stands for human readable

Check Process consuming most memory

This command will produce the percentage wise usage of memory

ps aux --sort=-%mem | head

If you want to show only the command name instead of the full path of the command, run the following command:

ps -eo pid,ppid,cmd,comm,%mem,%cpu --sort=-%mem | head -10

Change owernship

Below command provides, owernship to user ubuntu to folder /var/www

sudo chown -R ubuntu:ubuntu /var/www/

Do not run it on /etc/

Check ubuntu version

> lsb_release -a

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.6 LTS
Release:        18.04
Codename:       bionic

Find and kill process

Check all running processes with their process ID and name

ps -e 

Then we can find the command we want to kill with grep

ps -e| grep java
ps 1321
kill -9 1321

Open a tar file

The following command will extract the zip file and create a folder project-3

tar -xvf project-3.tar.gz

Create a compressed file

The below command does the exact opposite of the above command, it will create a tar file of the given folder. If you notice the difference in -x and -c. Here -c means create and -x means extract.

tar -cvf project-3.tar.gz project-3/

Set JAVA_HOME in linux

Add the path to JAVA_HOME variable, you can echo and verify the same.

export JAVA_HOME=/opt/openjdk11
echo $JAVA_HOME

Open port

If an application has to access server application running on a specific port, we need to open port.

sudo ufw enable
sudo ufw allow 3306


Icon For Arrow-up
Comments

Post a comment