Linux_logo_errorbits.comWorking 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.

Useful links:

Linux Directory Map / Structure

Introduction to Linux

Using Help in Linux

Download and install Oracle VirtualBox

How to install CentOS on Oracle VirtualBox