Linux Beginner’s Guide Part 3

4 minutes read

Working With Files

Creating Files

The touch command is used to create files of any type, for example you can create test.txt, test.jpg, test.doc but only specialized software can read and create content in these file types.


go to Documents directory: cd ~/Documents/

and create a few test files: touch

view the files created: ls

As you can see touch command can be used to create multiple files at once.

Editors like vi, vim and nano can be also used to create files, but we will learn later in this tutorial about them.

Creating Folders

The mkdir command can be used to create folders. The basic structure is:

mkdir [OPTIONS] folder

Let’s create a few folders in /Documents/ directory:

cd ~/Documents/
mkdir example example1 example2

One nice feature of mkdir command is that you can create full paths using argument -p:

mkdir -p example3/example/inside/example
cd example3
cd example

Moving Files

The mv command is used to move a file from a place to another one. The mv command can have two arguments: source and destination. The source is the place where the file is located and destination is the place where the file should be moved.


Switch to the Documents directory:

cd ~/Documents

Move file into Work directory, the file is the [SOURCE] and the directory is the [DESTINATION]:

mv Work

ls Work

mv command can be used also to move and in same time rename the file.

mv Work

The mv command can be used to rename a file in the same directory:


With mv command multiple files can be moved at same time.

mv Work

Copying Files

Making copies of a file is very useful and they can be created as a backup, as a template or can be transfered to different media types.


Use the command below to get to the Documents directory:

cd ~/Documents

The cp command is used to copy files and is similar to mv command, it requires at least these two arguments:  [SOURCE] [DESTINATION]

Let’s say we have to copy /etc/passwd to the current directory:

cp /etc/passwd .

The second argument is the . (dot) which represents the current directory, acts like a shortcut.

Please note that permissions have impact on commands like cp, it is necessary to have execute permissions to access the directory and read permissions on the file being copied and also you must have write and execute permissions on the directory where the file will be copied.

dd command is a utility that copies files or entire partitions at bit level.


dd command is very useful for:

-deleting or cloning entire disks or partitions; -copying raw data to external devices like memory sticks, CDs, DVDs, and so on; -backup and restoring of Master boot record (MBR); -creating a file with a specific size filled with zeros, which can be used as swap file (virtual memory);

Let’s create, with the dd command,  a file named /tmp/buffer with 100 blocks of zeros that are 1MB in size:

dd if=/dev/zero of=/tmp/buffer bs=1M count=100

Below you can find the description of a few arguments that dd uses:

if = input file = the input file to be read from

of = output file = the output file to be writen

bs = block size (block size units: K, M, G, T)

count = the number of blocks to be read from the input file

To clone from hard drive to another bs or count must not be specified.

dd if=/dev/sda of=/dev/sdb

Removing Files

rm command is used to delete files and directories. Please keep in mind that if you delete the files they are not moved to “Trash”, they are removed permanently.


To remove a file use the following command: rm linux.txt

To remove a directory use the following command: rm -r linux

Permissions have impact on commands like rm. To delete files within a directory, the user must have execute and write permissions on this directory.

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

Related Posts:

Many Linux commands deal with sensitive data like system hardware, passwords or operate under exceptional circumstances. Prevents regular users from executing these commands by mistakes and helps to protect data and system integrity. By logging in as root enab...
Microsoft loves Linux so much that its latest operating system is based on Linux. Azure Sphere OS is designed to run on embedded devices and IoT. Source: Microsoft’s Newest OS is Based on Linux – OMG! Ubuntu!
In terms of stability and security, Linux is ranked the most stable operating system and at the same time, it’s quite easy to maintain and support. One of the reasons why Linux web hosting has gained popularity is its easily accessible configuration files and ...
Ubuntu is an open-source operating system developed by the San microsystems. Linux allows users and in this case developers to make changes to the program without prior authorization from the creator. You can gather a deeper understanding of Ubuntu Linux from ...
A Linux operating system is quite different from a Windows operating system. They run off of different open-source operating systems such as Fedora and many more. Although they are not popular amongst regular users, many developers feel that a Linux laptop can...
grep command is a text filter that searches for the input and returns the text lines by a given pattern. In order to start the example, use the following command to get to the /Documents/ folder: cd ~/Documents