


What are the common commands for Linux files and disks?
May 12, 2023 pm 11:25 PM#View file information: ls ls is the abbreviation of the English word list. Its function is to list the contents of the directory. It is one of the most commonly used commands by users. It is similar to the dir command under DOS; The Linux file or directory name can have a maximum length of 265 characters. "." represents the current directory, and '..' represents the upper-level directory. Files starting with '.' are hidden files and need to be displayed with the -a parameter. ##lsCommon parameters -a displays all subdirectories and files in the specified directory, including hidden files -l displays file details in list format -h works with -l to display the file size in a humane way ##View directory filtering
ls?-lh?已k為單位顯示查詢出的文件大小 ls?-a?顯示所有文件,包含隱藏文件 ls?-lha?注意,這里參數(shù)的順序可以更改,所表述的含義是相同的。 ls?路徑:?查詢指定路徑的文件列表 *?-?通配符,代表任意字符(0到多個(gè)) ??-?通配符,代表一個(gè)字符 ()?-?中間為子shell的起始與結(jié)束 []?-?中間為字符組合?[abc]?-匹配字符abc?[a-z]-匹配a-z之間所有字符 {}?-?中間為命令區(qū)塊組合 &&?-?當(dāng)前一個(gè)指令執(zhí)行成功時(shí),執(zhí)行后一個(gè)指令 ||?-?當(dāng)前一個(gè)指令執(zhí)行失敗時(shí),執(zhí)行后一個(gè)指令? ls?test*?*表示后面不論接幾個(gè)字符都接受(沒(méi)有字符也接受) ls?test???表示后面當(dāng)且僅當(dāng)接一個(gè)字符時(shí)才接受 ls?test???????表示一定要接三個(gè)字符 cp?test[1~5]?/tmp?test1,?test2,?test3,?test4,?test5若存在,則復(fù)制到/tmp目錄下 ?若文件名為*.a?,則使用ls?\*.a進(jìn)行匹配
##Output redirection command:> Linux allows the command execution results to be redirected to a file, and the content that should be displayed on the terminal is saved to the specified file; ls -lha > ls.txt displays the query information in the ls.txt file. (If ls.txt does not exist, create one, and if it exists, overwrite its content) Note: ">" means overwriting the source file, and ">>" output redirection will be appended to the end of the file; You can use gedit filename to open this file to view the redirection results; ##Split screen display: more When viewing content, when the information is too long to be displayed on one screen, rapid scrolling will occur, making it difficult for the user to see the content of the file. At this time, the more command can be used to display only one page at a time. Press the space bar to display it. On the next page, press the q key to exit the display, and press the h key to get help; more: When there is too much query content, you can use the more keyword to display the query results in split screens; more ls -lha displays the query results in split screen format; ##Pipeline: | Pipes: The output of one command can be used as the input of another command through a pipe; The pipeline is actually a piece of memory used for buffering. All output content is cached first and then retrieved from the cache; Display the contents of a certain text in the terminal: cat file name; cat linux notes.txt | more "|" represents a pipeline (cache), which caches the content first and then displays it in split screen after all the caching is completed; ##Clear screen: clear Clear is used to clear the display content on the terminal. The same DOS command is the cls command. You can also use the shortcut key: Ctrl L ##Switch working directory: cd When using Unix/Linux, you often need to change the working directory; The cd command can help users switch working directories. All directory and file names in Linux are case-sensitive; cd can be followed by an absolute path or a relative path. If the directory is omitted, it defaults to the current user's home directory; The usage of cd is as follows:
cd: Switch to the current user's home directory (/home/user directory). When the user logs in, the default directory is the user's home directory; cd ~: Switch to the current user’s home directory (/home/user directory); cd .: switch to the current directory; cd ..: switch to the upper-level directory; cd -: Switch to the last directory;
##Display the current path: pwd Use the pwd command to display the current working directory. This command is very simple. Just enter pwd directly without parameters; ##Create directory: mkdir A new directory can be created through the mkdir command. The parameter -p can create directories recursively; It should be noted that the name of the new directory cannot have the same name as an existing directory or file in the current directory, and the directory creator must have write permissions on the current directory; The usage of mkdir is as follows:
mkdir test creates a folder named test; mkdir a/b/c –p creates a folder named c that exists in the b directory under the directory;
Note that this type of folder creation is called recursive directory creation ##Delete directory: rmdir You can use the rmdir command to delete a directory. You must leave the directory, and the directory must be an empty directory, otherwise it will prompt that the deletion failed; ##Delete files: rm Files or directories can be deleted through rm. Be careful when using the rm command because files cannot be recovered after being deleted; In order to prevent accidentally deleting files, you can use the -i parameter after rm to confirm the files to be deleted; Commonly used parameters and their meanings are shown in the following table:
Soft link: Soft link does not occupy disk space. If the source file is deleted, the soft link will become invalid. Hard links: Hard links can only link ordinary files, not directories.
Use format:
ln source file link file ---hard link ln -s source file link file ---soft link
A hard link is equivalent to a file with multiple file names. Creating a hard link will cause the counter in the file to be 1. Deleting a hard link or the source file counter will be -1. A counter of 0 means the file is actually deleted; Soft link files are equivalent to shortcuts in Windows. Deleting the source file will invalidate the soft link file; The new file of the hard link occupies the same size of hard disk space as the source file, so soft link (-s) is generally used; Note: If the soft link file and the source file are not in the same directory, the source file must use an absolute path and cannot use a relative path. ##Text search: grep The grep command in Linux system is a powerful text search tool. grep allows pattern search on text files. If a matching pattern is found, grep prints all lines containing the pattern; The general format of grep is:
grep [-option] ‘Search content string’ file name When entering string parameters in the grep command, it is best to enclose them in quotes or double quotes. For example: grep ‘a(chǎn)’ 1.txt;
Common option description:
-v displays all lines that do not contain matching text (equivalent to negation); -n displays matching lines and line numbers; -I ignore case; The grep search content can be a regular expression;
##Find files: find The Find command is very powerful. It is usually used to search for files that meet the conditions in a specific directory. It can also be used to search for files with specific user attributes;
##Copy files :cp The function of the cp command is to copy the given file or directory to another file or directory, which is equivalent to the copy command in DOS; Description of common options:
-a This option is usually used when copying a directory. It retains links, file attributes, and the copied directory. In short, it maintains the original attributes of the file; -f no longer prompts that the directory file already exists; -i interactive copy, prompts the user for confirmation before overwriting the target file; -r If the given source file is a directory file, cp will copy all subdirectories and files in the directory, and the target file must be a directory name; -v displays copy progress;
##Move files: mv Users can use the mv command to move files or directories, or rename files or directories. Equivalent to clipping in Window; Description of common options:
-f interactive operation, no prompt will be given if overwritten; -i Confirm the interactive mode operation. If the mv operation will cause the overwriting of an existing target file, the system will ask whether to rewrite and require the user to answer to avoid overwriting the file by mistake; -v displays the move progress;
##Archive management: tar Data in the computer often needs to be backed up. tar is the most commonly used backup tool in Unix/Linux. This command can archive a series of files into a large file, and can also unzip the archive file to restore data; tar uses the format tar[parameter] to package filename file; The tar command is very special. You can use "-" in front of its parameters or not; Commonly used parameters:
-c generates archive files and creates packaging files; -v lists the detailed process of archive unarchiving and displays the progress; -f specifies the archive file name, f must be followed by a .tar file, so the option must be placed last; -t lists the files contained in the archive; -x Unlock the archive file;
Note: Except for f, which needs to be placed at the end of the parameter, the order of other parameters is arbitrary. ##File compression and decompression: gzip Use tar in conjunction with the gzip command to package and compress files; tar is only responsible for packaging files, but not compressing them. Use gzip to compress tar-packed files, and their extensions are generally XXX.tar.gz; Common options:
-d decompression; -r compresses all subdirectories;
gzip and tar commands can be used together, just add "z" before the available tar parameters. Unzip using “tar –zxvf filename” ##File compression and decompression: bzip2 Use tar in conjunction with the bzip2 command to implement file packaging and compression (the usage is the same as gzip); The tar value is responsible for packaging files, but not compressing them. Use bzip2 to compress tar-packed files, and their extensions are generally xxxx.tar.gz2; Adding an option (-j) to the tar command can call bizp2 to implement a compression function and implement the process of packaging first and then compressing; Compression method: tar jcvf compressed package name file... (tar –jcvf bk.tar.gz2 *.txt) Decompression method: tar jxcf compressed package name (tar jxvf bk.tar.bz2) ##File compression and decompression: zip, unzip The target file compressed by zip does not need to specify an extension, and the default extension is zip; Compressed file: zip [-r] target file (without extension) source file; Unzip the file: unzip –d Decompressed directory file compressed file.
The above is the detailed content of What are the common commands for Linux files and disks?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

To tune MySQL into a Chinese interface, it can be implemented through MySQLWorkbench or command line tools. 1) In MySQLWorkbench, open "Preferences", select the "Appearance" tab, and then select "Chinese(Simplified)" in the "Language" drop-down menu, and restart. 2) When using command line tools, set the operating system locale variables, such as using "exportLANG=zh_CN.UTF-8" on Linux or macOS, and then run the mysql client.

Linux and Windows have their own advantages and disadvantages in CPU and memory usage: 1) Linux uses time slice-based scheduling algorithms to ensure fairness and efficiency; Windows uses priority scheduling, which may cause low-priority processes to wait. 2) Linux manages memory through paging and switching mechanisms to reduce fragmentation; Windows tends to pre-allocate and dynamic adjustment, and efficiency may fluctuate.

Linux's cost of ownership is usually lower than Windows. 1) Linux does not require license fees, saving a lot of costs, while Windows requires purchasing a license. 2) Linux has low hardware requirements and can extend the service life of the device. 3) The Linux community provides free support to reduce maintenance costs. 4) Linux is highly secure and reduces productivity losses. 5) The Linux learning curve is steep, but Windows is easier to use. The choice should be based on specific needs and budget.

LinuxoftenoutperformsWindowsinI/Operformanceduetoitscustomizablekernelandfilesystems,whileWindowsoffersmoreuniformperformanceacrosshardware.1)LinuxexcelswithcustomizableI/OschedulerslikeCFQandDeadline,enhancingperformanceinhigh-throughputapplications

The key to installing dual systems in Linux and Windows is partitioning and boot settings. 1. Preparation includes backing up data and compressing existing partitions to make space; 2. Use Ventoy or Rufus to make Linux boot USB disk, recommend Ubuntu; 3. Select "Coexist with other systems" or manually partition during installation (/at least 20GB, /home remaining space, swap optional); 4. Check the installation of third-party drivers to avoid hardware problems; 5. If you do not enter the Grub boot menu after installation, you can use boot-repair to repair the boot or adjust the BIOS startup sequence. As long as the steps are clear and the operation is done properly, the whole process is not complicated.

The key to enabling EPEL repository is to select the correct installation method according to the system version. First, confirm the system type and version, and use the command cat/etc/os-release to obtain information; second, enable EPEL through dnfinstallepel-release on CentOS/RockyLinux, and the 8 and 9 version commands are the same; third, you need to manually download the corresponding version of the .repo file and install it on RHEL; fourth, you can re-import the GPG key when encountering problems. Note that the old version may not be supported, and you can also consider enabling epel-next to obtain the test package. After completing the above steps, use dnfrepolist to verify that the EPEL repository is successfully added.

Linux usually performs better in web server performance, mainly due to its advantages in kernel optimization, resource management and open source ecosystem. 1) After years of optimization of the Linux kernel, mechanisms such as epoll and kqueue make it more efficient in handling high concurrent requests. 2) Linux provides fine-grained resource management tools such as cgroups. 3) The open source community continuously optimizes Linux performance, and many high-performance web servers such as Nginx are developed on Linux. By contrast, Windows performs well when handling ASP.NET applications and provides better development tools and commercial support.

Newbie users should first clarify their usage requirements when choosing a Linux distribution. 1. Choose Ubuntu or LinuxMint for daily use; programming and development are suitable for Manjaro or Fedora; use Lubuntu and other lightweight systems for old devices; recommend CentOSStream or Debian to learn the underlying principles. 2. Stability is preferred for UbuntuLTS or Debian; you can choose Arch or Manjaro to pursue new features. 3. In terms of community support, Ubuntu and LinuxMint are rich in resources, and Arch documents are technically oriented. 4. In terms of installation difficulty, Ubuntu and LinuxMint are relatively simple, and Arch is suitable for those with basic needs. It is recommended to try it first and then decide.
