Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

File directory command, a novice at the beginning of linux foundation

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article focuses on directory-related basic commands, all of which are demonstrated using screenshots of redhat server 8.0 and centos 7.

Let's talk about a few concepts and basic commands before we talk about orders.

1. Log in to the system

After power on, the system looks like this.

Then fill in according to the account and password you set, and if you change it like this, you will log in successfully:

2. Command prompt

Such as the last line in the figure above, there is a parenthesis plus a dollar sign, this is the command prompt. This means that we can now write commands and run them.

In [sun@sunny ~] $, the first character sun represents the user name, @ is the delimiter, sunny is the host hostname, and ~ represents the home directory (

The average user's home directory is / home/username,root user's home directory is / root. This place actually shows the current working directory, and the default working directory for booting is in / home/username. The following prompts usually have two:

$is represented as a user with normal permissions

# indicated as administrator root privilege user

Who

It is used to see what is online, which tty is used and how long it takes to log in.

Whoami

Used to view the user name currently in use.

3. Switch user su

The command to switch the user is the su,Linux su command, which is used to change the identity of another user. In addition to root, you need to type the user's password. All users have permission to use this command.

Su

Enter directly, use the password to switch to the identity of root permissions, but will not change the working directory and will not change the environment variables. As shown in the figure:

At this point, the current command prompt has changed to #, but we are still in the / home/sun working directory, which means that the environment variables have not changed.

Su-(su-l)

Su plus a dash, su -, use this command to switch to the root account and change the working directory environment. As shown in the figure:

In addition to switching to the root user, it can also receive root or other user names, and the same can be switched over. Option-l is full switch, pay attention to the difference between the following figure:

4. # pwd (print work directory)

The pwd command displays the current working directory. Execute the pwd directive to immediately know the absolute path name of your current working directory. For example, the previous command su is used repeatedly.

-p displays the actual directory.

5 、 # man

The man command is the help instruction under Linux. Through the man instruction, you can view the instruction help, configuration file help and programming help and other information in Linux. You can use man [commands] to view the documentation for each command, such as man cp. But when we use man to find it, the command has multiple chapters.

The whatis command can see how many duplicate chapters there are. Man-f is equivalent to whatis.

Want to read a chapter of the manual directly man chapter number command such as, man 1 ls.

The contents of each chapter are as follows, and the more important one is 1pm 5pm 8:

1. User command (/ bin,/usr/bin,/usr/local/bin)

2. System call tool

3. Library call / bin. A library is an advanced call that encapsulates one or more kernel calls, which cannot be executed directly and has no execution entry, so it can only be called.

4. Special files, device files, as entrances for access, such as tty

5. File format configuration files such as passwd modify password, / etc/passwd

Explain the syntax of the configuration file

6. Games

7. Miscellaneous miscellaneous

8. Management commands (/ sbin, / usr/sbin, / usr/local/sbin)

9. Kernel-related files

N, Tcl, or Tk instruction

In the man manual, different symbols have different uses:

[] brackets indicate that you can default

| | Vertical bar means you can choose more than one, but cannot co-exist |

{} curly braces indicate grouping

Angle brackets indicate that you must choose the opposite of the square bracket.

... An ellipsis indicates that it can be used repeatedly.

The different information in the man manual is distinguished, and there are mainly the following categories of information:

NAME: command name

SYNOPSIS: a brief description of usage, available options

DESCRIPTION: a detailed explanation of the features and the meaning of the options

OPTIONS: explain the meaning of each option

FILES: configuration file related to this command

BUGS: if there is a bug, please provide it to this mailbox

EXAMLES: an example

SEE ALSO: see also reference

Because man manuals are rich in content, it is sometimes necessary to use some keyboard shortcuts to find and turn pages (the CLI command line interface does not support mouse paging)

1. Flip the screen

Forward screen b key

The space bar on the backward screen

Forward line k

Enter the car one line back

2. Find

/ keyword look backwards

? Keyword looks forward

N next

N previous one

Q key is exit

6 、 ls

In the linux system, different file types will have different colors. Our common directories are blue and executable files are green.

A directory is a path map as well as a file. The Linux ls command is used to display the contents of the specified working directory (listing the files and subdirectories contained in the current working directory).

Parameters:

-a displays all files and directories (ls internally starts the file name or directory name with "." As a hidden file and will not be listed)

-l in addition to the document name, the document type, permissions, owner, file size and other information are also listed in detail.

-r display documents in reverse order (originally in alphabetical order)

-t list the documents in the order of establishment time

-An is the same as-a, but not listed "." (current catalogue) and ".." (parent directory)

-F add a symbol to the listed file name; for example, executable files add "*" and directories add "/"

-R if there are files in the directory, the following documents are also listed in sequence.

-d displays the inode node information of the directory's own attributes

-I display the inode Inode number

The first character of ls-l shows the file type, and the following file types are commonly used:

The dash represents the normal file files.

The d letter d means this is the grid directory file dir

The letter b stands for block device file block / dev

C character device file char / dev

L link file, also known as symbolic link file, or soft link file, / dev

P stands for pipe file command pipe pipe

S socket file socket / tmp

The file type symbol is followed by nine-digit file permissions, each with a set of three, using rwx to indicate read, write and execute, respectively.

This is followed by the number of times the file was hardwired.

Owner, owner of the file

The group group of the file

The size of the file size

Time stamp

Time when mtime--modify 's last editor was modified

The time when ctime--change last changed permission attributes, etc., and this time will change as the other two change.

Time when atime--access was last visited

You can modify the timestamp using the touch command.

For example: list all files in the root directory: # ls-al / | # ls /

Bin dev lib media net root srv upload www

Boot etc lib64 misc opt sbin sys usr

Home lost+found mnt proc selinux tmp var

List all files whose names begin with s in the current working directory, and the newer the files, the more they are excluded:

# ls-ltr s*

List the details of all the following directories and files in the / bin directory:

# ls-lR / bin

List all files and directories under the current working directory; add "/" to the name of the directory, and "*" after the name of the executable file:

# ls-AF

7 、 cd

The Linux cd command is used to switch the current working directory to dirName (directory parameter). Change directory .

The dirName representation can be an absolute path or a relative path. If the directory name is omitted, change to the user's home directory (that is, the directory where you were just login).

In addition, "~" also means home directory, "." Indicates the directory in which it is currently located, ".." Represents the directory above the current directory location.

Grammar

Cd [dirName]

DirName: the target directory to switch.

Example

Skip to / usr/bin/:

Cd / usr/bin

Jump to your own home directory:

Cd ~

Skip to the top two layers of the current directory:

Cd.. /..

Switch back and forth between the previous directory and the current directory

Cd-

8 、 mkdir

The Linux mkdir command is used to create a subdirectory named dirName.

Grammar

Mkdir [- p] dirName

Parameter description:

-p make sure the directory name exists, and create one if it doesn't exist.

Example

Under the working directory, create a subdirectory called AAA:

Mkdir AAA

In the BBB directory under the working directory, create a subdirectory called Test. If the BBB directory does not already exist, create one. (note: if-p is not added in this example, and the original BBB directory does not exist, an error will occur. )

Mkdir-p BBB/Test

9 、 rmdir

The Linux rmdir command deletes the empty directory.

Grammar

Rmdir [- p] dirName

Parameters:

-p is deleted when the subdirectory is deleted so that it is also empty.

Example

Delete the subdirectory named AAA under the working directory:

Rmdir AAA

In the BBB directory under the working directory, delete the subdirectory named Test. If the BBB directory becomes empty after the Test is deleted, the BBB will also be deleted.

Rmdir-p BBB/Test

10 、 cp

The Linux cp command is mainly used to copy files or directories.

Grammar

Cp [options] source dest

Or

Cp [options] source... Directory

Parameter description:

-a: this option is usually used when copying a directory, preserving links, file properties, and copying everything in the directory. Its function is equal to the combination of dpR parameters.

-d: keep the link when copying. The links mentioned here are equivalent to shortcuts in the Windows system.

-f: overwrite existing target files without prompting.

-I: contrary to the-f option, prompt the user to confirm whether or not to overwrite the target file before overwriting, and the target file will be overwritten when answering "y".

-p: copy the modification time and access rights to the new file in addition to copying the contents of the file.

-r: if the source file given is a directory file, all subdirectories and files under that directory will be copied.

-l: do not copy the file, just generate the linked file.

Example

Use the directive "cp" to copy all files under the current directory "test/" to the new directory "newtest", enter the following command:

$cp-r test/ newtest

Note: when users use this instruction to copy directories, they must use the parameter "- r" or "- R".

11 、 rm

The Linux rm command is used to delete a file or directory.

Grammar

Rm [options] name...

Parameters:

-I ask for confirmation one by one before deletion.

-f even if the original file attribute is set to read-only, it will be deleted directly without confirmation one by one.

-r delete the directory and the following files one by one.

Example

To delete a file, you can use the rm command directly. If you delete a directory, you must match the option "- r", for example:

Rm test.txt

Rm: do you want to delete the generic file "test.txt"? Y

Rm homework

Rm: cannot delete directory "homework": it is a directory

Rm-r homework

Rm: do you want to delete directory "homework"? Y

Delete all files and directories under the current directory, command behavior:

Rm-r *

Once the file is deleted by the rm command, it cannot be recovered, so the command must be used with great care.

12 、 mv

The Linux mv command is used to rename or move a file or directory to another location.

Grammar

Mv [options] source dest

Mv [options] source... Directory

Parameter description:

-I: if the specified directory already has a file with the same name, ask whether to overwrite the old file first

-f: do not give any indication when the mv operation wants to overwrite an existing target file

Mv parameter setting and running result

Command format run result

Mv filename change source filename to destination filename

Mv file name directory name moves the file to the target directory

Mv directory name, directory name, destination directory already exists, set the source directory

Move to the target directory; target

Change the name if the directory does not exist

Mv directory name file name error

Example

Rename the file aaa to bbb:

Mv aaa bbb

Place the info directory in the logs directory. Note that if the logs directory does not exist, the command renames info to logs.

Mv info/ logs

For example, if you move all files and directories under / usr/student to the current directory, the command behavior:

$mv / usr/student/*.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report