Home > System Tutorial > LINUX > body text

How to operate Linux proficiently? Learning the directory file operation command cd is the key

WBOY
Release: 2024-07-03 15:29:21
Original
925 people have browsed it

如何熟练操作 Linux?学习目录文件操作命令 cd 是关键

Click "Linux Commune" under the title above to quickly follow

Introduction

Interpretation of common directory file operation commands in Linux

So, if you want to be proficient in operating Linux, you can only improve your system operating capabilities by learning Linux commands one by one

The first thing we need to learn is the operating commands of Linux directory files

cd switches the user’s current working directory

cd(option)(parameter)

The cd command is used to switch the user's working directory to a specified directory. You can use an absolute path or a relative path for this specified directory (an absolute path means starting from the root directory, and a relative path means starting from the current directory)

If you use the cd command directly without adding any parameters, it will switch to the home directory of the logged in user

For example, I logged in as the root user at the beginning, so when he enters the command line, he will enter the /root/ directory. After using cd to switch to other directories, directly cd (without any parameters) and he will switch back to /root/directory

Some things to pay attention to when switching directories with cd

"~" means homedirectory (home directory or user directory)

"." indicates the current directory

".." indicates the directory above the current directory location.

Examples

cd to enter the user directory;

cd~ Enter the user directory;

cd - Return to the directory you were in before entering this directory;

cd.. Return to the upper-level directory (if the current directory is "/" 64-bit linux, it will still be at "/" after execution; ".." means the upper-level directory);

cd../..return to the previous two levels of directory;

cd!$ uses the parameters of the previous command as cd parameters.

pwd displays the user’s current working directory

pwd(option)

删除文件夹指令linux_linux 删除文件夹 命令_linux删除文件夹命令夹

pwd is used to display the user’s current working path, which is presented as an absolute path

For example, the following examples

[root@localhostlinuxidc]#cd/root

[root@localhost~]#pwd

/root

[root@localhost~]#cd/home/linuxidc/

[root@localhostlinuxidc]#pwd

/home/linuxidc

ls displays the target list (used before when talking about the directory structure)

ls(options)(parameters)

The parameter can be a directory. If nothing is added, it represents the current directory

ls directory is the most frequently used command in Linux in my opinion

Under Windows, open the file explorerlinux delete folder command, step into a directory, and the file directories above are directly displayed

Under Linux, if you step into a directory and want to view the files or folders in a directory, you must use the ls command

The options of ls command are as follows

-a: Display all files and directories (ls defaults to file names or directory names with "." as shadow collections and will not list them);

-A: Display the list of all files except the hidden files "." and "..";

-C: Display output results in multiple columns. This is the default option;

-l: Contrary to the function of the "-C" option, all output information is output in single column format and not in multiple columns;

-F: Append the file type identifier after each output item. The specific meaning: "*" represents an ordinary file with executable permissions, "/" represents a directory, "@" represents a symbolic link, and "|" represents a command. Pipeline FIFO, "=" represents sockets. When the file is a normal file,

Do not output any identifier;

-b: Output the non-outputable characters in the file by backslash "" plus character encoding;

-c: When used with the "-lt" option, the output directory contents are sorted according to the file status time. The sorting is based on the ctime array in the index node of the file. When used with the "-l" option, the sorted sentence is the status change time of the file;

-d: Only display the directory name, not the content list under the directory. Display the symbolic link file itself, rather than the list of directories it points to;

-f: The effect of this parameter is the same as specifying the "aU" parameter at the same time, and turns off the effect of the "lst" parameter;

-i: Display the file index node number (inode). An index node represents a file;

--file-type: has the same function as the "-F" option, but does not display "*";

-k: Display file size in KB (kilobytes);

-l: Display the content list under the directory in long format. The output information includes file name, file type, permission mode, number of hard connections, owner, group, file size and last modification time of the file from left to right;

-m: Use "," to separate each file and directory name;

-n: Replace the name with the user ID and group ID;

-r: Arrange the file names in reverse order and output the directory content list;

-s: Display the size of files and directories in blocks;

-t: Sort files and directories by modification time;

-L: If you encounter a file or directory that is a symbolic link, directly list the original file or directory pointed to by the link;

-R: Recursive processing, processing all files and subdirectories in the specified directory together;

--full-time: list the complete date and time;

--color[=WHEN]: Use different colors to highlight different types.

I told you before what colors each color represents. Here you can also specify different types to display different colors through --color

The following is a simple demonstration

[root@localhost~]#ls#Displays files in the current directory by default

1.txt2.txt3.txtabc

[root@localhost~]#ls-a#Display all files in the current directory, including hidden files starting with "."

.1.txt3.txtb.bash_logout.bashrcc.cshrc.python_history.viminfo

..2.txta.bash_history.bash_profile.bashrc-anaconda3.bak.cache.ipython.tcshrc.vimrc

[root@localhost~]#ls-l#Display detailed information of files in the current directory, such as permissions, file size, and change time

total12

-rw-r--r--.1rootroot0Apr510:291.txt

-rw-r--r--.1rootroot0Apr510:292.txt

-rw-r--r--.1rootroot0Apr510:293.txt

drwxr-xr-x.2rootroot4096Apr510:29a

drwxr-xr-x.2rootroot4096Apr510:29b

drwxr-xr-x.2rootroot4096Apr510:29c

[root@localhost~]#ll# is equivalent to the ls-l command, which displays detailed file information

total12

-rw-r--r--.1rootroot0Apr510:291.txt

-rw-r--r--.1rootroot0Apr510:292.txt

-rw-r--r--.1rootroot0Apr510:293.txt

drwxr-xr-x.2rootroot4096Apr510:29a

drwxr-xr-x.2rootroot4096Apr510:29b

drwxr-xr-x.2rootroot4096Apr510:29c

[root@localhost~]#ls-al# The combination option is equivalent to ls-a-l to display detailed information of all files or directories in the current directory

total68

dr-xr-x---.7rootroot4096Apr510:29.

dr-xr-xr-x.22rootroot4096Apr509:27..

-rw-r--r--.1rootroot0Apr510:291.txt

-rw-r--r--.1rootroot0Apr510:292.txt

-rw-r--r--.1rootroot0Apr510:293.txt

drwxr-xr-x.2rootroot4096Apr510:29a

drwxr-xr-x.2rootroot4096Apr510:29b

-rw-------.1rootroot4083Apr418:03.bash_history

-rw-r--r--.1rootroot18May202009.bash_logout

-rw-r--r--.1rootroot176May202009.bash_profile

-rw-r--r--.1rootroot247Mar1205:07.bashrc

-rw-r--r--.1rootroot176Mar1106:12.bashrc-anaconda3.bak

drwxr-xr-x.2rootroot4096Apr510:29c

drwxr-xr-x.3rootroot4096Apr105:19.cache

-rw-r--r--.1rootroot100Sep222004.cshrc

drwxr-xr-x.5rootroot4096Mar1205:10.ipython

-rw-------.1rootroot32Mar3117:16.python_history

-rw-r--r--.1rootroot129Dec32004.tcshrc

-rw-------.1rootroot4016Apr204:35.viminfo

-rw-r--r--.1rootroot25Mar1205:10.vimrc

You can try other options by yourself. Due to space constraints, I won’t demonstrate them one by one

mv Unicom file directory command

mv(option)(parameter)

The mv command can be used to connect a file or a directory, and can also be used as a rename command

It usually requires two parameters, source (source file or source directory), target (target file or target directory)

Note that if the same file exists in the target path, the previous file will be overwritten. If it is just connected to the Linux server maintenance in the current directory, and the directory name is different from the original file, then this is just a rename operation

mv options are as follows

--backup=: If you need to overwrite the file, back it up before overwriting;

-b: When the file exists, create a backup for it before overwriting;

-f: If the target file or directory duplicates an existing file or directory, the existing file or directory will be overwritten directly;

-i: Interactive operation, the user is asked before overwriting. If the source file has the same name as the target file or a file in the target directory, the user is asked whether to overwrite the target file. The user inputs "y" to indicate that the target file will be overwritten; inputting "n" indicates to cancel the connection to the source file. This is okay

To prevent files from being overwritten by mistake.

--strip-trailing-slashes: delete the slash "/" in the source file;

-S: Specify a suffix for the backup file instead of using the default suffix;

--target-directory=: Specify the source file to be connected to the target directory;

-u: The connection operation is only performed when the source file is newer than the target file or the target file does not exist.

Usually we don’t need options when using the mv command, so we just list the options for reference

mv application

[root@localhostlinuxidc]#ls

a.pya.sh

[root@localhostlinuxidc]#mva.pyb.py#Just changed the name

[root@localhostlinuxidc]#ls

a.shb.py

[root@localhostlinuxidc]#ls/root/a/

1.py2.py3.py4.py5.py

[root@localhostlinuxidc]#pwd

/home/linuxidc

[root@localhostlinuxidc]#mv/root/a/*.#Unicom all files in the a directory to the current directory (* represents the key value, . represents the current directory)

[root@localhostlinuxidc]#ls

1.py2.py3.py4.py5.pya.shb.py

The above is the detailed content of How to operate Linux proficiently? Learning the directory file operation command cd is the key. For more information, please follow other related articles on the PHP Chinese website!

source:itcool.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template