+5 votes
81 views
Linux DIR command | Examples and what it is for

in Linux/Unix by (552k points)
reopened | 81 views

1 Answer

+3 votes
Best answer

How to use DIR command in Linux

The use of commands in Linux is one of the actions that we carry out on a daily basis for informational, management, installation or process tasks with services or the users themselves, each command is key in Linux and one of the best known and most important is the dir command. Basically the dir command generates information about the files and directories either in the current path or in any path that we indicate, TechnoWikis will fully explain how to use dir in Linux and for this case we will use Ubuntu..

 

Addr Parameters
The general usage parameters of DIR are as follows:

 

  • -a, --all: Do not ignore entries starting with . (hidden)
  • -A, --almost-all: do not list the values ​​of . Y ..
  • --author: together with the -l value prints the author of each file
  • -b, --escape: print C style for non-graphic characters
  • -block-size=SIZE: allows defining sizes at the time of the result
  • -B: do not add implicit entries ending in ~
  • -C: generates the result by columns
  • -d, --directory: list directories but not their content
  • -D, --dired: create output designed for Emacs directed mode
  • --format=WORD: arrange output by horizontal -x, commas -m, horizontal -x, long -l, single column -1, verbose -l, vertical -C
  • -g: do not show the owner of the file
  • --group-directories-first: group directories before files
  • -G, --no-group: don't print group names
  • -h: apply a user-readable format
  • -i, --inode: list the index number of each file
  • -l: use a long list format
  • -m: output the result with a comma-separated list of entries
  • -n, --numeric-uid-gid: Allows you to list the numeric IDs of users and groups
  • -N: print input names without quotes
  • -o: do not list group information
  • --show-control-chars: display non-graphic characters
  • -Q: is responsible for enclosing the names of the entries in double quotes
  • -R, --recursive: list subdirectories recursively
  • -s, --size : print the allocated size of each file in blocks
  • -S: sort by file size with largest first
  • -U: do not list entries in directory order
  • -x: list entries by lines instead of by columns

 

 

 

 

To stay up to date, remember to subscribe to our YouTube channel!   SUBSCRIBE ON YOUTUBE

 

 

How to use DIR command in Linux

 

 

Step 1

We open the terminal and execute "dir" without parameters to list the current directory:

 

image

 

Step 2

It is possible to list the directories in a specific path by running:
 dir /path 
image

 

Step 3

It is possible to list one file per line for a clearer display, in this case we must use the -1 option as follows:
 dir -1 /path 
image

 

Step 4

It is possible to list all the files in a directory and include the hidden ones in the result, for this we will use the -a option as follows:
 will tell 
image

 

Note
on Linux hidden directories are preceded with a dot (.), for example .ssh.

 

step 5

It is possible to use “dir -al” for some more information displayed.
We can list only the directory entries but not the contents of the directory, for this we can use the -d option like this:
 dir -d /path 
step 6

To add details like owner, group owner and permissions, we can use the -dl parameter which shows a long list of the directory:
 dir -dl /path 
image

 

 

Step 7

If you want to display the index number of each file, you must use the -i option as follows:
 dir -il 
image

 

 

step 8

There we will see the number of files and in the first column we see the inode (index nodes or index numbers), this inode in Linux is basically a type of file system data storage in which file information is stored minus its name real data. It is possible to see the file sizes using the -s option:
 dir -shl 
image

 

Note
the -h parameter allows us to see the file sizes in a readable format for us and the size is expressed in Kilobytes (K), now we can organize by size in the desired path:
 dir -ashlS /home/user 
image

 

 

step 9

To sort the files by modification time so that the most recently modified file is first in the list, we must use the -t parameter:
 dir -ashlt /home/user 
image

 

step 10

To see the files without the owner(s), we will use the -g option like so:
 dir -ahgG /home/user 
image

 

 

step 11

With this result neither the owner of the file nor the owner of the group is printed, if we want to see the author of the file we will use the --author parameter:
 dir -al --author /home/user 
image

 

step 12

To print the directories first before the files we execute:
 dir -l --group-directories-first 
image

 

 

step 13

To see the directories recursively we execute the command using the -R parameter as follows:
 dir -R 
image

 

 

step 14

the sign (.) indicates that the current directory and the user's home directory have subdirectories.
To see the data with user and ID group we execute the following:
 dir -l --author 
image

 

step 15

We add the "n" option for more details:
 dir -nl --author 
image

 

 

step 16

To see the result separated by commas, we execute using the -m parameter:
 dir-am 
image

 

With this we see how the DIR command is one of the best options to know what directories and files we have in Linux.

 

 


by (3.5m points)
edited

Related questions

+3 votes
1 answer
asked Jan 26, 2023 in Linux/Unix by backtothefuture (552k points) | 79 views
+5 votes
1 answer
asked Oct 13, 2023 in Linux/Unix by backtothefuture (552k points) | 53 views
+3 votes
1 answer
+5 votes
1 answer
asked Jul 27, 2023 in Linux/Unix by backtothefuture (552k points) | 57 views
+3 votes
1 answer
asked Feb 6, 2023 in Linux/Unix by backtothefuture (552k points) | 80 views
Sponsored articles cost $40 per post. You can contact us via Feedback

Most popular questions within the last 30 days

10,659 questions
10,791 answers
510 comments
3 users