Linux Common Commands Daquan 1
I. Commands for managing files and directories
Linux commands for managing files and directories
Command |
Function |
Command |
Function |
Pwd |
Show current directory |
Ls |
View the contents of the directory |
Cd |
Change your directory |
Cat |
Display the contents of a file |
Grep |
Find a character in a file |
Cp |
Copying files |
Touch |
Create a file |
Mv |
Moving files |
Rm |
deleting files |
RmDir |
Delete Directory |
1.1 pwd Command
The command is interpreted in English as print working directory (print working directory). Enter the PWD command, and Linux will output the current directory.
1.2 CD command
The CD command is used to change your directory.
CD/go to the root directory
CD ~ Go to the/home/user user directory
Cd/usr go to the USR directory in the root directory-------------absolute path
CD test goes to-------relative path in the test subdirectory under the current directory
1.3 ls Command
The LS command is used to view the contents of the directory.
Options |
Meaning |
-A |
Enumerate all the files in the directory, including hidden files |
-L |
List details in the directory, including permissions, owner, group, size, date created, whether the file is a link, etc. |
-F |
List of files showing file types |
-R |
Reverse, from the back to list the contents of the directory |
-R |
Recursive, this option recursively enumerates the contents of all subdirectories in the current directory |
-S |
Size, sorted by file size |
-H |
Display the size of a file in a human-readable way, such as K, M, G units |
Ls-l Examples.doc |
List all information about file Examples.doc |
1.4 Cat Command
The cat command can be used to merge files or to display the contents of the entire file on the screen.
Cat Snow.txt The command displays the contents of the file Snow.txt, Ctrl+d quits Cat.
1.5 grep command
The most important function of the grep command is to find a specific string in a heap of files.
grep Money Test.txt
The above command looks for the money string in Test.txt, and the grep lookup is case-sensitive.
1.6 Touch Command
The touch command is used to create a new file, and he can create a blank file where you can add text and data.
Touch newfile This command to create a blank file named NewFile.
1.7 cp Command
The CP command is used to copy files, to copy files, and to enter commands:
CP <source filename> <target filename>
CP t.txt document/t The command will copy the file T.txt to the document directory and be named T.
Options |
Meaning |
-I. |
Interactive: If the file will overwrite the target file, he will be prompted to confirm |
-R |
Recursion: This option copies the entire directory tree, subdirectories, and other |
-V |
Verbose: Show the progress of a file's replication |
1.8 MV Command
The MV command is used to move files.
Options |
Description |
-I. |
Interaction: If the selected file overwrites the file in the target, he will prompt to confirm |
-F |
Mandatory: It will go beyond interactive mode and move files without prompting, which is a very dangerous option |
-V |
Verbose: Show the progress of a file's movement |
MV T.txt document moves the file T.txt to the directory document.
1.9 RM Command
The RM command is used to delete files.
Options |
Description |
-I. |
Interactive: Prompt to confirm deletion |
-F |
Force: Replace interactive mode without prompting to confirm deletion |
-V |
Verbose: Show file deletion progress |
-R |
Recursive: Deletes a directory and all of its files and subdirectories |
RM t.txt the command to delete the file T.txt
1.10 rmdir Command
The rmdir command is used to delete a directory.
Ii. commands related to disk space
Commands about disk space
Command |
Function |
Mount |
Mount File System |
Umount |
Uninstalling a file system mounted on a mount |
Df |
Check the disk space of each hard disk partition and the mounted file system |
Du |
Show file directory and size |
Fsck |
Mainly to check and repair the Linux file system |
2.1 Mount Command
The mount command is mounted on a file system that can mount a hard disk, a CD-ROM, a floppy disk, or mount an NFS network file system. The standard usage of this command is as follows:
mount –t device type storage directory
Mount ip Address:/supplied directory storage directory
| Options |
Description |
| (none) |
No parameters, direct input command to display mounted text System and Directory |
| -a |
Hang up/etc/fs All file systems under tab |
| -T |
Develop hung The name of the file system that comes up, all system supported file systems, this information can be seen in/proc/filesystems this file |
| -N |
Hangs the file system, but does not write file system data to/etc/mtlab this file |
| -W |
Set the file system to read/write |
| -R |
The file system that hangs up is set to read-only |
Under directory/mnt, hang up the iso9660 file system. Enter the command:
Mount–t Iso9660/dev/hdb/cdrom
2.2 Umount Command
The function of the Umount command is to unload a file system that has been hung, and the file system on all mounts should be uninstalled before shutting down the system. This command is relative to the Mount command. Usage:
Umount a directory or device that is already hung
To uninstall the/cdrom directory that is already hung, enter the command:
Umount/cdrom
To unload a section that has been hung, enter the command:
Umount/dev/hdb1
2.3 DF Command
The DF command is used to check the disk space of the hard disk partition and the mounted file system, that is, to check the amount of hard disk usage. The standard usage is as follows:
DF [-option]
Options |
Function |
-A |
Make a list of all the file systems and the hard disk usage of each partition, including 0 blocks, such as the/proc file system |
-I. |
List the usage of i-nodes |
-K |
The size of each partition and the size of the file partition to be mounted are denoted by K |
-T |
List all partition disk space usage for a file system |
-X |
Lists all partition disk space usage that are not a file system, as opposed to the-t option |
-T |
Lists the name of the file system to which each partition belongs |
For example, to list disk usage for all file systems and partitions, enter the command:
Df–a
2.4 du command
The function of the du command is to display the file directory or size. Standard usage:
Du [-Options]
Options |
Meaning |
-A |
Displays the disk space occupied by each file in all directories and their secondary directories |
-B |
Displays the size of the directory and file, in units B |
-C |
And finally add a total |
-H |
Improve readability of information in kilobytes, MB, GB |
-S |
Only the sum of each file size is listed |
-X |
Only compute files that belong to the same file system |
2.5 fsck Command
The function of the fsck command is to check and repair the Linux file system, which is best used when no one or no partition hangs up, in fact, each boot system will do a check to see if there is a bad track or data loss phenomenon. Usage:
fsck (-option) partition name
Options |
Function |
-A |
Automatic repair of file system, not asking any questions, more dangerous |
-A |
Check all the file systems listed in the file according to the contents of the/etc/fstab configuration file. Without the additional parameter "-P", the file system of the/directory is checked first, and all file systems are not checked at the same time |
-R |
Take an interactive approach, ask questions when repairing, and let users confirm and decide how to handle them |
-S |
Check the job in turn instead of executing it at the same time. Use this parameter for sequential execution when you specify multiple file systems in turn, and check them interactively, or fsck may ask several questions at the same time, making it confusing |
-V |
Show the process of command execution |
-T |
Specifies the type of file system to check |
-N |
Does not actually execute the instruction, only lists the actions that will occur when the actual execution |
Iii. file backup and compression commands
File backup and Compression commands
In Linux, the commonly used file compression tools are gzip, bzip2, zip. BZIP2 is the ideal compression tool that provides maximum compression. Zip compatibility is good and Windows supports it.
Command |
Function |
Bzip2/bunzip2 |
Compression/Decompression tool with extension bz2 |
Gzip/gunzip |
Zip/Unzip tool with extension GZ |
Zip/unzip |
Compression/Decompression tool with zip extension |
Tar |
Create Backup and Archive |
3.1 bzip2 Command
To compress a file using bzip2, enter the command at the shell prompt:
bzip2 filename
The file is compressed and saved as filename.bz2.
To extract a file, enter the command:
BUNZIP2 filename.bz2
FILENAME.BZ2 will be deleted and replaced with filename.
bzip2 filename.bz2 file1 file2 file3/usr/work/school
The above command compresses the contents of the File1, File2, File3, and/usr/work/school directories and puts them in filename.bz2.
3.2 gzip Command
To compress a file using gzip, enter the command:
gzip filename
The file is compressed and saved as filename.gz.
To extract a file, enter the command:
Gunzip filename.gz
Filename.gz will be deleted and replaced with filename.
Gzip-r filename.gz file1 file2 file3/usr/work/school
The above command compresses the contents of the File1, File2, File3, and/usr/work/school directories and puts them in filename.gz.
3.3 Zip command
The zip command is used in conjunction with GZIP.
3.4 Tar Command
The
tar command was originally used for tape backup, but because of the increasing capacity of the hard disk, the main use of this command now is to back up all the files. Tar this command packs a large number of files and directories into a file.
| Options |
function |
| -C |
Create a new archive |
| -F |
When used with the-c option, the tar file created uses the file name specified by this option and when used with the-X option , the archive specified by this option is dismissed |
| -T |
Displays the list of files included in the tar file |
| -V |
Show file Progress |
| -X |
Extract files from archive |
| -Z |
Compress tar files with gzip |
| -j |
Use bzip2 to compress tar files / td> |
To create a tar file, enter the command:
TAR–CVF Filename.tar Directory/file/home/mine
The above command puts Directory/file,/home/mine into the archive.
To list the contents of a tar file, enter the command:
TAR–TVF Filename.tar
To extract the tar file command, enter the command:
TAR–XVF Filename.tar
This command does not delete the tar file, but it copies the contents of the archive to the current working directory and preserves any directory structure used by the archive file.
Keep in mind that tar does not compress files by default. To create a file that uses tar and bzip2 to archive compressed files, use the-J option:
TAR–CJVF filename.tbz File
If you use the BUNZIP2 command to extract the Filename.tbz file, the FILENAME.TBZ is deleted and replaced with Filename.tar.
To extend and de-archive the bZIP tar file, enter the command:
TAR–XJVF FILENAME.TBZ
To create a file that is archived and compressed in tar and gzip, use the-Z option:
TAR–CZVF filename.tgz File
If you use the Gunzip command to extract the Filename.tgz file, the filename.tgz is deleted and replaced with Filename.tar.
Transferred from: http://www.linuxidc.com/Linux/2011-08/40437.htm
Linux Common Commands Daquan 1