Linux Common commands

Source: Internet
Author: User
Tags file copy file system mkdir parent directory readable regular expression

1 file and directory operation commands

1.1 File Content Query command

grep, Fgrep, Egrep

Syntax: grep[option [lookup mode] [filename 1, filename 2,......]

Options:-e Each pattern treats as an extended regular expression

-F Each pattern treats as a set of fixed strings, not as regular expressions

-I comparison is case insensitive

-L Displays the name of the first matching string and separates it with a newline character. When matching strings appear more than once in a file, the secondary file name is not repeated;

-X displays only rows that are strictly matched for the entire row

1.2 File Lookup commands Find, locate

Syntax: Find start directory look for condition actions

Find by name and file attributes

-name ' string ' finds the file name matches all the files for the given string, and the wildcard character * 、?、 [] is available within the string.

-lname ' string ' finds the filename matches all the symbolic link files for the given string, and the wildcard character * 、?、 [] is available within the string.

-gid N finds all files that belong to a user group with an ID number of n.

-uid N finds all files belonging to the user with ID number n.

-group ' string ' looks for all files that belong to the given string named by the user group.

-user ' string ' finds all files that belong to a given string of user names.

-path ' string ' finds all files that match the given string, and the wildcard character * 、?、 [] is available within the string.

-perm permissions to find files and directories with the specified permissions, the representation of the permission can be as 711, 644.

-type x finds a file of type X,

Syntax: Locate related words

1.3 Copy, delete, and move commands for files

File copy command CP [option] source file or directory destination file or directory

Option:-A is usually used when copying directories

Keep connection when-D copy

-F Deletes an existing destination file without prompting

The-I and F options are the opposite

-P In addition to copying the source file content, the CP also copies its modified time and access rights to the new file

-R If the source file given is a directory file, the CP will recursively replicate all subdirectories and files in the directory, at which point the target file must be a directory name;

-l no copy, just link file

File Move command mv[option] source file or directory destination file or directory

-I interactive operations

-F Disables interactive operation

File Delete command rm[option] File ...

-F ignores files that do not exist and never gives a hint

-R instructs Rm to recursively delete all directories and subdirectories listed in the parameters

-I for interactive deletion

1.4 File Link Command

ln [options] target [link name] or ln [options] Target directory

Option:-S to establish symbolic links

1.5 Create and DELETE commands for directories

mkdir Create a directory

Syntax: mkdir [Options] DirName

Options:-M sets access permissions on new directory

-P can be a path name. In this case, if some directories in the path do not already exist, plus this option, the system will automatically establish those directories that do not yet exist, that is, you can build multiple directories at once.

R

Mdir Delete Empty Directory

Syntax: rmdir [Options] DirName

Option:-P recursively deletes the directory dirname, which is also deleted when the subdirectory is deleted and its parent directory is empty.

1.6 Change working directory, display directory content command

1. Change Working directory: CD [directory]

2, display the current working directory absolute path: pwd

3, display contents: ls [options] [directory or file]

Option:-a displays all subdirectories and files in the specified directory, including hidden files;

-C sorted by file modification time

-C is divided into columns to display each

-D If the argument is a directory, display only its name without displaying the file below it

-F Marks "/" After the directory name, "*" After the executable file, marked "@" after the symbolic link, and "|" after the pipe (or FIFO), and the "=" tag behind the socket file.

-L displays file details in long format

-L Displays the file that the link points to if the specified name is a symbolic link

-T sort by modified time instead of name when shown

-U is sorted by file last accessed time instead of first name when displayed

4, change the file or directory Access rights command

chmod [who] [+|-| =] [mode] file name?

WHO option:

-U represents the user, that is, the owner of the file and directory

-G represents the same group of users

-O (Other) indicates that another user

-A (all) indicates that all users

Operation Symbol:

+ Add a permission-Cancel a permission

= gives the given permission and cancels all other permissions (if any)

Mode option:

-R Readable

-W can write

-X Executable

CHGRP [-r] group filename? Change the group to which the directory or file belongs

chown [-RV] User or group file

1.7 Backup and Compression commands

1. Tar command create file for files and directories

Syntax: tar [main option + Secondary options] file or directory

U main option

C Create a new profile. If the user wants to back up a directory or some files, select this

R append the file you want to archive to the end of the file

T list the contents of the archive file to see which files have been backed up;

U Update files

(x) Release of files from the file;

U auxiliary Options

b This option is set for the tape drive, followed by a number to indicate the size of the block, the system preset value is 20

F Use an archive file or device, this option is usually required

K to save a file that already exists. For example, to restore a file, in the process of restoration, encountered the same file, will not be overwritten;

m when the file is restored, change the time of all files to the current;

M Create multiple volumes of files to store on several disks;

V detailed report on tar processing file information

W Each step requires confirmation

Z use gzip to compress/decompress files

2. Gzip command compression/decompression command

Syntax: gzip [option] Compressed (uncompressed) file name

Option:-C writes output to

Standard output, and keep the original file

-D Unzip compressed file

-L displays detailed information for each compressed file

-R recursively finds the specified directory and compresses all files in it or is uncompressed

-t test, check that the compressed file is complete

-V for each compressed and decompressed file, display file name and compression ratio

3, Unzip command

WinZip compressed files under MS Windows under Linux system

Syntax: Unzip [options] compress file names. zip

Option:-X file list to extract the file, but not the specified file file

-V View compressed file directory, but don't understand the pressure

-t test file for damage, but does not understand the pressure

-D directory to extract compressed files to the specified directory

-Z Show only annotations for compressed files

-N does not overwrite files that already exist

-O overwrites existing files and does not require user confirmation

-j does not reconstruct the document's directory structure, extracting all files to the same directory

1.8 Running DOS commands in a Linux environment

The Linux system provides a set of portable tools called Mtools that allow users to easily read and write files and directories from a standard DOS floppy disk.

MCD Directory name change Msdos directory

Mcopy the source file destination file to copy files between Msdos and Unix;

Mdel Directory name Delete msdos directory

Mdir Directory name Display Msdos directory

Mformat Drive Letter Create Msdos file system on a low-level formatted floppy disk

Rnlabel drive Letter produces MSDOS volume label

MMD Directory name Delete msdos directory

Mren source file Target file Rename existing Msdos file

Mtype file name Displays the contents of the Msdos file

2 Device Management Command

Linux defines an IDE hard disk in the following form:/dev/hd[drive][partition]

SCSI hard drives Use the same mechanism:/dev/sd[drive][partition]

For a typical Linux partition, you can format it and generate a file system using MKFS, which commands the following:

Mk2fs–c

Mount file system: Mount–t ext2 [-o optioms] partition Mountpiont

Where-t specifies some options, such as read-only RO, readable writable RW, and so on, for the specified mount file system type; partition defines the partition name; Mountpiont defines the name of the directory to which the file system is loaded.

Mount CD-ROM file system: Mount–t Iso9660–r/dev/cdrom/mnt/cdrom

Mount floppy Drive File system: Mount–t msdos–rw/dev/fd0/dev/mnt/floppy

Uninstall File System Umount/mnt/cdrom

Note the following points for installation of tape devices:

1, first of all to choose a only

A SCSI ID number, and then link the device to the appropriate location

2, select the driver.

3, Generate equipment files. The main device number for the SCSI tape device is 9, and the minor device number is 0. Device file names are usually/dev/nrst0 (tape devices that do not support wrapping) or/dev/nst0 (tape devices that support wrapping)

Related Article

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.