Work with files and directories in Linux

As you know, working in Linux is based on operations with files and directories: searching for, moving, viewing and copying them. Therefore, these skills are necessary for every user who wants to work successfully in Linux OS. This article will help you understand all these issues and feel confident in the "communication" with Linux.

Basic operations are performed in console mode.

To create a directory, just type “mkdir” and the name of the folder after it. Deletion occurs in the same way, only instead of “mkdir” you specify “rmdir”.

You can find out the name of the current directory by using “pwd”. To display its contents, use "ls". It looks like this:

pwd / home / a / newdirectory

ls / home / a / newdirectory

After the command, write the path to the directory you need.

To view all the information about the directory you are interested in, use the –l key for “ls”.

Ls lists the contents of the folder in alphabetical order. If you need to sort it by date or in reverse order, use the –t and –lrt keys respectively.

As for working with files, it consists of three simple steps:

  • copying;
  • moving;
  • deletion.

Copying is performed by the command “cp”, move - “mv”, and delete - “rm”.

Just list the command and the full file name along with its extension, on which you want to perform some action. For example:

cp file1.bkp

When moving, also specify the destination directory:

mv file1.bkp newdirectory

Now let's figure out how to perform a search in Linux. The “find” command will help us in this, which allows you to perform a search according to all possible criteria: by type, owner, date or last access. For example:

find.-name "myfile"

You can also search by the presence of any particular character in the name. Let's try to find all the files whose name contains the letter “z”:

find.-name "* z *"

To clarify the search criteria by type, specify the keys: -f (files), -d (directories):

find.-type f

To search for a given size, enter:

find.-size and then the number corresponding to the size. By adding “c” or “k”, you can set the value in bytes or kilobytes, respectively.

Compression is done using gzip and bzip2. They are absolutely identical in function, except gzip allows you to save a name as well as a timestamp.

To create an archive, use the command "tar". For extended work, prescribe keys:

-c - create archive;

-x - unpacking;

-v - display a list of archived files;

-z - compress with gzip;

-j - bzip2 compression.

The cpio command is useful for extracting data from the archive.

Now you are familiar with the basics of working with files and directories. Leave your feedback about this article and ask all your questions on the topic.