0% found this document useful (0 votes)
50 views22 pages

Linux List Command

The ls command is used to list files and directories in Linux. It displays the file/directory name by default but can be configured to show additional details like permissions, owner, size, date etc using options like -l, -a, -s, -h. The ls output can be sorted based on name, size, date or extensions using options like -r, -S, -t, -X. Hidden files and directories can be displayed using -a. Directory information alone can be displayed using -d.

Uploaded by

Zinphyothant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views22 pages

Linux List Command

The ls command is used to list files and directories in Linux. It displays the file/directory name by default but can be configured to show additional details like permissions, owner, size, date etc using options like -l, -a, -s, -h. The ls output can be sorted based on name, size, date or extensions using options like -r, -S, -t, -X. Hidden files and directories can be displayed using -a. Directory information alone can be displayed using -d.

Uploaded by

Zinphyothant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Linux Basic Command

List command
Dr. Nyo Nyo Htwe
How do I list or view directories?

o To see directories and files in the current MS-DOS directory, use the dir
command.
o In Linux to view directories and files in the current directory, you'd use the ls
command.
o Long Listing Format
Long Listing Format (ls –l)
 When the long listing format is used, the ls command will display the following file
information:
1. The file type
2. The file permissions
3. Number of hard links to the file
4. File owner
5. File group
6. File size
7. Date and Time
8. File name
ls command options
option description
ls -a list all files including hidden file starting with '.'
ls --color colored list [=always/never/auto]
ls –d/ ls -f list directories/file - with ' */'
ls -i list file's inode index number
ls -l list with long format - show permissions
ls -la list long format including hidden files
ls -lh list long format with readable file size
ls -ls list with long format with file size
ls -r list in reverse order
ls -R list recursively directory tree
ls -s list file size
ls -S sort by file size
ls -t sort by time & date
ls -X sort by extension name
Questions
1. List files/directory with alphabetic order  ls -l
2. list hidden files/directory - ls -a
3. display specific directory information  ls –d tmp
4. display files in human readable format - ls -lh
5. display files/directories with alphabetic reverse order.  ls -r
6. How to sort ls command output with file extensions.  ls -X
7. Display files with file size ls -lS
8. Display all files sorted by size in reverse order ls -lSr
9. Display files only filenames and file sizes  ls –s -h
10. How to make ls hide a particular type of files  ls --hide=*.txt
11. How to change ls command output format  ls --format=comma
12. Display One File Per Line Using ls -1.
13. Display Directory Information Using ls –ld
14. Display directory/files with modification time  ls –lt / ls –ltr (reverse order)
1. List Files using ls with no option
 ls with no option list files and directories in bare format
o where we won’t be able to view details like file types, size, modified date and time,
permission and links etc.
o It lists the contents sorted in alphabetical order.
How to list hidden files/directories
 The ls command doesn't display hidden files/directories by default.
 However, you can force the tool to do that using the -a command-line
option.
Display Specific Directory Information
• You can display specific directory information by using the ls command with -d option. In
the following example,
• it will display information of the /etc directory in the long format:
Display files in Human Readable Format
• To display files in human readable format -h option should be used with ls command. In
the following example,
• the command will display all files in human readable long format:
Display files without color
• You can display files without color by using --color option with ls command like given
below:
How to display files/directories in reverse order

 By default, the ls command displays the files alphabetically in the output.


 The following command with ls -r option display files and directories in
reverse order.
How to sort ls command output based on file extensions

• To sort the ls command output alphabetically based on file extensions, use the -
X command-line option.
Sort Files by File Size
 With combination of -lS displays file size in order, will display big in size first.
Display All Files Sorted by Size in Reverse Order

 To display all files sorted by file size in reverse order -r and -s should be used
with ls command additionally.
 It displays all the files sorted by size in the directory in reverse order:

#ls -lSr
How to make ls display only filenames and file sizes in output

• If you want the ls command output to only contain file/directory names and their
respective sizes, then you can do that using the -h option in combination with -l/-s
command line option.

• ls -s –h

Ls –s Documents
How to display author information
• For this, you have to combine --author option with -l.
List Directory Information

o With ls -l command list files under directory /tmp.


o Wherein with -ld parameters displays information of /tmp directory.
How to make ls specifically indicate the type of file
in the output
This feature can be accessed using the -F option.
1. @ indicates a symbolic link 4. | indicates a named pipe
2. * indicates an executable 5. > indicates a door
3. = indicates a socket file 6. / indicates a directory
How to change ls command output format
o If you want, you can also change the output format for the ls command.
o The tool's --format option lets you do this.
o This option requires you pass a value that indicates the type of output format
you want.
o Available values are: 'verbose' or 'long', 'commas', 'horizontal' or 'across',
'vertical', and 'single-column'.
o For example, use --format=commas when you want a comma-separated output:
How to change ls command output format
o Available values are: 'verbose' or 'long', 'commas', 'horizontal' or 'across',
'vertical', and 'single-column'.
How to make ls hide a particular type of files

• If you want, you can also force the ls command to hide a particular type of files in
output.
• The --hide option (which requires a shell pattern to be passed to it) lets you do this
• ls --hide=*.txt
How to sort files based on modification time
• If you want to quickly know which files or directories were modified recently,
then you can use the ls command's -t option.

 use of the -t option

You might also like