Linux Command Line Tutorial For Beginners 2 - ls command in Linux

ProgrammingKnowledge
5 Jun 201617:15

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

00:00

πŸ“ 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.

05:02

πŸ” 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.

10:04

πŸ”Ž 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.

15:07

πŸ“š 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

The 'LS' command is a fundamental command in the Linux operating system that is used to list the contents of files and directories. In the context of the video, it is the central focus, with the tutorial explaining its basic usage and various options to manipulate directory listings. For example, the script mentions using 'LS' to display the contents of the home directory and other directories such as 'documents' or 'downloads'.

πŸ’‘Terminal

The terminal is a command-line interface for interacting with the Linux operating system. The script instructs viewers to open the terminal using 'Control + Alt + T' and demonstrates how to execute commands within it. The terminal is the primary environment where the 'LS' command and other Linux commands are executed.

πŸ’‘Options

In the script, 'options' refer to the various flags and arguments that can be used with the 'LS' command to modify its behavior, such as listing files in long format or including hidden files. The video explains how to use these options to customize the output of the 'LS' command, enhancing the user's ability to navigate and understand directory contents.

πŸ’‘Directory

A 'directory' in Linux is a folder that contains files and other directories. The script explains how to use the 'LS' command to list the contents of directories, such as the home directory or specific folders like 'documents'. Directories are a fundamental concept in Linux file system organization.

πŸ’‘File

Files are the basic units of storage in a Linux system, containing data and having attributes like size and creation date. The video script uses the 'LS' command to list files within directories, demonstrating how to view and sort files based on their properties, such as size or extension.

πŸ’‘Long format

The 'Long format' is an option in the 'LS' command, denoted by '-L', which provides a detailed listing of files and directories, including permissions, ownership, size, and creation date. The script illustrates how to use this option to get more information about the items in a directory, such as in the example where 'LS -L' is used to list the contents of the 'documents' directory.

πŸ’‘Hidden files

In Linux, 'hidden files' are files that start with a dot ('.') and are not displayed by default when using the 'LS' command. The script explains how to use the '-a' option with 'LS' to show these hidden files, which can include configuration files and system files that are typically not meant to be modified by the user.

πŸ’‘Sorting

The script introduces the concept of 'sorting' directory contents by size using the 'LS' command with the '-S' option. This allows users to organize files in order of their size, which can be useful for managing disk space or finding large files quickly.

πŸ’‘Wildcard

A 'wildcard' is a character used in command-line operations to match multiple files or directories based on a pattern. In the script, the wildcard '*.html' is used with the 'LS' command to list only files that end with the '.html' extension, demonstrating a way to filter and search for specific types of files.

πŸ’‘Output redirection

Output redirection is a technique in Linux to send the output of a command to a file instead of the terminal. The script shows how to use the '>' symbol with the 'LS' command to save its output to a file named 'out.txt', which can be useful for creating backups of directory listings or for later review.

πŸ’‘Man pages

Man pages, or manual pages, are the documentation for commands in Linux. The script mentions the 'man' command as a way to access detailed information about the 'LS' command and its options. This is an important resource for users to learn more about any command's functionality and usage.

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

play00:00

hey guys welcome to the next video on

play00:02

Linux command line tutorial for

play00:04

beginners and in this video we will

play00:06

learn about LS command LS is a Linux

play00:11

shell command that lists directory

play00:14

contents of files and

play00:16

directories now first of all let's open

play00:19

our terminal I have uh told you in the

play00:22

last video If you press control alt T

play00:26

then it's going to open your terminal so

play00:28

just press control alt T to open the

play00:31

terminal now for the ls command you need

play00:34

to know some syntax so we all know that

play00:38

LS command can be given by just writing

play00:42

LS on the terminal but it has some

play00:44

options so these options will come in as

play00:48

a second argument so we can say here

play00:52

comes the options right and then comes

play00:56

the file or directory name so you can

play00:59

say here here comes the file uh or

play01:03

directory name so you can write FD okay

play01:07

so LS command comes with options first

play01:11

and then files and directory now I will

play01:14

show you what I mean by that so first of

play01:18

all simple LS command will uh you know

play01:22

work like this only which list the

play01:25

content of uh directory so we are uh you

play01:30

know whenever we open the terminal we

play01:32

are in the home directory right so we

play01:35

can just say LS and it will show us the

play01:38

contents of our home directory which is

play01:42

uh the desktop or um other document

play01:45

directory or you know downloads or other

play01:48

directories the same when you open this

play01:51

folder when you click here it will also

play01:54

open the home directory and you will be

play01:56

able to see all the contents uh of the

play01:59

directories here so these all the you

play02:02

know contents are here also so whatever

play02:05

you see here will be listed here also

play02:09

okay now the second uh option of using

play02:14

Lis command is by using a directory uh

play02:19

name for example we want to see the

play02:21

contents of uh this document directory

play02:25

right so our document directory contains

play02:29

these two files so how we can list uh

play02:32

the content of this document directory

play02:34

you can just write LS and then just

play02:37

write uh documents and then press enter

play02:42

and it will list all the files which are

play02:44

there in the documents directory right

play02:47

in the same way if you want to list out

play02:49

all the contents in the downloads folder

play02:52

then I will just say LS downloads okay

play02:56

and press enter it will show us the

play02:59

contents of the downloads folder right

play03:02

so simple now if you want to list out

play03:06

all the contents of our root folder as I

play03:08

have shown you in the last video you

play03:10

just need to give LS and then forward

play03:13

slash which is our root directory right

play03:16

and press enter it will show us the

play03:19

content of our uh root directory and in

play03:22

here you can verify this by going to

play03:24

this uh computer option and you can

play03:27

match all the directories here and here

play03:30

right now uh by default as I already uh

play03:34

told you we whenever we open the

play03:37

terminal we are in the home uh you know

play03:40

directory right now home directory uh

play03:44

you can just uh give PWD command and it

play03:47

will give you what is your home

play03:50

directory and this is your home

play03:53

directory right right so you are

play03:55

presently in your home directory now in

play03:58

uh uh other the terms when you uh you

play04:02

know want to uh list out the content of

play04:05

home directory you can just say LS and

play04:08

then give this uh till day symbol which

play04:11

will also give you the same content as

play04:14

Lis will give you so let's print out Lis

play04:17

first but uh let me clear all the

play04:20

commands which I have given earlier so

play04:24

to clear the terminal you just need to

play04:26

write clear here so just write clear and

play04:29

press enter and it will clear your

play04:31

terminal and clear means your terminal

play04:34

will be you know blank but when you

play04:37

scroll up all the you know all the

play04:40

commands are there so clear means it

play04:42

will just scroll down a little and it'll

play04:45

blank out your terminal for you so let's

play04:49

list out again so LS so it gives me the

play04:52

content of my home directory and when

play04:55

whenever you give LS and the till the

play04:58

symbol this still day also means the

play05:01

home directory so whenever you press

play05:03

enter it'll give you the same content

play05:06

and whenever you do uh LS and you can uh

play05:11

type the path Pro uh you know by

play05:14

yourself so home programming knowledge

play05:17

which is my home directory once again

play05:19

and when I press enter it will give me

play05:21

the same uh directory structure right so

play05:25

there are three command to list out uh

play05:28

the same thing one is LS which will give

play05:31

you uh all the contents of your home

play05:34

directory when you open your terminal

play05:37

right and then LS till day which will be

play05:40

uh also giving you the same content so

play05:43

the till Day means the your home

play05:45

directory and also your uh you can type

play05:49

the home directory file path something

play05:52

like this now let's see some

play05:55

options so whenever you want to go

play05:58

inside some directory as I have uh done

play06:01

so I will just say LS document and uh

play06:06

you can just list out anything but you

play06:09

can just write LS and then dot dot and

play06:13

this dot dot means you want to print out

play06:17

one step back directory structure right

play06:20

so whenever you press LS like this it

play06:23

will give you programming knowledge

play06:26

because right now we are in home and

play06:29

then programming knowledge so whenever

play06:32

we want to uh print the content of Home

play06:34

folder then uh we just need to give

play06:38

these two D dots it will tell you just

play06:41

one folder back right if you want to go

play06:45

two folders back and you want to list

play06:47

out the content of uh two folders back

play06:51

uh content then you can do dot dot and

play06:54

then forward slash and once again dot

play06:56

dot and then press enter and and you can

play07:00

see it will give you your root directory

play07:03

uh you know directories and file

play07:05

structure so this will uh you know go to

play07:10

the root directory because right now we

play07:13

are in home uh our home you know you

play07:17

directory so whenever you go one step

play07:19

back you will be here in your home and

play07:22

one step back once again you will be in

play07:25

your root folder okay once again I will

play07:28

uh clear the screen and then we will

play07:31

move forward now uh there is uh are some

play07:36

Flags or options as I told you you can

play07:38

use with ls files so for example you

play07:41

give LS minus L and this means you want

play07:46

to list out all the files and directory

play07:48

in Long format and when you press enter

play07:51

it will give you the listings in Long

play07:53

format let me just uh make it a little

play07:57

bit bigger and I will give it once again

play07:59

in this command so clear and LS minus L

play08:03

and it gives you the you know content in

play08:06

Long format long format means it will

play08:09

give you the details uh who is your uh

play08:13

you know user what are the rights for

play08:17

this file and what is the size of your

play08:20

file and at which date this file was

play08:23

created and the time at which this file

play08:26

is created right now you may wondering

play08:30

what is this Dr WXR or what are all

play08:34

these things so you can see there these

play08:38

are the user rights so these user rights

play08:42

are separated by uh this minus uh symbol

play08:46

so the first uh you know this thing

play08:50

which is Dr WXR so what does this mean

play08:55

so d means directory here R means read w

play09:01

means uh write X means execute and once

play09:04

again R means write so these are the

play09:07

rights of the owner owner means so

play09:11

whoever is logged in so I can uh you

play09:14

know read WR execute this uh directory

play09:18

which is desktop right second is the

play09:22

group right after this minus right so

play09:25

execute and read are the rights of the

play09:28

group and then the third is for the

play09:31

others which is only execute this

play09:33

directory okay so this is how you can uh

play09:38

you know list out the long list of files

play09:42

and directories now there is one more

play09:45

command which is LS minus a and this

play09:48

will give you the hidden files also so

play09:52

this will show you the hidden files also

play09:55

so just write LS minus a and it will

play09:58

give give you all the hidden files so

play10:01

these are dots and double dots and do

play10:03

Android and Bash history logout do cach

play10:08

these are all the hidden files so hidden

play10:10

files in Linux start from dot okay and

play10:14

they will not be shown here you can see

play10:16

these uh dot files are not here so

play10:20

whenever you give LS minus a it will

play10:23

give you all the hidden files right and

play10:26

then you can combine uh the options so

play10:28

you you give LS

play10:31

minus a for uh showing the hidden file

play10:34

and then L for showing the long list

play10:38

then it will give you the hidden file

play10:40

and long list

play10:42

com combined okay so press enter it will

play10:46

give you long list and hidden file right

play10:48

something like this I will make it a

play10:50

little bit bigger so you can see it okay

play10:53

and I will uh just clear the terminal

play10:55

once again now there are some more

play10:58

commands for example you can sort

play11:02

your directory by their size so I will

play11:06

just give LS minus L for long list and

play11:10

then when you give capital S it'll sort

play11:13

your directory by their size so press

play11:16

enter and you can see the file which has

play11:20

uh the biggest size is listed first and

play11:24

then uh this will go down as according

play11:28

to the size so whatever file has the

play11:31

lowest size it will be at the bottom and

play11:34

whatever files or directory has the

play11:36

biggest size it will go at the top right

play11:38

so you can sort it something like this

play11:41

now for example we want to uh you know

play11:45

list something which uh Only We Know the

play11:48

extension of so let's uh list for

play11:52

example uh you can just write LS once

play11:55

again we will uh list out document list

play11:58

so just write documents and press enter

play12:02

and this document has uh this uh

play12:05

test.html and uh test. CS file but for

play12:09

example I want to only list out all the

play12:11

HTML files which are there in the

play12:14

document folder so what I I can do so I

play12:17

can just write LS and then I can just uh

play12:20

write documents and then I will just

play12:23

give this wild card which is estx so

play12:26

which uh will be will search for all the

play12:29

prefix uh which are there right and then

play12:32

I will just write Dot and then I will

play12:35

just write HTML so this means I want to

play12:38

search for all the files which ends with

play12:42

HTML and then I will press enter and it

play12:45

only prints out this uh test. HTML which

play12:49

is correct because we wanted to print

play12:51

out only HTML files in the other way

play12:55

when you give uh est. Atrix which means

play12:59

all the files so whatever all the

play13:01

extensions and all the names right and

play13:05

press enter and it will list out these

play13:07

two files which are there in your

play13:10

documents directory

play13:12

right now uh you can also output uh the

play13:17

content of your LS to a file so for

play13:21

example I want to uh you know save all

play13:25

the result which I have listed here to

play13:28

some file so I will write LS minus for

play13:32

example L with capital S and then I want

play13:36

to save all the content to a file so I

play13:38

can just give this angle bracket and

play13:42

then the name of the file which uh I

play13:45

want to uh you know save these content

play13:48

to so I will just say out.txt by the way

play13:52

this out.txt is not existing here so it

play13:55

will create this out.txt and then f fill

play13:59

all the result of Lis command to this uh

play14:03

you know out.txt file so this arrow

play14:06

means the direction of uh the stream so

play14:09

it'll uh put all the content into the

play14:12

output right and press enter and you

play14:15

will be able to see we have one new file

play14:19

created which is out.txt and when I open

play14:22

this file then it'll uh just you know

play14:26

fill all the result of LS minus LS

play14:30

command to this output file right so you

play14:34

can do this or you can output the

play14:36

content of the file also to a file now

play14:40

the next command is to list out only the

play14:44

director so for example you want to just

play14:46

list out only the directories you can

play14:48

just give uh LS minus D and then you

play14:52

just need to give uh estx and forward

play14:55

slash and it will list out all the

play14:57

direct directory trees okay so you can

play15:00

see it's not listing out the files but

play15:03

only the directories right so these are

play15:06

the all the important commands related

play15:09

to Lis but this is not all alsis uh is

play15:13

uh you know having more options and

play15:16

flags and if you want to know more about

play15:19

this LS command what you can do so you I

play15:22

will just clear the terminal first of

play15:24

all and to know more about this LS

play15:28

command you you can just write men and

play15:31

then LS so men is uh you know is a you

play15:36

can say the dictionary kind of thing for

play15:39

your Linux commands right and whenever

play15:42

you give this men command and then uh

play15:45

give the command name which you want to

play15:47

see or uh you want to take the reference

play15:50

of then when you when you click enter

play15:53

here it'll give you all the options

play15:55

which you can use with ls so you you can

play15:58

see LS minus list directory content so

play16:01

this is the explanation of this and then

play16:04

you can see all the flags so I have

play16:06

shown you how to use minus a but I

play16:08

haven't shown you how to use minus B so

play16:11

you can find out all the you know

play16:13

important information what this minus B

play16:16

does or what this minus C does or what

play16:18

this minus D does so d as I've shown you

play16:22

list directory entries right and uh I

play16:25

have also shown you what L does so I

play16:28

have only shown you the important

play16:30

command related to LS but there is a big

play16:34

list uh which you can uh you know

play16:36

execute with this LS command so you just

play16:39

need to write M man and then LS and it

play16:42

will give you this kind of interface

play16:44

which you can see the reference right

play16:47

and you can see at the bottom whenever

play16:49

you press Q or write quit then you uh

play16:53

quit this man terminal so I will just

play16:56

press Q which will quit the uh terminal

play16:59

right so just remember this man command

play17:03

if you want to take the reference of all

play17:06

the all the you know references of

play17:09

particular commands so I hope you have

play17:11

enjoyed this video please writ com And

play17:13

subscribe and bye for

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
Linux TutorialCommand LineBeginners GuideLS CommandDirectory ListingFile ManagementTerminal UsageOpen SourceScript AnalysisEducational Content