LINUX learning basic chapter directory operation command

Command basic format

command prompt

[root@localhost ~]# 
  • root: represents the currently logged in user.
  • Localhost: short host name of the current system (use the "hostname" command to view the full host name: localhost.localdomain)
  • ~: represents the current directory, the tilde represents the home directory, the super user home directory is "/ root", and the ordinary user home directory is "/ home /"
  • #: command prompt, super user is "#" and ordinary user is "$".

Command basic format

[root@localhost ~]# Command [options] [parameters]
  • Brackets indicate options, which can be added or not, and can be selected according to the actual task
  • Option is used to adjust the function of the command.
  • Parameter is the operation object of the command. If it is not written, it is the default parameter.

give an example

ls command -- list the files in the directory (list)

[root@localhost /]# ls boot
config-4.18.0-338.el8.x86_64                             loader
efi                                                      lost+found
grub2                                                    System.map-4.18.0-338.el8.x86_64
initramfs-0-rescue-54264917d5e142358b6e8ac51ce84000.img  vmlinuz-0-rescue-54264917d5e142358b6e8ac51ce84000
initramfs-4.18.0-338.el8.x86_64.img                      vmlinuz-4.18.0-338.el8.x86_64
initramfs-4.18.0-338.el8.x86_64kdump.img

ls can list the files in the directory.

[root@localhost /]# ls -a boot
.                                                        initramfs-4.18.0-338.el8.x86_64kdump.img
..                                                       loader
config-4.18.0-338.el8.x86_64                             lost+found
efi                                                      System.map-4.18.0-338.el8.x86_64
grub2                                                    vmlinuz-0-rescue-54264917d5e142358b6e8ac51ce84000
initramfs-0-rescue-54264917d5e142358b6e8ac51ce84000.img  vmlinuz-4.18.0-338.el8.x86_64
initramfs-4.18.0-338.el8.x86_64.img                      .vmlinuz-4.18.0-338.el8.x86_64.hmac

ls -a can list all files in the directory including hidden files, and a "." will be added before the file name of hidden files, Indicates that the file is hidden. The separate ".." indicates the current directory and "..." indicates the parent directory. These two directories will exist in each folder.

[root@localhost /]# ls -l boot
 Total consumption 162447
-rw-r--r--. 1 root root   193903 8 June 27-13:41 config-4.18.0-338.el8.x86_64
drwxr-xr-x. 3 root root     1024 10 15:00:17 efi
drwx------. 4 root root     1024 10 15:00:19 grub2
-rw-------. 1 root root 84003612 10 15:00:19 initramfs-0-rescue-54264917d5e142358b6e8ac51ce84000.img
-rw-------. 1 root root 29018916 10 15:00:20 initramfs-4.18.0-338.el8.x86_64.img
-rw-------. 1 root root 28405760 10 15:00:51 initramfs-4.18.0-338.el8.x86_64kdump.img
drwxr-xr-x. 3 root root     1024 10 15:00:17 loader
drwx------. 2 root root    12288 10 15:00:12 lost+found
-rw-------. 1 root root  4254963 8 June 27-13:41 System.map-4.18.0-338.el8.x86_64
-rwxr-xr-x. 1 root root 10218632 10 15:00:18 vmlinuz-0-rescue-54264917d5e142358b6e8ac51ce84000
-rwxr-xr-x. 1 root root 10218632 8 June 27-13:41 vmlinuz-4.18.0-338.el8.x86_64

ls -l means to list the details of the files in the directory.

[root@localhost /]# ls -al boot
 Total consumption 162455
dr-xr-xr-x.  6 root root     1024 10 15:00:51 .
dr-xr-xr-x. 18 root root     4096 10 15:00:19 ..
-rw-r--r--.  1 root root   193903 8 June 27-13:41 config-4.18.0-338.el8.x86_64
drwxr-xr-x.  3 root root     1024 10 15:00:17 efi
drwx------.  4 root root     1024 10 15:00:19 grub2
-rw-------.  1 root root 84003612 10 15:00:19 initramfs-0-rescue-54264917d5e142358b6e8ac51ce84000.img
-rw-------.  1 root root 29018916 10 15:00:20 initramfs-4.18.0-338.el8.x86_64.img
-rw-------.  1 root root 28405760 10 15:00:51 initramfs-4.18.0-338.el8.x86_64kdump.img
drwxr-xr-x.  3 root root     1024 10 15:00:17 loader
drwx------.  2 root root    12288 10 15:00:12 lost+found
-rw-------.  1 root root  4254963 8 June 27-13:41 System.map-4.18.0-338.el8.x86_64
-rwxr-xr-x.  1 root root 10218632 10 15:00:18 vmlinuz-0-rescue-54264917d5e142358b6e8ac51ce84000
-rwxr-xr-x.  1 root root 10218632 8 June 27-13:41 vmlinuz-4.18.0-338.el8.x86_64
-rw-r--r--.  1 root root      166 8 June 27-13:40 .vmlinuz-4.18.0-338.el8.x86_64.hmac

ls -a and ls -l can be used together to list the details of all files in the directory, expressed as "ls -al".

Directory operation command

ls(List)

Function: lists information about the directory
Common options:

optioneffect
-aLists all files including hidden files.
-dOnly the directory itself is listed.
-hList the file sizes in a readable manner.
-iList inode codes.
-lDetailed information display, including file permissions, attributes and other information.

Execution Authority: all users

cd(Change Directory)

Function: switch directory
Simplified usage:

Special symbolseffect
~Home directory. When you use cd directly, it defaults to home directory.
-Go back to the last working directory.
.Current directory.
. .Parent directory.

Execution Authority: all users
Related knowledge: absolute path and relative path

  • Absolute path: use the root directory as a reference to enter the required directory level by level.
  • Relative path: refers to the current directory.

pwd(Print Working Directory)

Function: view the current working directory and display the absolute path.

mkdir(Make Directories)

Function: create directory.
Execution permission: all users.
Common options: - p recursively create the desired directory.
Example:

[root@localhost ~]# mkdir -p 123/234
[root@localhost ~]# ls
123  anaconda-ks.cfg
[root@localhost ~]# cd 123
[root@localhost 123]# ls
234
[root@localhost 123]# cd 234
[root@localhost 234]# pwd
/root/123/234

rmdir(Remove Empty Directories)

Function: delete empty directory.
Because rmdir is "clumsy" and can only delete empty directories, it is generally not used, and the rm command is generally used to delete directories. rm -r can delete folders, but will frequently ask. rm -rf can be deleted directly, but cannot be recovered. Because Linux does not have a recycle bin like Windows, in order to avoid accidental deletion, the open source software extundelete can be installed in the system. It is possible to reply to the deleted files, and it needs to be installed before deletion.

ps: Shang Silicon Valley linux video course Learning notes, part from "bird's Linux private dishes"

Keywords: Linux Operation & Maintenance bash

Added by harishkumar09 on Wed, 05 Jan 2022 09:52:39 +0200