Linux Command Line Tutorial For Beginners 2 - ls command in Linux
Summary
TLDRThis Linux command line tutorial for beginners focuses on the 'ls' command, which lists directory contents. The video demonstrates how to open the terminal, use basic 'ls' syntax, and navigate directories. It explains various options like 'ls -l' for long format listing, 'ls -a' to show hidden files, and sorting by size with 'ls -lS'. The tutorial also covers how to output 'ls' results to a file and use wildcards for file extensions. The presenter encourages viewers to use 'man ls' for comprehensive command reference, aiming to enhance their understanding of directory management in Linux.
Takeaways
- π The 'ls' command in Linux is used to list the contents of files and directories.
- π To open the terminal, press 'Control + Alt + T'.
- π The basic syntax of the 'ls' command includes options followed by the file or directory name.
- π By default, 'ls' without any options lists the contents of the current home directory.
- π Using 'ls' with a directory name as an argument lists the contents of that specific directory.
- π 'ls' followed by a forward slash (/) lists the contents of the root directory.
- π The 'pwd' command shows the current working directory, which is usually the home directory.
- π The 'ls' command with the '-L' option lists files and directories in a long format, showing detailed information such as permissions, size, and creation date.
- π The 'ls' command with the '-a' option reveals hidden files, which start with a dot (.).
- π The 'ls' command with the '-S' option sorts the listed items by size.
- π The 'ls' command can be combined with other options, such as '-aL', to list both hidden files and detailed information.
- π To output the results of the 'ls' command to a file, use redirection with '>' followed by the filename, e.g., 'ls -l > out.txt'.
- π To learn more about the 'ls' command and its options, use the 'man' command followed by 'ls', e.g., 'man ls'.
Q & A
What is the primary function of the 'ls' command in Linux?
-The 'ls' command in Linux is used to list directory contents, including files and directories.
How do you open the terminal in Linux?
-You can open the terminal in Linux by pressing 'Control + Alt + T'.
What is the syntax for using the 'ls' command with options?
-The syntax for using the 'ls' command with options is 'ls [options] [file or directory name].'
What does the 'ls' command display when executed without any options?
-When executed without any options, 'ls' displays the contents of the current directory, which is usually the home directory when the terminal is first opened.
How can you list the contents of a specific directory using the 'ls' command?
-To list the contents of a specific directory, you can use 'ls' followed by the directory name, e.g., 'ls documents'.
What does the 'ls -l' option do?
-The 'ls -l' option lists the directory contents in a long format, showing detailed information such as file permissions, owner, size, and creation date and time.
What does the 'ls -a' option reveal that is not shown by default?
-The 'ls -a' option reveals hidden files, which are files and directories that start with a dot (.) and are not displayed by the regular 'ls' command.
How can you combine options to list both hidden files and detailed information?
-You can combine options by using 'ls -aL' to list both hidden files and detailed information in long format.
What does the 'ls -S' option do when sorting directory contents?
-The 'ls -S' option sorts the directory contents by file size, with the largest files listed first.
How can you output the results of the 'ls' command to a file?
-You can output the results of the 'ls' command to a file by using the '>' operator followed by the filename, e.g., 'ls -lS > out.txt'.
What command can you use to get more information about the 'ls' command and its options?
-You can use the 'man ls' command to get more information about the 'ls' command, including a description and a list of all available options.
Outlines
π Introduction to the 'ls' Command in Linux
This paragraph introduces the 'ls' command in Linux, which is used to list the contents of directories and files. The tutorial begins by instructing viewers on how to open the terminal using the control-alt-T shortcut. It explains the basic syntax of the 'ls' command and demonstrates its use to list the contents of the home directory. The paragraph also covers how to list contents of specific directories by specifying their names and how to verify the current directory using the 'PWD' command. Additionally, it mentions the use of the 'clear' command to clean the terminal screen.
π Exploring Advanced 'ls' Command Options
The second paragraph delves into the advanced options of the 'ls' command. It explains the use of the '-l' option to display files and directories in a long format, which includes detailed information such as user rights, file size, and creation date. The paragraph also discusses navigating directory structures using the '..' notation to move back to parent directories. It further explains how to combine options, such as using '-a' to reveal hidden files and '-l' for a detailed listing, and how to sort directories by size using the capital 'S' option.
π Filtering and Outputting 'ls' Command Results
This paragraph focuses on filtering the output of the 'ls' command using wildcards and flags. It demonstrates how to list files with specific extensions, such as '.html', by using the wildcard '*.html'. The paragraph also covers how to redirect the output of the 'ls' command to a file using the '>' operator, allowing users to save the results for later reference. Additionally, it explains how to list only directories by using the '-d' option and how to use the 'estx' wildcard to match directory names.
π Accessing Comprehensive 'ls' Command Documentation
The final paragraph provides guidance on how to access the full documentation for the 'ls' command using the 'man' command. It emphasizes the importance of the 'man' command as a reference tool for understanding all available options and flags for any Linux command, including 'ls'. The paragraph concludes with instructions on how to exit the 'man' terminal and encourages viewers to explore the documentation to learn more about the 'ls' command and its extensive capabilities.
Mindmap
Keywords
π‘LS command
π‘Terminal
π‘Options
π‘Directory
π‘File
π‘Long format
π‘Hidden files
π‘Sorting
π‘Wildcard
π‘Output redirection
π‘Man pages
Highlights
Introduction to the 'ls' command in Linux, which lists directory contents.
How to open the terminal using the shortcut 'Control + Alt + T'.
Basic syntax of the 'ls' command and its usage with options and file/directory names.
Listing the contents of the current directory with a simple 'ls' command.
Using 'ls' with a directory name to list its contents, such as 'ls documents'.
Listing the contents of the root directory using 'ls /'.
Explanation of the 'PWD' command to display the current working directory.
Using the tilde '~' symbol with 'ls' to represent the home directory.
Clearing the terminal with the 'clear' command.
Navigating back in the directory structure using 'ls ..'.
Using 'ls -L' to list files and directories in long format with detailed information.
Understanding file permissions represented by 'drwxr-xr-x'.
Using 'ls -a' to reveal hidden files starting with a dot.
Combining options 'ls -aL' to list both hidden files and long format details.
Sorting directory contents by size using 'ls -lS'.
Filtering files by extension with a wildcard, such as 'ls *.html'.
Outputting the results of 'ls' to a file using redirection.
Listing only directories with 'ls -D'.
Using the 'man' command to access the manual for more information on 'ls'.
How to exit the manual viewer with 'q' or 'quit'.
Transcripts
hey guys welcome to the next video on
Linux command line tutorial for
beginners and in this video we will
learn about LS command LS is a Linux
shell command that lists directory
contents of files and
directories now first of all let's open
our terminal I have uh told you in the
last video If you press control alt T
then it's going to open your terminal so
just press control alt T to open the
terminal now for the ls command you need
to know some syntax so we all know that
LS command can be given by just writing
LS on the terminal but it has some
options so these options will come in as
a second argument so we can say here
comes the options right and then comes
the file or directory name so you can
say here here comes the file uh or
directory name so you can write FD okay
so LS command comes with options first
and then files and directory now I will
show you what I mean by that so first of
all simple LS command will uh you know
work like this only which list the
content of uh directory so we are uh you
know whenever we open the terminal we
are in the home directory right so we
can just say LS and it will show us the
contents of our home directory which is
uh the desktop or um other document
directory or you know downloads or other
directories the same when you open this
folder when you click here it will also
open the home directory and you will be
able to see all the contents uh of the
directories here so these all the you
know contents are here also so whatever
you see here will be listed here also
okay now the second uh option of using
Lis command is by using a directory uh
name for example we want to see the
contents of uh this document directory
right so our document directory contains
these two files so how we can list uh
the content of this document directory
you can just write LS and then just
write uh documents and then press enter
and it will list all the files which are
there in the documents directory right
in the same way if you want to list out
all the contents in the downloads folder
then I will just say LS downloads okay
and press enter it will show us the
contents of the downloads folder right
so simple now if you want to list out
all the contents of our root folder as I
have shown you in the last video you
just need to give LS and then forward
slash which is our root directory right
and press enter it will show us the
content of our uh root directory and in
here you can verify this by going to
this uh computer option and you can
match all the directories here and here
right now uh by default as I already uh
told you we whenever we open the
terminal we are in the home uh you know
directory right now home directory uh
you can just uh give PWD command and it
will give you what is your home
directory and this is your home
directory right right so you are
presently in your home directory now in
uh uh other the terms when you uh you
know want to uh list out the content of
home directory you can just say LS and
then give this uh till day symbol which
will also give you the same content as
Lis will give you so let's print out Lis
first but uh let me clear all the
commands which I have given earlier so
to clear the terminal you just need to
write clear here so just write clear and
press enter and it will clear your
terminal and clear means your terminal
will be you know blank but when you
scroll up all the you know all the
commands are there so clear means it
will just scroll down a little and it'll
blank out your terminal for you so let's
list out again so LS so it gives me the
content of my home directory and when
whenever you give LS and the till the
symbol this still day also means the
home directory so whenever you press
enter it'll give you the same content
and whenever you do uh LS and you can uh
type the path Pro uh you know by
yourself so home programming knowledge
which is my home directory once again
and when I press enter it will give me
the same uh directory structure right so
there are three command to list out uh
the same thing one is LS which will give
you uh all the contents of your home
directory when you open your terminal
right and then LS till day which will be
uh also giving you the same content so
the till Day means the your home
directory and also your uh you can type
the home directory file path something
like this now let's see some
options so whenever you want to go
inside some directory as I have uh done
so I will just say LS document and uh
you can just list out anything but you
can just write LS and then dot dot and
this dot dot means you want to print out
one step back directory structure right
so whenever you press LS like this it
will give you programming knowledge
because right now we are in home and
then programming knowledge so whenever
we want to uh print the content of Home
folder then uh we just need to give
these two D dots it will tell you just
one folder back right if you want to go
two folders back and you want to list
out the content of uh two folders back
uh content then you can do dot dot and
then forward slash and once again dot
dot and then press enter and and you can
see it will give you your root directory
uh you know directories and file
structure so this will uh you know go to
the root directory because right now we
are in home uh our home you know you
directory so whenever you go one step
back you will be here in your home and
one step back once again you will be in
your root folder okay once again I will
uh clear the screen and then we will
move forward now uh there is uh are some
Flags or options as I told you you can
use with ls files so for example you
give LS minus L and this means you want
to list out all the files and directory
in Long format and when you press enter
it will give you the listings in Long
format let me just uh make it a little
bit bigger and I will give it once again
in this command so clear and LS minus L
and it gives you the you know content in
Long format long format means it will
give you the details uh who is your uh
you know user what are the rights for
this file and what is the size of your
file and at which date this file was
created and the time at which this file
is created right now you may wondering
what is this Dr WXR or what are all
these things so you can see there these
are the user rights so these user rights
are separated by uh this minus uh symbol
so the first uh you know this thing
which is Dr WXR so what does this mean
so d means directory here R means read w
means uh write X means execute and once
again R means write so these are the
rights of the owner owner means so
whoever is logged in so I can uh you
know read WR execute this uh directory
which is desktop right second is the
group right after this minus right so
execute and read are the rights of the
group and then the third is for the
others which is only execute this
directory okay so this is how you can uh
you know list out the long list of files
and directories now there is one more
command which is LS minus a and this
will give you the hidden files also so
this will show you the hidden files also
so just write LS minus a and it will
give give you all the hidden files so
these are dots and double dots and do
Android and Bash history logout do cach
these are all the hidden files so hidden
files in Linux start from dot okay and
they will not be shown here you can see
these uh dot files are not here so
whenever you give LS minus a it will
give you all the hidden files right and
then you can combine uh the options so
you you give LS
minus a for uh showing the hidden file
and then L for showing the long list
then it will give you the hidden file
and long list
com combined okay so press enter it will
give you long list and hidden file right
something like this I will make it a
little bit bigger so you can see it okay
and I will uh just clear the terminal
once again now there are some more
commands for example you can sort
your directory by their size so I will
just give LS minus L for long list and
then when you give capital S it'll sort
your directory by their size so press
enter and you can see the file which has
uh the biggest size is listed first and
then uh this will go down as according
to the size so whatever file has the
lowest size it will be at the bottom and
whatever files or directory has the
biggest size it will go at the top right
so you can sort it something like this
now for example we want to uh you know
list something which uh Only We Know the
extension of so let's uh list for
example uh you can just write LS once
again we will uh list out document list
so just write documents and press enter
and this document has uh this uh
test.html and uh test. CS file but for
example I want to only list out all the
HTML files which are there in the
document folder so what I I can do so I
can just write LS and then I can just uh
write documents and then I will just
give this wild card which is estx so
which uh will be will search for all the
prefix uh which are there right and then
I will just write Dot and then I will
just write HTML so this means I want to
search for all the files which ends with
HTML and then I will press enter and it
only prints out this uh test. HTML which
is correct because we wanted to print
out only HTML files in the other way
when you give uh est. Atrix which means
all the files so whatever all the
extensions and all the names right and
press enter and it will list out these
two files which are there in your
documents directory
right now uh you can also output uh the
content of your LS to a file so for
example I want to uh you know save all
the result which I have listed here to
some file so I will write LS minus for
example L with capital S and then I want
to save all the content to a file so I
can just give this angle bracket and
then the name of the file which uh I
want to uh you know save these content
to so I will just say out.txt by the way
this out.txt is not existing here so it
will create this out.txt and then f fill
all the result of Lis command to this uh
you know out.txt file so this arrow
means the direction of uh the stream so
it'll uh put all the content into the
output right and press enter and you
will be able to see we have one new file
created which is out.txt and when I open
this file then it'll uh just you know
fill all the result of LS minus LS
command to this output file right so you
can do this or you can output the
content of the file also to a file now
the next command is to list out only the
director so for example you want to just
list out only the directories you can
just give uh LS minus D and then you
just need to give uh estx and forward
slash and it will list out all the
direct directory trees okay so you can
see it's not listing out the files but
only the directories right so these are
the all the important commands related
to Lis but this is not all alsis uh is
uh you know having more options and
flags and if you want to know more about
this LS command what you can do so you I
will just clear the terminal first of
all and to know more about this LS
command you you can just write men and
then LS so men is uh you know is a you
can say the dictionary kind of thing for
your Linux commands right and whenever
you give this men command and then uh
give the command name which you want to
see or uh you want to take the reference
of then when you when you click enter
here it'll give you all the options
which you can use with ls so you you can
see LS minus list directory content so
this is the explanation of this and then
you can see all the flags so I have
shown you how to use minus a but I
haven't shown you how to use minus B so
you can find out all the you know
important information what this minus B
does or what this minus C does or what
this minus D does so d as I've shown you
list directory entries right and uh I
have also shown you what L does so I
have only shown you the important
command related to LS but there is a big
list uh which you can uh you know
execute with this LS command so you just
need to write M man and then LS and it
will give you this kind of interface
which you can see the reference right
and you can see at the bottom whenever
you press Q or write quit then you uh
quit this man terminal so I will just
press Q which will quit the uh terminal
right so just remember this man command
if you want to take the reference of all
the all the you know references of
particular commands so I hope you have
enjoyed this video please writ com And
subscribe and bye for
Browse More Related Video
![](https://i.ytimg.com/vi/qrAnlpcMyYc/hq720.jpg)
Lecture 2 - Command line environment
![](https://i.ytimg.com/vi/Qk3Qqj6dCJ0/hq720.jpg)
Basic Linux Commands - CompTIA A+ 220-902 - 2.1
![](https://i.ytimg.com/vi/VbEx7B_PTOE/hq720.jpg)
Linux for Hackers // EP 1 (FREE Linux course for beginners)
![](https://i.ytimg.com/vi/5XgBd6rjuDQ/hq720.jpg)
How to use the Command Line | Terminal Basics for Beginners
![](https://i.ytimg.com/vi/7ff8AjrXGPk/hq720.jpg)
The BEST Variants For TRUE Letz/Vasto/Vizard In Type Soul.
![](https://i.ytimg.com/vi/gd7BXuUQ91w/hq720.jpg)
60 Linux Commands you NEED to know (in 10 minutes)
5.0 / 5 (0 votes)