"Linux Command detailed" 2, file and directory operations management

Source: Internet
Author: User

2. File and directory Operations management

This section focuses on how to use commands to manipulate files and directories under Linux, such as PWD, CDs, LS, and so on.

2.1 pwd: Show working directory path

Use the PWD command to display the absolute path of the working directory where the current user is located.


2.1.1 Command syntax:

pwd[Options]


Options Option meaning
-L The output link path when the directory link
-P Output physical Path


2.1.3 Instances:

Example 1: Displays the user's current working directory path.

[Email protected] ~]# pwd

/root

The user's current working path is root


Example 2: Displays the actual physical path and link path of the user's current working directory.

[Email protected] init.d]# pwd

/etc/init.d

[Email protected] init.d]# pwd-p

/etc/rc.d/init.d

Show actual physical path

[Email protected] init.d]# pwd-l

/etc/init.d

Show Link Path


2.2 CD: Changing the working directory path

Use the CD command to change the user's working directory path. The working directory path can be either an absolute pathname or an absolute path name, an absolute path starts with a/(root), and then sequentially to the desired directory, with relative paths starting from the current directory.


2.2.1 Command syntax:

cd[options [Catalogue]


2.2.2 Option Parameters:

Options Option meaning
-P If it is a connection path, the source physical path to the link path is entered

The CD command combines various symbols using the following methods

Cd: Go to User home directory
CD ~ Go to User home directory
CD- Return to the directory in which it was before entering this directory
Cd.. Return to Parent directory (if current directory is "/", then "/" after execution)
Cd.. /.. Return to the top level two directory


2.2.3 Instances:

Example 1: Change user working directory path to/etc

[Email protected] ~]# cd/etc/

[Email protected] etc]# pwd

/etc

To view the current user's working directory path, you can see that you have changed to/etc


Example 2: Changing the user working directory path location to the parent path of the current directory

[Email protected] etc]# pwd

/etc

[Email protected] etc]# CD.

[Email protected]/]# pwd

/

You can see that the working directory path has changed to the parent path directory of the current directory "/".


Example 3: Change the user working directory path location to the user home directory

[Email protected]/]# pwd

/

View the user's current working directory path is "/"

[Email protected]/]# CD ~

[Email protected] ~]# pwd

/root

[Email protected] ~]#

You can see that the user's working directory path has changed to the current user's home directory


Example 4: Change the user working directory path location to the user Xiaoming home directory

[Email protected] ~]# CD ~xiaoming

[Email protected] xiaoming]# pwd

/home/xiaoming

You can see that the user's working directory path has changed to the user Xiaoming's home directory/home/xiaoming


Example 5: Change the user working directory path location to/ETC/INIT.D, or enter the source physical path if it is a link path

[Email protected] ~]# cd-p/ETC/INIT.D

[Email protected] init.d]# pwd

/etc/rc.d/init.d

Current working directory path is/ETC/RC.D/INIT.D


2.3 ls: Listing directory and file information

With the LS command, all subdirectories and file information will be listed for the directory, and the file name and other information requested will be output for the files.


2.3.1 Command syntax:

ls[Options [Directory | file]


2.3.2 Option Parameters:

ls option parameter meaning

Options Option meaning
-A Show All files and directories (LS default) the name of the file or directory begins with "." are not listed as hidden files)
-A Same-A but not listed "." (current directory) and ".." (Parent directory)
-C Mating-lt: CTime sorted and displayed CTime
-D If the parameter is a directory, only its name is displayed and the files and subdirectories below it are not displayed
-F Show file types
-I. Display the file details in the first column of the output
-L To display the details of a file in a long format
-R Display the files in reverse order (originally alphabetical order)
-T List the files in the order of establishment time
-S Display the size of each file allocation in blocks
-S Sort by file size


Different types of files have different colors in the Linux system, and the meanings of these colors are as follows:

    • Green: Represents the executable file.

    • Red: Represents the compressed file.

    • Dark blue: Represents the directory.

    • Yellow: Represents a device file, including block device files and character device files.

    • White: Represents a generic file.

    • Gray: represents some other file.

    • Flashing red: There is a problem with the file that represents the link.


2.3.3 Instances

Example 1: List all directories under the root directory (\)

# 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


Example 2: List the current working directory under all the names that are the beginning of the file, the newer the more the row after  

Ls-ltr s*


Example 3: List all directories and file details below the/bin directory  

Ls-lr/bin


Example 4: List all files and directories in the current working directory after the name plus "/", the executable file after the name plus "*"  

Ls-af










"Linux Command detailed" 2, file and directory operations management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.