Basic commands, view the file, command link

Basic commands, view the file, command link

linux commands basic format:命令 [-选项] [参数]

Directory display command ls

ls (list is shorthand), displays all files

Show root of the file:ls -a /

Representatives -a show all files, including hidden files (a representative of all, hidden files usually begin with.);

-l displays the detailed information file (l represents the long), execute ls -l /the command:

From left to right on behalf of:

File Type (d represents a directory directory, - representing a binary file, l representative of the soft link file link, b interface for the storage device is a device file, c is the device file serial port devices, such as a mouse, keyboard)

Permissions (other main group, r representatives read, w representative of write, x representatives execute),

Reference count file or directory in the case (this figure and the related directory, while the number of hard links, and if the establishment of a directory in the directory A and B, then B's reference count is 2, because there is a default under B. And two .. directory, and the directory a reference count of +1, and if a multiple hard link to the file reference count is also incremented by one),

Owner (only one), group ownership, file size in bytes, modification time, file name;

-lh (h Representative human) displays the detailed information of the file, the file -l except that the size of the display more user-friendly;

-d list only represents a directory.

It represents a unique -i flag Query File (i represents the inode).

-sh you can view the block occupied by the total capacity of each file can be found in the first line of total ll command result is the number of total files using block * Each block size, the number is greater than the total file size, but the remaining disk space has been can not use, because each file and then have to take up a small block, this is a waste of disk space:

Create a directory mkdir

mkdir (make directories) to create a new directory command.

Create a new directory i1 under the tmp: mkdir -p /tmp/i1, -p create recursive mean, if you want to create a directory in a directory that does not exist it is necessary to use this option. mkdir supports the creation of multiple directories, just use spaces to multiple directories can be separated, write the name of the directory completely.

When you create a direct distribution rights:mkdir -m 711 test2

Change directory cd

cd (change directory) switch directories. After the addition of particular directory cd can complete the handover, the two points can be added back to the parent directory.

Displays the current directory pwd

pwd (print working directory) displays the current directory. If the current directory is linked files, add -P option displays a link to a specific location.

Delete rmdir and rm

rmdir (remove empty directory) delete the directory (must be empty directory, or failed), - p represents the multi-layered delete empty directories.

rm (remove) delete a file or directory. -r means to delete the directory; -f indicates that no confirmation again; -rf means to delete the directory and does not require confirmation.

Copy shear cp mv

cp (copy) copy of the file or directory, the general format is CP [files to copy] [destination], without the option to copy files, and multiple files can be copied to a location; represents -R & lt copy the directory represented ;-p preserve file attributes, because the modified time after time to copy a file copy the past, the equivalent of the newly created time, you want to preserve file modification time will use this option. cp copy command name can have modifications, as long as the new destination to a particular file (e.g., / root represents copied to the root, / root / c indicates a copy to the next to root, and renamed the c)

In addition, cp can also create hard links and soft links to the file, the format is cp 选项 源文件 链接文件to establish a hard link -l representatives, -s on behalf of the establishment of flexible connections.

-a -d and -r is a combination of, on behalf of -d If you want to copy the file is a soft link file, the file copy or soft link, it can also be used as a complete copy of the file permissions, can replace -p.

mv (move) to cut the file and rename, a general format Music Videos [cut to the file or directory] [destination], cp, and the renaming of the same function, you may be simultaneously cut multiple files. If you want to cut a file or directory in the current directory, the file name can be written directly, without having to write the whole path. If the two positions do not write the full path to the file name represents the write-only renamed in the current directory location.

Often you need to change the owner and group files copied or cut pay attention to the file to someone else to use when.

Create a file touch

touch to create a file, add the file name will be able to create, if not create the directory of the current need to write the full path. If you want to create the file filename with spaces must be enclosed in double quotes to include the file name, this is very easy, follow-up treatment is also in trouble, it is not recommended in linux file name spaces.

In addition to the implementation of touch can create a command file, but also the three kinds of time the existing files are unified into now, because sometimes the boot procedures, the time the file may appear significant deviations, then you need to execute this command, add some options touch can freely modify three times (respectively modification time content update, status time status update time, access time access time).

View Files command

cat, tac and nl command

cat view the file contents, add the file name you want to view. -n represents the display line numbers when viewing. View the contents of the file, including special characters: cat -A 文件, editor in linux file carriage return is $, while the windows in the edited file is opened in linux, carriage return is ctrl + M $ (^ M $ ), this when the script is not functioning at this time as long as the file name plus dos2unix will be able to convert it to a linux executable file, this command if not you can manually install: yum -y install dos2unixcommand there unix2dos similar effect.

tac represents rows reverse order view, these two commands do not see a lot of content files.

nl command to add line numbers to print the file content. These three commands are directly view the contents of the file (not flip).

more and less command

more can also view the contents of the file, it displays a percentage number to view the contents of the file, press f or spaces can flip, carriage return line may have a look, q or Q quit reading the representation, but more can not page up. As well as search, browse in the state of the input / Find what you want to enter, you can jump to that position, but can only search down.

less and more similar, but added upturned function, pageup can turn up a page on the arrow to watch his party, less can also find content, input / Enter to find content in browse mode, you can jump to that position, press n skip to the next search word, you can search for it up with? Instead of / can be.

head and tail commands

You can specify head to see the first few lines, head -n 20 文件it represents the first 20 rows of view, if we do not see the option on behalf of the first 10 rows.

display similar tail and head, is to look at the file end of the line, you can use -n to specify the number of rows, -f representatives dynamic view, change file appears tail command will change, commonly used to view the log. Press ctrl + c to exit the view status. tail -n +100 文件View data files represent 100 lines.

Lines 11 through 20 show the file:head -n 20 文件 | tail -n 10

11 to the line 20 displays the file and line number there:cat -n 文件 | head -n 20 | tail -n 10

od command

od command to view the non-text files: od -t c 文件the representative embodiment shows a content ascii, embodiment C represents the ascii, d, f, o, x representing decimal output, floating point number, octal and hex output an output representative of a use of the default character output.

Link command ln

ln (link) to create a link, ln 原文件 链接文件express generate a hard link file, -s representation generation soft link file.

Soft links Hard links
Modify the source file Can be accessed Synchronous modification
Delete files Inaccessible Can be accessed
file type File type is l You need to see the inode, and source files with the same inode
size Small And source files as large as
Change the time New time The same source file
access permission Fully open, but can access depends on the source file And the same source file
limit Can not be established across partitions can not be used for directory
Arrow logo Details are identified with an arrow

The so-called hard link, in fact, more than a public file inode, and the two files in addition to the file names of all the information are the same, regardless of which file name can be linked through to a unique inode reading the file, and then find only datablock, therefore modify which files will eventually affect the two files, and if you delete any of the files, it will not cause data can not be accessed because the inode and block still exists, so hard links safer.

Hard link is essentially a catalog of more than block it, will not have a huge impact on the disk and inode number.

Because you want to link to an inode same, so hard links can not cross file system (partition), as to why not for hard links directory, mainly because of the file in the directory is constantly changing, which can lead to difficult to maintain such a link relationship.

Soft links just create a shortcut to a source file, which is a separate file, so different from the source file and inode size of this file is the space occupied by the file name of the source file, delete the source file causes can not be opened soft links.

You can also create a hard link and soft link with the cp command.

Guess you like

Origin www.cnblogs.com/shizhuoping/p/12515621.html