Recent Posts

Featured image for How to Allow Root Login in Ubuntu 18.04

How to Allow Root Login in Ubuntu 18.04

In Ubuntu 18.04, the root account is typically disabled for security reasons. However, there might be situations where you need to enable root login temporarily. Please note that enabling root login should be done with caution, and it’s recommended to only do so when absolutely necessary. Here’s a step-by-step guide on how to allow root login in Ubuntu 18.04:

Step 1: Set the Root Password Before enabling root login, you need to set a password for the root account. Open a terminal and run the following command:

Featured image for Introduction to rsync

Introduction to rsync

rsync is a powerful and widely used command-line utility in Unix-like operating systems that facilitates efficient and reliable file synchronization and data transfer between directories or across different machines. It is particularly useful for remote backups, mirroring, and incremental transfers. The name “rsync” stands for “remote synchronization.”

Basic Syncing

Syncing Folder src into dest

To synchronize the contents of a local folder src into another local folder dest, you can use the following command:

Featured image for Working with Tar Compressed Archives in Linux

Working with Tar Compressed Archives in Linux

In Linux, the tar command is commonly used for archiving and extracting files and directories. Tar archives can be compressed to save space using various compression algorithms like gzip (*.tar.gz) or bzip2 (*.tar.bz2). This guide will cover how to create, extract, and work with tar compressed archives in Linux.

Compressing Files and Directories with Tar

1. Create a Tar Archive

To create a tar archive of a folder, use the tar -cvpf command:

Featured image for Compress Each Folder with one archive if archive is not exist

Compress Each Folder with one archive if archive is not exist

The provided command is a shell script written in Bash that iterates through directories in the current directory, checks if an archive file (.tar.gz) already exists for each directory, and if not, it creates a compressed archive of the directory using the tar command.

Here’s an explanation of what the script does:

bash
1
2
3
4
5
for dir in `find . -maxdepth 1 -type d  | grep -v "^\.$" `; do
    if ! [ -e ${dir}.tar.gz ] ; then
        tar -cvzf ${dir}.tar.gz ${dir}
    fi
done
  1. for dir in find . -maxdepth 1 -type d | grep -v “^.$” ; do: This line starts a loop that iterates through all subdirectories (excluding the current directory) in the current directory.

  2. if ! [ -e ${dir}.tar.gz ] ; then: This line checks if an archive file with the name ${dir}.tar.gz does not exist in the current directory.

  3. Inside the if block, tar -cvzf ${dir}.tar.gz ${dir} creates a compressed archive of the current directory (${dir}) with the name ${dir}.tar.gz. Here’s what the options used with the tar command do:

    • -c: Create a new archive.
    • -v: Verbosely list the files processed.
    • -z: Compress the archive using gzip.
    • -f: Specifies the archive file’s name.
  4. The done keyword marks the end of the loop.

Featured image for Delete Except Newest Files Bash

Delete Except Newest Files Bash

The provided Bash commands are useful for listing and deleting files, including dotfiles, except for the newest ones. Here’s a breakdown of what each command does:

List all files except the newest three:

bash
1
ls -t | tail -n +4
  • ls -t: Lists all files in the current directory sorted by modification time in descending order (newest first).
  • tail -n +4: Displays all lines starting from the fourth line. In this context, it shows all files except the newest three.

Delete those files:

bash
1
ls -t | tail -n +4 | xargs rm --
  • xargs: Takes the output from the previous command (the list of files to delete) and passes them as arguments to the rm (remove) command.
  • rm --: Deletes the specified files.

List all dotfiles except the newest three:

bash
1
ls -At | tail -n +4
  • ls -At: Lists all files, including dotfiles, sorted by modification time in descending order.
  • tail -n +4: Displays all lines starting from the fourth line. It shows all dotfiles except the newest three.

Delete dotfiles:

bash
1
ls -At | tail -n +4 | xargs rm --
  • xargs: Takes the output from the previous command (the list of dotfiles to delete) and passes them as arguments to the rm (remove) command.
  • rm --: Deletes the specified dotfiles.

It’s important to use these commands with caution, especially the ones that involve deletion (xargs rm --). Deleting files is irreversible, and there’s no easy way to recover them if you make a mistake. Make sure you’re in the correct directory and that you are certain about the files you want to delete before running these commands.