Linux learning record 3 -- several commonly used file commands

Posted by fogofogo on Wed, 09 Feb 2022 08:15:28 +0100

preface

This article mainly studies several common file commands, ls, file and less.

1, Some additional information about the command

Options and parameters

Usually, a command is followed by one or more options, and commands with different options have different functions. In addition, the command will be followed by one or more parameters. These parameters are the object of the command (I feel a little similar to calling the function), so most commands look as follows:
command -options arguments
Most commands use the option of adding a hyphen before a single character, such as -; However, many commands also support the long option of adding two hyphens before a single character, and many commands also allow multiple short options to be used together (this is fun).

Long list format

for instance:

drwxr-xr-x  2 yrf-tan yrf-tan     4096 5 June 20-16:30 Documents
drwxr-xr-x  2 yrf-tan yrf-tan     4096 5 June 22:20 Downloads
-rw-r--r--  1 yrf-tan yrf-tan     8980 5 June 18-22:41 examples.desktop
-rw-rw-r--  1 yrf-tan yrf-tan 83325072 5 August 10:29 google-chrome-stable_current_amd64.deb
fieldmeaning
-rw-r-r-- ,drwxr-xr-xAccess to the file. The first character indicates the type of file. Between different types, the "-" at the beginning indicates that the file is an ordinary file and d indicates a directory. The next three characters represent the access rights of the file owner, the next three characters represent the access rights of the members of the group to which the file belongs, and the last three characters represent the access rights of other owners.
1Number of file hard links
Yrf Tan (first)User name of the file owner (yrf Tan is the user name of my computer, and your user name will be displayed on your computer)
Yrf Tan (second)The name of the user group to which the file belongs
4096File size in bytes
16:30, May 20Date and time when the file was last modified
Documentsfile name

2, Several common file commands

1,ls

Purpose: ls you can view the contents of the directory and determine the attributes of various files and directories

Common options for ls command:

optionLong optionmeaning
-a–allList all files, including those starting with a dot, which are usually not listed (such as hidden files)
-d–directoryUsually, if a directory is specified, the ls command lists the contents of the directory rather than the directory itself. Use this option in conjunction with - l to view the details of the directory rather than the contents of the directory.
-F–classifyOption adds a type indicator after each listed name (for example, a slash if the name is a directory name)
-h–human-readableList in long format and display the file size in a human readable manner rather than in bytes
-lDisplay results in long format
-r --reverseDisplay the results in reverse order. Typically, the ls command displays the results in ascending alphabetical order
-SSort results by file size
-tSort by modification time

These commands can also be combined

Output example:
ls:

yrf-tan@yrftan-Lenovo-G50-70m:~$ ls
deepin-wine-for-ubuntu  examples.desktop                        Public     music
Desktop                 google-chrome-stable_current_amd64.deb  Templates
Documents               Music                                   Videos
Downloads               Pictures                                download

ls -a:

yrf-tan@yrftan-Lenovo-G50-70m:~$ ls -a
.                                       Music
..                                      .pam_environment
.bash_history                           Pictures
.bash_logout                            .pki
.bashrc                                 .presage
.cache                                  .profile
.config                                 Public
.dbus                                   .sogouinput
deepin-wine-for-ubuntu                  .sudo_as_admin_successful
Desktop                                 .swo
Documents                               .swp
Downloads                               Templates
examples.desktop                        .thunderbird
.gnupg                                  Videos
google-chrome-stable_current_amd64.deb  .viminfo
.ICEauthority                           .xinputrc
.local                                  download
.mozilla                                music

ls -d:

yrf-tan@yrftan-Lenovo-G50-70m:~$ ls -d
.
yrf-tan@yrftan-Lenovo-G50-70m:~$ ls -d .swp
.swp

ls -F:

yrf-tan@yrftan-Lenovo-G50-70m:~$ ls -F
deepin-wine-for-ubuntu/  google-chrome-stable_current_amd64.deb  Videos/
Desktop/                 Music/                                  download/
Documents/               Pictures/                               music/
Downloads/               Public/
examples.desktop         Templates/

ls -h:

yrf-tan@yrftan-Lenovo-G50-70m:~$ ls -h
deepin-wine-for-ubuntu  examples.desktop                        Public     music
Desktop                 google-chrome-stable_current_amd64.deb  Templates
Documents               Music                                   Videos
Downloads               Pictures                                download
yrf-tan@yrftan-Lenovo-G50-70m:~$ ls --human-readable
deepin-wine-for-ubuntu  examples.desktop                        Public     music
Desktop                 google-chrome-stable_current_amd64.deb  Templates
Documents               Music                                   Videos
Downloads               Pictures                                download

ls -l:

yrf-tan@yrftan-Lenovo-G50-70m:~$ ls -l
total 81436
drwxrwxr-x 17 yrf-tan yrf-tan     4096 5 September 19-22:34 deepin-wine-for-ubuntu
drwxr-xr-x  2 yrf-tan yrf-tan     4096 5 June 20-16:30 Desktop
drwxr-xr-x  2 yrf-tan yrf-tan     4096 5 June 20-16:30 Documents
drwxr-xr-x  2 yrf-tan yrf-tan     4096 5 June 22:20 Downloads
-rw-r--r--  1 yrf-tan yrf-tan     8980 5 June 18-22:41 examples.desktop
-rw-rw-r--  1 yrf-tan yrf-tan 83325072 5 August 10:29 google-chrome-stable_current_amd64.deb
drwxr-xr-x  2 yrf-tan yrf-tan     4096 5 June 20-16:30 Music
drwxr-xr-x  2 yrf-tan yrf-tan     4096 5 June 20-16:30 Pictures
drwxr-xr-x  2 yrf-tan yrf-tan     4096 5 June 20-16:30 Public
drwxr-xr-x  2 yrf-tan yrf-tan     4096 5 June 20-16:30 Templates
drwxr-xr-x  2 yrf-tan yrf-tan     4096 5 June 20-16:30 Videos
drwxr-xr-x  2 yrf-tan yrf-tan     4096 5 June 18-23:13 download
drwxr-xr-x  3 yrf-tan yrf-tan     4096 5 June 18-22:53 music

ls -r:

yrf-tan@yrftan-Lenovo-G50-70m:~$ ls -r
 music       Pictures                                Documents
 download       Music                                   Desktop
Videos     google-chrome-stable_current_amd64.deb  deepin-wine-for-ubuntu
Templates  examples.desktop
Public     Downloads

ls -S:

yrf-tan@yrftan-Lenovo-G50-70m:~$ ls -S
google-chrome-stable_current_amd64.deb  Desktop    Music     Templates  music
examples.desktop                        Documents  Pictures  Videos
deepin-wine-for-ubuntu                  Downloads  Public    download

ls -t:

yrf-tan@yrftan-Lenovo-G50-70m:~$ ls -t
Downloads  Public                  music
Videos     Desktop                 examples.desktop
Pictures   Templates               google-chrome-stable_current_amd64.deb
Music      deepin-wine-for-ubuntu
Documents  download

2,file

Use the file command to determine the file type, because the file name in the Linux system does not need to reflect the file content. When we need to view the short description of a file, we can call the file command, file filename
, after calling, the file command will print out a brief description of the contents of the file. For example:

yrf-tan@yrftan-Lenovo-G50-70m:~$ file Pictures
Pictures: directory

3,less

Use the less command to view the contents of the file. The less command is a program for viewing text files. The less command is used as follows:
less filename
Use the less command to view the file, scroll the file back and forth, and press q to exit the less program.

commandfunction
GJump to the end of the text file
lG or gJump to the beginning of the text file
/charectersFind the specified amount string forward
nLook forward to the next occurrence of the string, which is the previously specified search
hshow this help screen
qExit less

Origin of less command:
The less program is designed to replace the more program in early UNIX. The name less comes from "less is more"

summary

This article mainly introduces some commands ls, file and less for viewing file information, as well as the options and parameters of the command and a description of the long file format.

Topics: Linux