[LINUX] ls command options

What is the ls command?

A command to list the files and folders in your current directory. I typed it even when I was opening the Windows command prompt `'ls' is an internal or external command, It is not recognized as an operable program or batch file. `` There are many people who come out and break the screen.

Overview

I forgot about the ls option and had to look it up several times, so I wrote a note. It's not exhaustive, it's just a memo of what you use. I may add it if the number of frequently used commands increases in the future.

option

One-letter options can be represented at once with a single hyphen. For example, if you want to do ls -a and ls -l at the same time, you can use ls -a -l, but you can do the same with ls -al. -a ls -a displays a list including dot files starting with". ". When using Ubuntu, the command la was used as the same meaning as ls -a, which was very convenient. You can use la anywhere by adding the following alias to the configuration file that is executed when the shell is loaded, such as .bash_profile.

alias la='ls -a'

-l The -l option displays file information. It is convenient to set ll ='ls -l' in the alias.

Example (for files)

-rw-r--r-- 1 seal-qiita naist-student  8 Jun  7 01:22 sample.txt

How to read each section

type/Ownership/Group user permissions/External user permissions, 
Number of hard links,
Owner name,
group name,
file size(B),
Last updated month
Last updated date,
Last updated time,
file name

The first 10-character list is "File type is file (-), own authority is readable and writable (rw-), users in the same group are read-only (r--), external users are read-only ( It means "r--)". "Unexecutable" seems to be applied to binary files (**. Exe, a.out, etc.), and can be executed even if the authority of py files etc. is rw- (Reference / questions / 164297)). The next number indicates "one hard link". A hard link is the number of names that can access the file. For files, it is 1 unless otherwise specified (use the ln command to set it).

Example (for directories)

drwxr-xr-x 3 yuki-yos is-student 32 Oct  5 15:21 sample_dir

How to read each section

type/Ownership/Group user permissions/External user permissions, 
Number of hard links=Number of subdirectories+2,
Owner name,
group name,
The size of the directory itself, not including its contents(B),
Last updated month
Last updated date,
Last updated time,
file name

The first 10-character list is "File type is directory (d), own authority is readable and writable (rwx), users in the same group can read and move (rx), external users can read and move (rx) "means. The directory permission "x" indicates whether to put it in it. A directory with 3 hard links means that it has only one subdirectory. These three hard links are the link to sample_dir in the parent directory (the current location when using ls), . in supplement_dir, and .. in the subdirectory of sample_dir. Since a link to yourself and a . are always present, a directory hard link is defined as" the number of subdirectories plus two. "

I'm not very happy with this notation because I don't know the number of files even if I know the number of hard links. In the first place, I've never been happy to know the number of hard links, but what is the intention of the description? -h An option that displays the file size displayed by -l in the most appropriate unit instead of bytes. For example, if it is 10,000 bytes, it will be automatically converted to 10KB.

Summary

For now, it lists three options: -a, -l, and -h. It's especially easy to forget how to read the -l display, so I hope it helps.

Recommended Posts

ls command options
Frequently used ps command options
Slice notation with command line options
Linux command # 4
Linux command # 3
Command memorandum
nkf command
command prompt
vim command
sed command
Color scheme change when executing LS command
Linux command # 5
grep command
command memo
top command
Command memorandum
Command memo
mv command
seq command
Difference between ls -l and cat command
[Linux command] ls command option list [Must-see for beginners]