How To Mount A Windows NTFS Disk In Linux

How To Mount A Windows NTFS Disk In Linux The New Technology File System (NTFS) is a proprietary file system created by Microsoft and is used extensively in Microsoft’s Windows operating systems.By default, a lot of Linux distributions will not be able to mount NTFS, though it is possible to install a driver which allows us to do this so that we are able to read and write data to an NTFS disk.In the example below, we will attach the VMDK file from a Windows-based virtual machine to a CentOS 7 Linux virtual machine.Once we run ‘fdisk –I’, we can see that the disk is recognized (after a system reboot), but it is not yet mounted for us to access the data. We should be able to see the primary disk for the Linux system /dev/sda, while /dev/sdb is our 1GB NTFS disk, which has the /dev/sdb1 NTFS partition. [[email protected] ~]# fdisk -l Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x0004c930 Device Boot Start End Blocks Id System /dev/sda1 * 2048 616447 307200 83 Linux /dev/sda2 616448 4810751 2097152 82 Linux swap / Solaris /dev/sda3 4810752 41943039 18566144 83 Linux Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0xfc757b2a Device Boot Start End Blocks Id System /dev/sdb1 128 2091135 1045504 7 HPFS/NTFS/exFAT By default, once we attempt to mount the NTFS disk, we will receive the error below: [[email protected] ~]# mkdir /windows [[email protected] ~]# mount /dev/sdb1 /windows/ mount: unknown filesystem type 'ntfs' Install Required Packages If you want to perform the mount, you have to install the NTFS-3G package, which is a Linux NTFS userspace driver. This package will arrive from EPEL if you are using CentOS/RHEL, so if you have not yet configured your system to use the EPEL repository, run the command below: [[email protected] ~]# yum install epel-release -y Now we will be able to install the ntfs-3g package from the EPEL repository. [[email protected] ~]# yum install ntfs-3g -y Otherwise, if you are using Ubuntu/Debian, you will be able to simply run ‘apt-get install ntfs-3g’ straight away. In our Debian 8 installation, it was already available, so we were able to mount NTFS without any issues. Mount The NTFS Disk We can now successfully perform the mount without any errors. [[email protected] ~]# mount /dev/sdb1 /windows/ [[email protected] ~]# blkid /dev/sdb1 /dev/sdb1: LABEL="NTFS" UUID="CA4A1FD94A1FC0DD" TYPE="ntfs" We can confirm that the NTFS disk is seen as mounted by the operating system. [[email protected] ~]# df -h /windows/ Filesystem Size Used Avail Use% Mounted on /dev/sdb1 1021M 11M 1011M 2% /windows At this point, you will be able to read and write data to the mounted NTFS disk. Automatically Mount NTFS We may now create an entry in the /etc/fstab file, so that our NTFS disk will automatically mount on system boot. Below, you’ll see an example of the entry that I have placed in my fstab file. This will mount the disk to the /ntfs directory. /dev/sdb1 /windows ntfs-3g defaults 0 0 After this configuration has been added, the NTFS disk should mount automatically on system boot. Before performing a reboot, it is recommended that you first run the ‘mount –a’ command and confirm that the disk mounts without any issues. If any issues occur during boot, you will be left with a system that does not properly boot, so it’s important to test first. Summary We have seen that it is possible to easily mount an NTFS disk in CentOS 7 Linux once the ntfs-3g package, which provides us with the necessary drivers, has been installed.

By | Aug 6

How to Change Permissions and Owners via Command Line

How to Change Permissions and Owners via Command Line Introduction In this tutorial, we will teach you how to change file or folder permissions and owners using a command line on Linux or Unix systems. There are two simple commands that can be used to accomplish this task; they are Chmod and Chown.   Change Permissions and Owners via Command Line For this guide you will require the following:– Access to the command line Step 1 — Changing file and folder permissions via command line Chmod is a command that is used to change the permissions of a file or a folder.Simply put, each file has three types of users who can interact with it: Owner – The user who made and owns the file or directory. Group – Each user who is also a member of the group. Others – Every other user on the system who are neither a member or an owner of the group. The command ‘ls -1’ can be used to view file permissions and owners of a file or folder. For example, ‘1s and -1 file1.txt’ will display: -rwxr–rw- 1 user user 0 Jan 19 12:59 file1.txt ‘-rwxr–rw-‘ - This is the part of the line which shows permissions. There are 4 main letters which you will usually see in this part of the line: r,w,x,d. The letter ‘d’ means that the type of the file is a directory.1 –  This is the number of hard links. A hard link is just an extra name for a file which already exists.User user – This helps you view who the owner and group owner of the file is.0 – This shows how big the file is.Jan 19 12:59 – This is the date of the last edit.File1.txt – This shows the name of the file or folder.Let’s return to the command ‘Chmod’. This command grants us the ability to change the permissions of a file or  folder. We will show you how to do this by simply appending numbers. Each permission type will have its own number: r(read) – 4 w(write) – 2 x(execute) – 1 For example, if we would like to set the permissions of ‘file1.txt’ to those: -rwxr–rw- 1 user user 0 Jan 19 12:59 file1.txt We would have to type the command: chmod 746 file1.txt User Permissions Every number in the command represents a permission for one of the user types, such as the owner, group owner, or others.‘chmod 777 file2.txt’ is a different example, this command will grant every permission for every type of user (owner, group, or other).This is a list of the most common permissions for files:  -rw——- 600 Owner can read and write.  -rw-r–r– 644 Owner can read and write, the group and others can read.  -rw-rw-rw- 666 Owner, group and others can read and write.  -rwx—— 700 Owner can read, write and execute, group and others cannot do anything with the file.  -rwx–x–x 711 Owner can read, write and execute, the group and others can execute.  -rwxr-xr-x 755 Owner can read, write and execute, the group and others can read and execute. rwxrwxrwx 777 Owner, group and others can read, write and execute. The usual permissions for directories: drwx—— 700 Only owner can read and write in this directory. drwxr-xr-x 755 Owner, group and others can read the directory, but only owner can change its contents. There are plenty of ways to change permissions of a file using the chmod command. However, our suggestion is to learn one of them and use it each time; in this situation, the numbering way. Step 2 — Changing file and folder owners via command line Chown is a command that is used to change the owners of a file or a folder. The most basic syntax of the Chown command is this: chown [owner/group owner] [file name] Usually, if we have a file called ‘demo.txt’ and would like to set the owner and group owner of the file to ‘Jerry’ and ‘clients’ respectively, we would use the command below: chown jerry:clients demo.txt As you can see, the owner and group owner are separated using a colon symbol ‘:’. If the goal was to change the owner of the file only, then we would use the command below: chown jerry demo.txt In the command above, we left out the group owner, instead only typing in the new owner of the file; in this way, the group owner will stay unchanged.If we wanted to change the group owner of the file but not the owner, then we would use the command below: chown :clients demo.txt In this case, only the group owner has been changed to ‘clients’, leaving the owner unchanged. Step 3 — Using additional options with chmod and chown commands There’s one way which should work with both commands, it is ‘–R’ in which the R stands for recursive.This option allows you to replace the permissions or owners in the given directory and all other files and folders within that directory. Different options for “chmod” and “chown”: “-f” – Silent, stealthy, and simple. Force is not going to show most error messages. “-v” – Will provide you with a diagnostic of every file which has been affected by the command. “-c” – This is similar to ‘-v’. However, it will only provide information in a case where changes were actually made. Conclusion Using the skills we have taught you in this guide, you will be able to manage your Server or VPS in a more simple manner by changing permissions and owners of files and folders with a command line.

By | Aug 6

How To Compress And Decompress Files In Linux

How To Compress And Decompress Files In Linux Compression How to Compress and decompress files in Linux...Compressing is a very useful process when backing up important files as well as sending large files over the internet.Remember that compressing an already compressed file adds extra overhead, hence, you will receive a slightly bigger file. For this reason, do not compress a compressed filed. There are lots of programs that you can use to compress and decompress files in GNU/Linux. In this tutorial, we will teach you about two applications only. Compress and decompress files in Linux The most common programs that are used to compress files in Unix-like systems are: gzip bzip2 Compress and decompress files using Gzip program ‘gzip’ is a utility which will help you compress and decompress files with ‘Lemepel-Ziv’ coding (LZ277 algorithm. 1.1 Compress files To compress a file called ‘dreamvps.txt’, replacing it with a gzipped compressed version, execute the following command. $ gzip dreamvps.txt Gzip should replace the original file ‘dreamvps.txt’ with a gzipped compressed version called ‘dreamvps.txt.gz'.You can also use the ‘gzip’ command in different ways.One good example is that we can create a compressed version of a particular command’s output. Look at the command below. $ ls -l Downloads/ | gzip > dreamvps.txt.gz The command above will create a compressed version of the directory listing of Downloads folder. 1.2 Compress files and write the output to different files (Don’t replace the original file) By default, the ‘gzip’ program will compress any given file, replacing it with a gzipped compressed version. You can, however, keep the original file and enter the output to standard output. For instance, the command below will compress ‘dreamvps.txt’ and will also enter the output to ‘output.txt.gz’. $ gzip -c dreamvps.txt > output.txt.gz Similarly, to decompress a gzipped file specifying the output filename. $ gzip -c -d output.txt.gz > dreamvps1.txt The command above will decompress the ‘output.txt.gz' file and will enter the output to ‘dreamvps1.txt’ file. In both cases, it will not delete the original file. 1.3 Decompress files In order to decompress the file ‘dreamvps.txt.gz’, you will need to replace it with the original uncompressed version; our example will use the following. $ gzip -d dreamvps.txt.gz You can also use gunzip to decompress the files. $ gunzip dreamvps.txt.gz 1.4 View contents of compressed files without decompressing them If you want to view the contents of the compressed file using gzip with out decompressing it, use ‘–c’ flag like shown below. $ gunzip -c dreamvps1.txt.gz Alternatively, you can also use the ‘zcat’ utility like in the following. $ zcat dreamvps.txt.gz You could also pipe the output to ‘less’ command to view the output page by page like below. $ gunzip -c dreamvps1.txt.gz | less $ zcat dreamvps.txt.gz | less Alternatively, there is a ‘zless’ program which will do the same function as the pipeline above. $ zless dreamvps1.txt.gz   1.5 Compress file with gzip by specifying compression level Another notable advantage of ‘gzip’ is; it will support compression level. It will support 3 compression levels like shown below: 1– Fastest (Worst) 9– Slowest (Best) 6– Default level To compress a file called ‘dreamvps.txt’, you will need to replace it with a gzipped compressed version with ‘best’ compression level, you will need to use the following. $ gzip -9 dreamvps.txt   1.6 Concatenate multiple compressed files It is also possible to concatenate several compressed files into one. You can see how by looking at the examples below. $ gzip -c dreamvps1.txt > output.txt.gz $ gzip -c dreamvps2.txt >> output.txt.gz The two commands above will compress ‘dreamvps1.txt’ and ‘dreamvps2.txt’ then will save them in one file called ‘output.txt.gz’.You may view the contents of both files (‘dreamvps1.txt’ and ‘dreamvps2.txt’) without extracting them using any one of the following commands. $ gunzip -c output.txt.gz $ gunzip -c output.txt $ zcat output.txt.gz $ zcat output.txt The ‘bzip2’ is quite similar to the gzip program, however, it uses a different compression algorithm called the ‘Burrow-Wheeler block sorting text compression’ algorithm, and Huffman coding. The files compressed using ‘bzip2’ will end with a ‘.bz2’ extension.As we have stated, the usage of ‘bzip2’ is almost the exact same as gzip. Simply replace ‘gzip’ in the example above with ‘bzip2’, ‘gunzip’ with ‘bunzip2’, ‘zcat’ with ‘bzcat' and so on.To compress a file with ‘bzip2’, replace it with a compressed version, run the below. $ man gzip In the case that you do not want to replace the original file, use the ‘–c’ flag and enter the output to a new file. $ bzip2 dreamvps.txt To decompress a compressed file, use the below. $ bzip2 -c dreamvps.txt > output.txt.bz2 Or the below. $ bzip2 -d dreamvps.txt.bz2 To view the contents of a compressed file without having to decompresses it, the below. $ bunzip2 -c dreamvps.txt.bz2 Or the below. $ bzcat dreamvps.txt.bz2 For more details, refer man pages. $ man bzip2 Final Thoughts: In this tutorial, we have taught you about gzip and bzip2 programs and how to use them to compress and decompress files with some examples in GNU/Linux. Cheers!

By | Aug 9