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:
Step 2
It is possible to list the directories in a specific path by running:
dir /path
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
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
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
Step 7
If you want to display the index number of each file, you must use the -i option as follows:
dir -il
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
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
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
step 10
To see the files without the owner(s), we will use the -g option like so:
dir -ahgG /home/user
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
step 12
To print the directories first before the files we execute:
dir -l --group-directories-first
step 13
To see the directories recursively we execute the command using the -R parameter as follows:
dir -R
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
step 15
We add the "n" option for more details:
dir -nl --author
step 16
To see the result separated by commas, we execute using the -m parameter:
dir-am
With this we see how the DIR command is one of the best options to know what directories and files we have in Linux.