How to install the Ubuntu system?

  1. Download Ubuntu ISO file: Visit the official Ubuntu website (https://ubuntu.com/download) and download the latest version of Ubuntu ISO file. Make sure to download the appropriate version for your system architecture (32-bit or 64-bit).

  2. Create a bootable USB drive: Create a bootable USB drive by using a tool like Rufus, Unetbootin, or Etcher. This will allow you to boot into Ubuntu from the USB drive and install it on your system.

  3. Boot from USB drive: Insert the bootable USB drive into your system and reboot your computer. Make sure to select the USB drive as the boot device from the BIOS settings.

  4. Choose Ubuntu installation: In the initial Ubuntu installer, select the option to install Ubuntu. You can also choose to try Ubuntu without installing it, if you want to test it out first.

  5. Select language and keyboard settings: Choose your preferred language and keyboard layout.

  6. Select installation type: Select the installation type according to your preference. You can choose to erase your entire disk and install Ubuntu, or you can choose to install Ubuntu alongside your current operating system.

  7. Create User Account: Create a new user account with a username and password.

  8. Wait for installation to complete: Once you have completed all the previous steps, just sit back and wait for the installation to complete. When the installation is finished, remove the USB drive and restart your computer.

Congratulations, you have successfully installed Ubuntu!Ubuntu!

How to compress and decompress files on Linux?

To compress and decompress files on Linux(Ubuntu), you can use the following commands:

Compress files

To compress a file or directory, you can use the tar command.

1
tar -czvf archive_name.tar.gz file_or_directory_name

The options used in this command are:

  • -c: create a new archive
  • -z: compress the archive with gzip
  • -v: show the progress while archiving
  • -f: specify the filename for the archive

For example, to compress a directory named my_folder, you can use the following command:

1
tar -czvf my_folder.tar.gz my_folder

This command will create a new compressed file named my_folder.tar.gz.

Decompress files

To decompress a file or directory, you can use the following command.

1
tar -xzvf archive_name.tar.gz

The options used in this command are:

  • -x: extract files from archive
  • -z: uncompress the archive with gzip
  • -v: show the progress while extracting
  • -f: specify the filename of the archive

For example, to decompress the my_folder.tar.gz file that we created earlier, you can use the following command:

1
tar -xzvf my_folder.tar.gz

This command will extract the contents of my_folder.tar.gz to a directory named my_folder.

How to use cron scheduled tasks for planning work on Ubuntu?

Cron is a built-in scheduling tool in Ubuntu that allows you to schedule tasks to run automatically at specified times and dates. Here are the steps to set up cron jobs in Ubuntu:

Open the terminal: Press Ctrl+Alt+T or search for “Terminal” in the Ubuntu launcher.

Check the cron service status: Run the following command in the terminal to see if the cron service is running or not:

sudo service cron status

Install or update cron: Use the following command to install cron if it is not already installed or to update if it is outdated:

sudo apt-get install cron

Edit crontab: Once you have installed cron, you can edit the crontab file to specify the tasks that need to be scheduled. Use the following command to edit the crontab file:

1
crontab -e

This will open the crontab file in the default text editor. The syntax for specifying a cron job is as follows:

1
2
3
4
5
6
7
8
* * * * * /path/to/command
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday is both 0 and 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

Add a cron job: Once you have opened the crontab file, you can add a new line to schedule a task. For example, if you want to run a script named myscript.sh every day at 10:30 AM, you can add the following line:

1
30 10 * * * /path/to/myscript.sh

Here, 30 specifies the minute, 10 specifies the hour, and * * * specifies that the task should run every day of every month.

Save and exit: Once you have added the cron job, save and exit the crontab file.

Verify the output: To check the output of the scheduled tasks, you can redirect the output to a log file. For example, you can modify the cron job in step 5 as follows:

1
30 10 * * * /path/to/myscript.sh >> /path/to/logfile.log 2>&1

Here, >> appends the output to the log file, and 2>&1 redirects any error messages to the same log file.

That’s it! You have successfully set up a cron job in Ubuntu to schedule a task. You can use cron to automate many repetitive tasks, such as backups, system updates, and running scripts.

Show current time with python

Here’s a Python 2 code snippet that shows the current time in the format of YYYY-MM-dd HH:mm:ss:

1
2
3
4
5
6
import datetime

now = datetime.datetime.now()
current_time = now.strftime("%Y-%m-%d %H:%M:%S")

print(current_time)

First, we import the datetime module, which gives us access to the date and time-related functions in Python. Then, we call datetime.datetime.now() to get the current date and time, and store it in the now variable.

Next, we use the strftime() method to format the date and time as a string. In this particular case, we’re using the format string “%Y-%m-%d %H:%M:%S”, which represents the year, month, and day in the format of YYYY-MM-DD, followed by the hours, minutes, and seconds in the format of HH:mm:ss.

Finally, we print the formatted date and time to the console using the print() function. The output will be in this format: 2016-05-13 10:40:10

How to transfer files to Linux on Ubuntu?

There are several ways to transfer files to a Linux machine on Ubuntu16.04. Here, we will cover two common methods:

Using scp command: scp stands for secure copy and encrypts the data during transfer. To use scp, open a terminal and type the following command:

1
scp /path/to/local/file.zip root@192.168.1.10:/data/file.zip

Replace /path/to/local/file with the path to the file you want to transfer, username with the username of the remote machine, remote with the IP address of the remote machine, and /path/to/destination with the path to the destination directory.

You may also specify the port number to use using the -P option:

1
scp -P 22  /path/to/local/file.zip  root@192.168.1.10:/data/file.zip

Or you can use tool like FileZilla to connect to your Linux machine via SSH/SFTP and transfer files. (Windows)

How to configure SSH on Ubuntu?

To configure SSH login on Ubuntu16.04, follow these steps:

Install OpenSSH: OpenSSH is a free implementation of the SSH as well as SFTP protocols. To install it, type the following command in the terminal:

1
sudo apt-get install openssh-server
1
sudo vi /etc/ssh/sshd_config

Configure SSH Options: You can configure SSH options using an editor (such as nano or vim) to update the following file: /etc/ssh/sshd_config. Here are some important options to consider:

Port: Change the default SSH port (22) to a non-default, secure port using the Port option.
PermitRootLogin: Disable remote SSH root login by changing it to no.
PasswordAuthentication: Disable password authentication and only allow public-key authentication by changing it to no.
Restart OpenSSH service: After modifying the /etc/ssh/sshd_config file, apply your changes by restarting the OpenSSH service:

1
sudo systemctl restart sshd

Add SSH keys: After configuring SSH options, you may want to add public SSH keys to allow secure access from remote computers to your Ubuntu16.04 server.

On the remote computer, create an SSH key:

1
ssh-keygen -t rsa

Copy the public key to your Ubuntu server:

1
ssh-copy-id username@192.168.1.10

Test the SSH connection:

1
ssh username@192.168.1.10

Note: Replace username with the appropriate user on your Ubuntu system, and target_server_ip with the appropriate IP address.

Now, you should be able to log in to your Ubuntu16.04 server via SSH from a remote computer using the private SSH key associated with the public key added earlier.rlier.