FFmpeg is a powerful multimedia tool that allows you to handle audio, video, and other media files. In this tutorial, we'll go through the steps to install and use FFmpeg on Ubuntu and CentOS using the command line.
Installing FFmpeg on Ubuntu
Open your terminal and run the following command:
Code copied to your clipboard!
Installing FFmpeg on CentOS
Run this command in your terminal:
Code copied to your clipboard!
Using FFmpeg
Once installed, you can use FFmpeg to perform various operations. Here are a few examples:
How to Verify FFmpeg Installation
To check if FFmpeg was installed successfully, you can run the following command:
Code copied to your clipboard!
Basic Usage Examples
Convert video format:ffmpeg -i input.mp4 output.avi
Extract audio:ffmpeg -i input.mp4 -q:a 0 -map a output.mp3
FFmpeg can be a complex tool with a wide array of features. These basic commands should help you get started with common tasks. To explore more features, refer to the official documentation.
Setting up SSH key-based authentication is not only a secure way to connect to remote servers but also highly convenient, especially for automated tasks like crontab jobs. For instance, if you need to copy files between your local server and a remote server for regular backups, using this method ensures seamless operations without the need for manual password entry.
Step 1: Generate an SSH Key Pair
On your local machine (Linux or macOS), generate a new SSH key pair by running the following command:
Code copied to your clipboard!
Follow the prompts and press Enter to save the key to the default location (~/.ssh/id_rsa).
Step 2: Install ssh-copy-id on macOS (If Needed)
On macOS, ssh-copy-id may not be installed by default. You can install it using Homebrew:
Code copied to your clipboard!
Once installed, proceed with copying your public key to the remote server.
Step 3: Copy the Public Key to the Remote Server in Linux
Use the ssh-copy-id command to copy your public key to the remote server:
Code copied to your clipboard!
If the remote server uses a non-default SSH port, specify it using the -p flag:
Code copied to your clipboard!
Step 4: Test the Connection
Once the public key is copied, test the connection to the remote server:
Code copied to your clipboard!
For non-default SSH ports, include the -p flag:
Code copied to your clipboard!
Additional Note: Automating Backups with Crontab
Using key-based authentication is essential for automating tasks like backups. For example, you can use scp or rsync in a crontab job to transfer files securely and without interruption. Here’s a simple crontab entry to copy a file from your local server to the remote server:
Code copied to your clipboard!
For non-default ports, modify the command accordingly:
Code copied to your clipboard!
Conclusion
By setting up SSH key-based authentication, you ensure a secure and hassle-free way to connect to your remote servers. This method is particularly useful for automation tasks like backups using crontab, enhancing both security and convenience.
Creating partitions on your storage devices such as HDDs, SSDs, or NVMe drives is an essential task when managing your system's storage. This guide will show you how to use fdisk to create partitions and then use mkfs to format them. We'll cover partitioning with fdisk and formatting with the ext4 file system as an example. Other file systems like ntfs, xfs, and btrfs will also be mentioned.
Step 1: List Available Disks
Before creating partitions, you should first check the available storage devices. To list the devices attached to your system, use the following command:
Code copied to your clipboard!
The lsblk command will display all attached storage devices, including HDDs, SSDs, and NVMe drives, along with their partitions.
Step 2: Start Partitioning the Disk Using fdisk
Once you identify the disk you want to partition (e.g., /dev/sda), use fdisk to create partitions. Run the following command to start fdisk on the chosen disk:
Code copied to your clipboard!
In this case, replace /dev/sda with the actual disk name. Once in the fdisk interactive mode, you can create partitions.
Step 3: Create a New Partition
Inside the fdisk prompt, you can create a new partition by following these steps:
Type n to create a new partition.
Choose whether to create a primary or extended partition (usually p for primary).
Define the partition size.
Type w to write the changes and exit.
This process will create a new partition on the disk. You can repeat this process for additional partitions if needed.
Step 4: Format the Partition with mkfs
After creating the partition, you will need to format it with a file system. The most commonly used file systems are ext4, ntfs, xfs, and btrfs. To format the partition with ext4, use the following command:
Code copied to your clipboard!
Replace /dev/sda1 with the appropriate partition name. This will format the partition with the ext4 file system.
Other File System Types
Besides ext4, here are other common file systems you can use:
NTFS: Used for Windows systems. To format a partition with NTFS, use sudo mkfs.ntfs /dev/sda1.
XFS: A high-performance file system. To format with XFS, use sudo mkfs.xfs /dev/sda1.
BTRFS: A modern file system with advanced features. To format with BTRFS, use sudo mkfs.btrfs /dev/sda1.
Step 5: Verify the Partition and File System
To verify the new partition and its file system, you can use the lsblk or blkid commands:
Code copied to your clipboard!
Alternatively, to see detailed information, use:
Code copied to your clipboard!
This will display the partition information, including its file system type.
Step 6: Mount the Partition
Once the partition is created and formatted, you'll need to mount it to a directory in your system. Create a mount point:
Code copied to your clipboard!
Then mount the partition:
Code copied to your clipboard!
Replace /dev/sda1 with your partition name and /mnt/mydrive with your desired mount point.
Step 7: Make the Mount Permanent
If you want the partition to be mounted automatically after reboot, you need to add it to the /etc/fstab file. Open the file with a text editor:
Code copied to your clipboard!
Then add the following line:
Code copied to your clipboard!
Replace the partition name, mount point, and file system type if needed.
Conclusion
Creating and formatting partitions is a crucial step in setting up a new disk. By following these steps, you can create partitions using fdisk, format them with the file system of your choice using mkfs, and make them available for use in your system.
When you're working with files on your local machine and need to transfer them to a server, you can use secure and efficient tools like scp (secure copy) or rsync. These commands are simple to use and can make file transfer processes seamless, whether you're working on an Ubuntu or CentOS server.
Step 1: Install Necessary Tools
Both scp and rsync come pre-installed on most Linux distributions. However, if they're not installed, you can easily install them.
For Ubuntu or other Debian-based systems, use the following command:
Code copied to your clipboard!
If you're using CentOS or Red Hat-based systems, use this command:
Code copied to your clipboard!
Step 2: Copying Files with SCP
The scp command is a simple way to securely copy files over SSH. To use scp to transfer a file from your local machine to the server, use this command:
Code copied to your clipboard!
For example, if you want to copy a file named myfile.txt from your local machine to the /var/www/html directory on your server, use:
Code copied to your clipboard!
Step 3: Copying Files with Rsync
The rsync command is another efficient tool for transferring files, and it has additional features like synchronization and incremental backups. Here's how you can use rsync to copy files to your server:
Code copied to your clipboard!
For example, to copy myfile.txt to the /var/www/html directory on your server, use:
Code copied to your clipboard!
Step 4: Verifying the Transfer
Once the file transfer is complete, you can verify it by logging into your server and checking the remote directory.
Code copied to your clipboard!
Use the above command to list the contents of the target directory on the server and confirm that the file is present.
Conclusion
Whether you choose to use scp or rsync, both tools provide a secure and efficient way to copy files from your local machine to a remote server. The choice between the two depends on your specific needs, with rsync offering additional features like incremental file synchronization.
Now you're ready to securely transfer your files from your local machine to your server using the best tools available!