How to do Directory and File Organization in Linux OS

Directory and File Organization

Directory and File Organization: Learn effective strategies for organizing directories and files in the Linux operating system. Discover essential Linux file management techniques to boost productivity.

Scenario: –

A few files have accumulated in your home directory, and you have decided that it is time to organize things. You plan to create several new subdirectories, and to copy and move your files around to fit into your new scheme. Additionally, you have several files that are not needed at all, which must be deleted.

Deliverable:

A more organized home directory, with files placed into the appropriate subdirectories.

Instructions: –

  1. Log in as user with the password. If you are using the graphical environment, start a terminal.
  1. Immediately after logging into the system, you should be in your home directory. Verify this using the “printer working directory” command.
    amar@amar-pc:~$ pwd
    /home/amar
  1. Check to see if you have any files in your home directory using each of the following commands:
    ls
    ls -a
    ls -al

    Why do the first and second command return different numbers of files?
    Ans: – ls returns fewer files than ls -a because the -a option includes files whose names begin with a period. Such files are usually used for storing configuration information and are not included in directory listings by default.

    What is the size of the largest file currently in your home directory as reported by the third command?
    The fifth column of ls -l’s output displays the file’s size.
Directory and File Organization
Directory and File Organization
Directory and File Organization
  1. You will now use touch to create the files needed for this sequence. The details of how the expansion used in the following command works will be covered in a later Unit. For now, simply type the following line exactly as you see it (with the curly braces {} included, and an underscore character between the first two groups of sets):

    amar@amar-pc:~/Desktop$ touch {report,graph}_{jan,feb,mar}
Directory and File Organization
  1. Use the ls command to examine the results of the previous command. You should find that it created the following six ne, empty files in your home directory.

    amar@amar-pc:~/Desktop$ ls
Directory and File Organization
  • These files represent the data files that you will use in the remainder of this sequence. If for some reason you do not see these files, ask the instructor for assistance; without these files, the remainder of this lab will not work.
  1. In order to organize your files you must first crate some new directories. Use mkdir to create a few directories. As you change directories, below, be sure to check that your working directory is as expected.

    amar@amar-pc:Desktop$ mkdir Projects
    amar@amar-pc:Desktop$ mkdir Projects/graphs
    amar@amar-pc:Desktop$ cd Projects/
    amar@amar-pc:Projects$ mkdir reports
    amar@amar-pc:reports$ cd reports
    amar@amar-pc:reports$ mkdir ../backups
Directory and File Organization
  • use ls to examine your work:

    amar@amar-pc:reports$ cd
    amar@amar-pc:~$ cd Desktop/
    amar@amar-pc:Desktop$ ls -l
Directory and File Organization
  1. Begin by moving all of the graph files into the graphs subdirectory of the Projects directory. Do this in two steps: in the first steps: in the first step, move one file; in the second step, move two files:

    amar@amar-pc:Desktop$ mv graph_jan Projects/graphs/
    amar@amar-pc:Desktop$ mv graph_feb graph_mar Projects/graphs/
    amar@amar-pc:Desktop$ ls -l Projects/graphs/
    total 3
    -rw-rw-r-- 1 amar amar 0 Oct 31 03:29 graph_feb
    -rw-rw-r-- 1 amar amar 0 Oct 31 03:29 graph_jan
    -rw-rw-r-- 1 amar amar 0 Oct 31 03:29 graph_mar
  1. Next, move two of the “report” files into the reports subdirectory of the Projects directory.
    Move the files in one command:

    amar@amar-pc:Desktop$ ls -l Projects/reports
    total 2
    -rw-rw-r-- 1 amar amar 0 Oct 31 03:29 report_feb
    -rw-rw-r-- 1 amar amar 0 Oct 31 03:29 report_jan

  1. Remove the remaining report file:

    amar@amar-pc:Desktop$ rm report_mar
    amar@amar-pc:Desktop$ ls
    Projects

  1. Change into the Backups directory and copy the January files into this directory. Copy one using an absolute pathname and the other using a relative pathname:

    amar@amar-pc:Backups$ cd
    amar@amar-pc:~$ cd Desktop/
    amar@amar-pc:Desktop$ cd Projects/Backups/
    amar@amar-pc:Backups$ pwd
    /home/amar/Desktop/Projects/Backups
    amar@amar-pc:Backups$ cp ../reports/report_jan .
    amar@amar-pc:Backups$ cp /home/amar/Desktop/Projects/graphs/graph_jan .
    amar@amar-pc:Backups$ ls -l
    total 2
    -rw-rw-r-- 1 amar amar 0 Oct 31 03:54 graph_jan
    -rw-rw-r-- 1 amar amar 0 Oct 31 03:54 report_jan
    amar@amar-pc:Backups$


    The trailing dot is the destination: the present working directory.
  1. Log out or close your graphical terminal by running the exit command.

Keyword:-

  • Linux file organization
  • Directory structure
  • Linux file management
  • File organization tips
  • Linux OS organization
  • Linux directory structure

Leave a Comment