In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "basic operation commands of folders in CentOS". The explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn the basic operation commands of folders in CentOS.
File (folder) View class command
Ls-- displays the contents of the specified directory
Description: ls displays the results in different colors to distinguish between file categories. Blue represents a directory, gray represents a normal file, green represents an executable file, red represents a compressed file, and light blue represents a linked file.
-a Murray-shows everything, including hidden files
Description: in the Linux system, with "." The beginning is to hide the file or the directory.
-lMusure-displays the details of a file or directory in a long format (more detailed content).
Description: the ls-l command can be simplified to ll
The output information is divided into seven groups:
File category and file permissions, number of links or subdirectories, file owner, group to which the file belongs, file size in bytes B, file creation or modification time, file name.
File category: the first bit of the first group represents the file category, "-" represents the ordinary file, "d" represents the directory, "l" represents the symbolic link, "c" represents the character device, and "b" represents the block device.
File permissions: the last 9 bits of the first group represent file permissions, the first 3 bits are user, the middle 3 bits are group, and the last 3 bits are other permissions
-dmurmuri-displays the properties of the directory itself instead of the contents of the directory.
1 [root@localhost ~] # ls-ld / home
2 drwxr-xr-x. 4 root root 4096 September 22 10:41 / home
3 [root@localhost] # ls-d / home
4 / home
5 [root@localhost] #
-hmurmuri-displays the file size in K, M, G, etc. (default is bytes)
1 [root@localhost] # ls-h / home
2 justin lost+found
3 [root@localhost ~] # ls-lh / home
4 total dosage 20K
5 drwx-. 27 justin justin 4.0K September 22 13:19 justin
6 drwx-. 2 root root 16K September 18 15:30 lost+found
7 [root@localhost ~] #
-Rmurmuri-if there are files in the directory, they will also be listed in sequence.
1 [root@localhost ~] # ls-lR / home
2 / home:
3 the total dosage is 20
4 drwx-. 27 justin justin 4096 September 22 13:19 justin
5 drwx-. 2 root root 16384 September 18 15:30 lost+found
6 / home/justin:
7 total dosage 32
8 drwxr-xr-x. 2 justin justin 4096 September 22 10:49 Public
9 drwxr-xr-x. 2 justin justin 4096 September 22 10:49 template
10 drwxr-xr-x. 2 justin justin 4096 September 22 10:49 video
11 drwxr-xr-x. 2 justin justin 4096 September 22 10:49 Picture
12 drwxr-xr-x. 2 justin justin 4096 September 22 10:49 document
13 drwxr-xr-x. 2 justin justin 4096 September 22 10:49 download
14 drwxr-xr-x. 2 justin justin 4096 September 22 10:49 Music
15 drwxr-xr-x. 2 justin justin 4096 September 22 10:49 desktop
16 / home/justin/ Public:
17 Total dosage 0
18 / home/justin/ template:
19 Total dosage 0
20 / home/justin/ Video:
21 total dosage 0
22 / home/justin/ Picture:
23 the total dosage is 0
24 / home/justin/ documentation:
25 Total dosage 0
26 / home/justin/ download:
27 the total dosage is 0
28 / home/justin/ Music:
29 the total dosage is 0
30 / home/justin/ Desktop:
31 Total dosage 0
32 / home/lost+found:
33 Total dosage 0
34 [root@localhost] #
-tmurmuri-list the files in the order in which they were created
1 [root@localhost ~] # ls-l / home
2 the total dosage is 20
3 drwx-. 27 justin justin 4096 September 22 13:19 justin
4 drwx-. 2 root root 16384 September 18 15:30 lost+found
5-rw-r--r--. 1 root root 0 September 22 15:21 t
6 [root@localhost ~] # ls-lt / home
7 the total dosage is 20
8-rw-r--r--. 1 root root 0 September 22 15:21 t
9 drwx-. 27 justin justin 4096 September 22 13:19 justin
10 drwx-. 2 root root 16384 September 18 15:30 lost+found
11 [root@localhost ~] #
Description: the ls command can also be combined with the wildcard "?" Or "*" together, question mark "?" You can match any character in a file name, while "*" can match any number of characters in a file name. These two wildcards also apply to most other commands in the Shell environment.
1 gssapi_mech.conf popt.d xml
2 gtk-2.0 portreserve yp.conf
3 hal postfix yum
4 host.conf ppp yum.conf
5 hosts prelink.cache yum.repos.d
6 hosts.allow prelink.conf
7 hosts.deny prelink.conf.d
8 [root@localhost etc] # ll-d / etc/po*.d
9 drwxr-xr-x. 2 root root 4096 January 11 2010 / etc/popt.d
10 [root@localhost etc] # ll-d / etc/po?.d
11 ls: unable to access / etc/po?.d: there is no file or directory
12 [root@localhost etc] #
Du--- displays file or directory size
-h or-- human-readable--- is in the unit of KMagazine G to improve the readability of the information.
1 [root@localhost src] # du-h nagios-3.5.0.tar.gz
2 1.8M nagios-3.5.0.tar.gz
3 [root@localhost src] # du nagios-3.5.0.tar.gz
4 1748 nagios-3.5.0.tar.gz
5 [root@localhost src] #
-a Murray-displays the disk space occupied by each file in all directories and subdirectories
-b or-bytes--- displays directory or file size in byte
1 [root@localhost local] # du-b src/nagios-3.5.0.tar.gz
2 1789376 src/nagios-3.5.0.tar.gz
3 [root@localhost local] #
-c or-- total--- displays not only the size of each directory or file, but also the sum of all directories or files
-m or-- megabytes--- is in 1MB
-smurmuri-shows only the sum of the file sizes
1 [root@localhost local] # du-sh src/
2 41M src/
3 [root@localhost local] #
-xMMI-only files that belong to the same file system are calculated
-Lmurmuri-calculate all file sizes
Df--- shows the status of the file system; it is mainly used to understand the disk usage of each file system that has been mounted in the system.
-h displays more readable units of capacity
-T displays the type of file system
1 [root@localhost ~] # df-Th
2 File system type capacity used available mount point% used
3 / dev/sda2ext49.9G 2.6G 6.9G 28% /
4 tmpfs tmpfs 504m 112K 504m 1% / dev/shm
5 / dev/sda1ext4194M 27m 158m 15% / boot
6 / dev/sda5ext47.7G 147m 7.2g 2% / home
7 / dev/sr0iso96602.9G 2.9G 0 100% / media/RHEL_6.3 i386 Disc 1
8 [root@localhost] #
File--- View File Typ
1 [root@localhost home] # file justin/
2 justin/: directory
3 [root@localhost home] # file justin1
4 justin1: empty
5 [root@localhost ~] # file install.log
6 install.log: UTF-8 Unicode text
Description: the file command is used to view the type of file, which can be distinguished by the internal storage structure of the file, not by the extension of the file. In Linux systems, there is no absolute relationship between file extension and file type.
View the contents of the file
Cat--- displays the contents of the file
1 [root@localhost log] # cat / var/log/messages
Note: cat does not pause when displaying the contents of a text file. For long files, only the contents of the last page remain on the screen after a quick scrolling display, so cat is not suitable for viewing long files.
More--- pagination displays the contents of the file
-number of rows displayed by num--- at a time
-s-when you encounter blank lines of more than two consecutive lines, replace them with blank lines of one line
+ num-display from line num
1 [root@localhost log] # more-5s / var/log/messages
2 Sep 22 10:36:06 localhost kernel: imklog 5.8.10, log source= / proc/kmsgstarted.
3 Sep 22 10:36:06 localhost rsyslogd: [origin software= "rsyslogd" swVersion= "5.8.10" x-pid
4 = "1323" x http://www.rsyslog.com"] start
5 Sep 22 10:36:06 localhost kernel: Initializing cgroup subsys cpuset
6 Sep 22 10:36:06 localhost kernel: Initializing cgroup subsys cpu
7-More-- (0%)
Description: similar to cat, but with a page-by-page display to facilitate users to read page by page, blank key (space): show the next page, b key: show the previous page, Q key: exit
Less---- pagination displays the contents of the file
Note: the usage of the less command is similar to that of the more command, the difference between them is that when the contents of the file are displayed at the end of the file, the more command automatically exits the reading environment, while the less command does not automatically exit, and users can still use the arrow keys to scroll the file, which is more conducive to repeated reading of the contents of the file. When you want to end browsing, press Q at the prompt ":" of the less command to exit.
Head--- looks at the contents of the beginning of the file
-n specifies the specific number of rows to display.
1 [root@localhost] # head-5 / etc/passwd
2 root:x:0:0:root:/root:/bin/bash
3 bin:x:1:1:bin:/bin:/sbin/nologin
4 daemon:x:2:2:daemon:/sbin:/sbin/nologin
5 adm:x:3:4:adm:/var/adm:/sbin/nologin
6 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
7 [root@localhost ~] #
Description: by default, head displays the first 10 lines
Tail--- views the contents at the end of the file
1 [root@localhost] # tail-5 / etc/passwd
2 nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
3 abrt:x:173:173::/etc/abrt:/sbin/nologin
4 sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
5 tcpdump:x:72:72::/:/sbin/nologin
6 justin:x:500:500:justin_peng:/home/justin:/bin/bash
7 [root@localhost ~] #
Description: the usage of the tail command is similar to the head command
Create File (folder) command
Touch--- changes the time record of the file. If the file does not exist, create an empty file.
1 [root@localhost home] # touch file1 file2
2 [root@localhost home] # ls
3 file1 file2 justin lost+found t
4 [root@localhost home] #
-a change the reading time record of the file.
-m change the modification time record of the file.
-c if the destination file does not exist, a new file will not be created
Description: it is often used to create new test files in practical use. Using the file name as a parameter, you can create multiple files at the same time. When the target file already exists, the time stamp of the file is updated, otherwise an empty file with the specified name is created.
Mkdir---Make Directory--- creates a new directory
-p make sure the directory name exists, and create one if it doesn't exist.
1 [root@localhost home] # ls
2 justin lost+found t
3 [root@localhost home] # mkdir dir1
4 [root@localhost home] # mkdir dir2/dir
5 mkdir: unable to create directory "dir2/dir": there is no such file or directory
6 [root@localhost home] # mkdir-p dir2/dir
7 [root@localhost home] #
Create multi-level directories at the same time
1 [root@localhost home] # ls
2 justin lost+found t
3 [root@localhost home] # mkdir-p {dir1,dir2/ {dir3,dir4}}
4 [root@localhost home] # ls
5 dir1 dir2 justin lost+found t
6 [root@localhost home] # ls dir2
7 dir3 dir4
8 [root@localhost home] #
Delete File (folder) command
Rmdir--- deletes an empty directory (an error will be reported if the directory is not empty)
-p if the subdirectory becomes empty after it is deleted, it will be deleted as well.
1 [root@localhost home] # mkdir-p {dir1,dir2/dir3}
2 [root@localhost home] # ls
3 dir1 dir2 justin lost+found t
4 [root@localhost home] # rmdir dir1
5 [root@localhost home] # rmdir dir2
6 rmdir: failed to delete "dir2": directory is not empty
7 [root@localhost home] # rmdir-p dir2/dir3/
8 [root@localhost home] # ls
9 justin lost+found t
10 [root@localhost home] #
Rm--- deletes a file or directory
-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.
1 [root@localhost home] # mkdir-p dir1/dir2
2 [root@localhost home] # rm-r dir1/
3 rm: do you want to enter the directory "dir1"? Y
4 rm: do you want to delete the directory "dir1/dir2"? Y
5 rm: do you want to delete the directory "dir1"? Y
6 [root@localhost home] #
Thank you for your reading, these are the contents of the "basic operation commands of folders in CentOS". After the study of this article, I believe you have a deeper understanding of the basic operation commands of folders in CentOS, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.