Introduction to Common Commands in Linux (Directory Commands)

I. Command prompt

[root@localhost ~]#
Among them:

Symbol Meaning
root Current logged-in user
localhost host name
~ Current directory (~Home directory)
# Super User's Prompt (Ordinary User's Prompt is $)

II. Command Format

Command [Options] [Parameters]

Be careful:
Individual commands do not follow this format. When there are multiple options, they can be written in the form of simplified options and complete options (e.g. - a equals - all).

Level of authority

  1. Super user root:
  2. User
  3. User Group
  4. Others

Common directory/file commands

4.1 Query the contents of the directory: ls

ls [Options] [Files or Directories]

[Options] include:
*- a Displays all files, including hidden files
*- l Display details
*- d View the directory's own properties
*- h Humanized Display File Size
*- i Display inode

Enter the command: ls-l and get the result:

[root@localhost ~]# ls -l
//Total dosage 24
-rw-------. 1 root root   953 9month  17 2015 anaconda-ks.cfg
-rw-r--r--. 1 root root 12360 9month  17 2015 install.log
-rw-r--r--. 1 root root  3482 9month  17 2015 install.log.syslog

Explain in the second document:

Column 1: -rw-r-r-r-
Represents the type and permissions of this file.
* The first character represents the file as "directory, file, link file, etc."
Where: [-] represents file [d] represents directory [l] represents soft link file
* In the following characters, there are three groups of permissions, which are all three combinations of parameters of "r w x". The positions of these three permissions are yes. If there is no permission, they are represented by [-], where: [r] stands for readable [w] for writable [x] for executable.
1. The first group is "the permission of the file owner". Take the second file as an example, the owner of the file can read and write, but not execute.
2. The second group is "permission of same user group". Take the second file as an example, the same user group can read, not write and execute.
3. The third group is "the permissions of other non-user groups". Taking the second file as an example, the file is only readable, not writable and executable for non-user groups.

The second column shows how many file names are connected to this node

The third column shows the "owner user account" of the file

The fourth column shows the user groups to which the file belongs.

The fifth column shows the size of the file in B by default.

List 6 shows the date of creation or the latest modification of this file

The seventh is listed as the name of the document.

4.2 Directory Processing Command

1. Create directory mkdir

Mkdir-p [directory name]

  • - p: Represents the recursive creation of directories. If the parent directory does not exist, the parent directory is created first, and then the subdirectory is created.
  • The directory name can be a multi-level directory.

2. Switching directory cd

cd [Directory]

Simplified operation:
* cd ~: Enter the current user's home directory
* cd
* cd -: Enter the last directory
* cd..: Return to the previous directory
* cd.: Enter the current directory

Relative Path and Absolute Path
* Relative path: refer to the current directory, search; when the current directory is different, the entry location may be different;

cd ../user/local
* Absolute path: Start from the root directory, first-level search. In any directory, you can enter the designated location.
cd /etc/learn

3. View the current directory pwd

pwd

4. Delete files or directories rm

  • remove empty directories

    rmdiv [empty directory]

  • (Force) Delete files or directories

    rm [Options] [Files or Directories]
    [Options]:

  • - r: Delete directories
  • - f: Forced deletion, even if the directory is not empty

4. Copy cp

cp [Options] [Original File or Directory] [Target Directory]
[Options]:

  • - r: Copy directory
  • - p: Attribute Copy of Associated Files
  • - d: If the base source file is a link file, the link properties are copied.
  • - a is equivalent to - pdr, and the copy file is exactly the same as the original file.

5. Cut or rename mv

mv [original file or directory] [target directory]

  • If the original file and the target file are in the same directory, it is named operation.
  • If the original file is not in the same directory as the target file, it is a clipping operation.

The Role of Common Catalogues

  • / Root Catalogue
  • / bin command saves directories (commands that ordinary users can read)
  • / boot Start Directory, Start Related Files
  • / dev settings file save directory
  • / etc configuration file save directory
  • / home directory for ordinary users
  • / lib system library save directory
  • / mnt system mount directory
  • / media mounts directories to place removable devices

5.1 Hard Link and Soft Link

1. Characteristics of Hard Links

  • Having the same i node and storage block can be regarded as the same file.
  • It is possible to identify whether two files are hard-linked by i node, and the two file i nodes that are hard-linked are the same.
  • Cannot cross-partition;
  • It can not be used for directories, but only for files.
  • Delete the original file, hard links can also be used;

2. Soft Link Features

  • Similar to Windows shortcuts;
  • Softlink has its own i node and block, but the file name and i node number of the original file are saved in the data block, and there is no actual file data.
  • The first part of viewing the soft link file is: L rwxrwxrwx, whose permissions are rwxrwx, l means that the file is a soft link file;
  • Modify any file, and the other changes.
  • Delete the original file, soft links can not be used;
  • When creating soft links, we must write absolute paths. If we do not write absolute paths, we will find the original files in the directory where the soft links are located, and if we cannot find them, we will report an error.
[root@localhost ~]# ln -s /home/zixuan/test /home/zixuan/learn/test.soft
[root@localhost ~]# ls -l /home/zixuan/learn/
//Total dosage 4
-rw-r--r--. 2 root root 21 5month  18 15:44 test.hard
lrwxrwxrwx. 1 root root 17 5month  18 16:01 test.soft -> /home/zixuan/test
[root@localhost ~]# cat /home/zixuan/test
this is a test file;
[root@localhost ~]# echo 111111 >> /home/zixuan/test
[root@localhost ~]# echo 111111 >> /home/zixuan/test
[root@localhost ~]# cat /home/zixuan/test
this is a test file;
111111
111111
[root@localhost ~]# cat /home/zixuan/learn/test.soft
this is a test file;
111111
111111
[root@localhost ~]# cat /home/zixuan/learn/test.hard
this is a test file;
111111
111111
[root@localhost ~]# ls -l /home/zixuan/learn
//Total dosage 4
-rw-r--r--. 2 root root 35 5month  18 16:06 test.hard
lrwxrwxrwx. 1 root root 17 5month  18 16:01 test.soft -> /home/zixuan/test
[root@localhost ~]# ls -l /home/zixuan/
//Total dosage 12
drwxr-xr-x. 2 root root 4096 5month  18 16:01 learn
-rw-r--r--. 2 root root   35 5month  18 16:06 test
drwxr-xr-x. 2 root root 4096 5month  17 11:41 zm
[root@localhost ~]# rm /home/zixuan/test
rm: Whether to Delete Ordinary Files "/home/zixuan/test"?y
[root@localhost ~]# ls -l /home/zixuan/learn
//Total dosage 4
-rw-r--r--. 1 root root 35 5month  18 16:06 test.hard
lrwxrwxrwx. 1 root root 17 5month  18 16:01 test.soft -> /home/zixuan/test
[root@localhost ~]# cat /home/zixuan/learn/test.hard
this is a test file;
111111
111111
[root@localhost ~]# cat /home/zixuan/learn/test.soft
cat: /home/zixuan/learn/test.soft: No file or directory
[root@localhost ~]# cat /home/zixuan/learn/test.hard
this is a test file;
111111
111111

Keywords: Anaconda Attribute Windows

Added by vombomin on Sun, 30 Jun 2019 04:45:47 +0300