Monthly Archives: September 2011


High speed HTTP/ HTTPS/ FTP/ BitTorrent/ MetaLink downloads from terminal

aria2c -V --max-concurrent-downloads=7 --ftp-user=useaccount --ftp-passwd=usersecret ftp://useraccount:[email protected]/somefolder/somefile

aria2c is a versatile command line utility that allows the user to download efficiently files using multiple protocols (HTTP/HTTPS/FTP/BitTorrent/MetaLink).


Create a new partition in an LVM filesystem and mount it, resize it and delete it

Managing storage space on Linux servers is a vital aspect of system administration, and the logical volume manager (LVM) is one of the most popular methods of achieving this. The LVM provides an efficient way to manage and organize the storage on a Linux system, allowing administrators to create and manage volumes flexibly. This article aims to explain some essential commands that are commonly used in managing LVM volumes.

1. lvcreate

The lvcreate command creates a new logical volume with a specified size and name. The syntax of the command is:

lvcreate -L size -n name volume_group;

The “size” parameter specifies the size of the logical volume in units like GB, MB, or TB, and the “name” parameter specifies the name of the logical volume. The “volume_group” parameter specifies the name of the volume group in which the logical volume will be created.

For example, to create a new logical volume named “partitionName” with a size of 372.3GB in a volume group named “boxname,” the following command can be used:

lvcreate -L 372.3GB -n partitionName /dev/boxname;

2. mkfs.ext4

The mkfs.ext4 command is used to create a new file system on a specified partition or logical volume. The syntax of the command is:

mkfs.ext4 device;

The “device” parameter specifies the name of the device on which the file system is to be created.

For example, to create an ext4 file system on a logical volume named “partitionName” in the “boxname” volume group, the following command can be used:

mkfs.ext4 /dev/boxname/partitionName

3. mount

The mount command is used to mount a file system to a specific directory in the file system hierarchy. The syntax of the command is:

mount -t filesystem device mountpoint;

The “filesystem” parameter specifies the type of file system to be mounted, the “device” parameter specifies the name of the device containing the file system, and the “mountpoint” parameter specifies the directory to which the file system should be mounted.

For example, to mount the ext4 file system created in the previous step on a directory named “someName” under the “media” directory, the following command can be used:

mount -t ext4 /dev/mapper/boxname-partitionName /media/someName/;

4. lvextend

The lvextend command is used to extend the size of an existing logical volume. The syntax of the command is:

lvextend -L +size device;

The “size” parameter specifies the size by which the logical volume is to be extended, and the “device” parameter specifies the name of the logical volume.

For example, to increase the size of the “partitionName” logical volume by 122.39GB, the following command can be used:

lvextend -L +122.39G /dev/boxname/partitionName;

5. resize2fs

The resize2fs command is used to resize the file system on a specified partition or logical volume. The syntax of the command is:

resize2fs device;

The “device” parameter specifies the name of the device containing the file system.

For example, to resize the ext4 file system on the “partitionName” logical volume after extending its size, the following command can be used:

resize2fs /dev/boxname/partitionName;

6. lvremove

The lvremove command is used to remove an existing logical volume. The syntax of the command is:

lvremove device;

The “device” parameter specifies the name of the logical volume to be removed.

For example, to remove the ext4 file system on the “partitionName” logical volume, the following command can be used:

lvremove /dev/boxname/partitionName;

Other

Following you can find the commands I used to create a new partition on an LVM (Logical Volume Manager) system where during installation there was some hard disk space left empty.

lvcreate -L 372.3GB -n partitionName /dev/boxname
mkfs.ext4 /dev/boxname/partitionName
mount -t ext4 /dev/mapper/boxname-partitionName /media/someName/
#lvextend -L+122.39G /dev/boxname/partitionName
#resize2fs /dev/boxname/partitionName
##lvremove /dev/boxname/partitionName

After creating the partition, we set it’s type – here we used ext4.
Later we mount the partition to a folder to gain access to it.
Following in comments (#) we show how to resize/extend an already existing partition and how to remove it (##) — make sure to remove all brackets before performing these operations.


Add an existing user to an existing group

Add an existing user to secondary/supplementary user group using the -a option

usermod -a -G groupname useraccount;

The usermod command is a Linux utility used to modify the user account information stored in the /etc/passwd and /etc/group files. The -a option is used to append the specified user account to the specified group. The -G option is used to specify the group name that the user account will be added to. The groupname argument is the name of the group that the user account will be added to, and the useraccount argument is the name of the user account that will be added to the group.

In this command, the user account specified by “useraccount” will be added to the group specified by “groupname”. The -a option ensures that the user account will be added to the specified group without removing it from any other groups it may belong to. The -G option specifies that the user account will be added to the specified group as a secondary group.

Once the user account has been added to the specified group, it will have the permissions and access rights associated with that group. For example, if the group has permissions to read and write to certain files or directories, then the user account will also have these permissions once it has been added to the group.

It’s important to note that changes made with the “usermod” command are not applied immediately. The changes will take effect after the next time the user logs in or after a system reboot. Additionally, it’s important to use this command with caution as adding a user to the wrong group could grant unintended access rights to sensitive information.

In conclusion, the usermod -a -G groupname useraccount command is a useful tool for managing user accounts and group memberships in Linux systems. By adding a user account to a specific group, administrators can grant the user access to specific resources and permissions, making it easier to manage and control access to resources on a system.


Get the first column of a file in bash

awk '{print $1}' someFile;

The command awk '{print $1}' someFile is a command that is used to extract specific data from a file in Unix/Linux systems. It uses the awk scripting language, which is a powerful tool for text processing and data manipulation.

The syntax of the command is as follows: awk ‘{print $1}’ someFile. Here, the awk command is followed by a set of instructions in single quotes. The instructions specify what to do with the data in the file someFile. In this case, the instruction is print $1 which means that awk will print the first field or column of each line in the file.

The $1 in the instruction refers to the first field of each line in the file. Fields in an awk file are separated by whitespace or any other specified delimiter. In this case, the default delimiter is whitespace, so each field is separated by a space or tab.

The someFile in the command is the name of the file that the awk command will process. The file can be any text file and can contain any type of data. The awk command will extract the first field of each line in the file and print it on the screen.

In conclusion, the command “awk ‘{print $1}’ someFile” is a powerful tool for extracting specific data from a file in Unix/Linux systems. The awk scripting language provides a flexible and efficient way to process text data and manipulate it to meet specific requirements.

*NOTE: If you want the second column change $1 to $2 etc. $1 can be replaced by a variable and used in a more elaborate way that applies to more cases/problems.