Last article: Linux file command proficiency guide (1)
File Processing Command
Profiling a file list
The ls command is used to view the list of files in any directory where the user has the execution permission. This command has many interesting options. For example:
$ ls -liah *22684 -rw-r--r-- 1 bluher users 952 Dec 28 18:43 .profile19942 -rw-r--r-- 1 scalish users 30 Jan 3 20:00 test2.out925 -rwxr-xr-x 1 scalish users 378 Sep 2 2002 test.sh
|
The above list shows eight columns:
Column 1st indicates the inode of the file, because we use the-I option. The remaining columns are displayed normally using the-l option.
The 2nd column displays the file type and file access permissions.
The number of links displayed in the 3rd column, including directories.
Columns 4th and 5th show the file owner and group owner. Here, the owner "bluher" belongs to the group "users ".
The size unit of the file displayed in the 6th column is the displayed unit, rather than the default number of bytes, because the-h option is used.
7th columns show the date. It looks like three columns), including month, day, and year, and the time of the day.
The file name is displayed in the 8th column. Use-a in the option list to include a list of hidden files such as. profile.
Process files
You can move (mv), copy (cp), or delete (rm) files and directories. It is usually a good idea to use the-I option wisely for confirmation.
$ Cp-I ls. out ls2.out
Cp: overwrite 'ls2. out '?
The mv command allows you to use the-B option, which will make a backup copy before moving the file. Rm and cp accept powerful but dangerous-r options that will be recursively executed in a directory and its files.
$ Rm-ir Test
Rm: descend into directory 'test '? Y
You can use mkdir to create a directory and rmdir to delete the directory. However, because rmdir cannot be used to delete directories containing files, it is usually easier to use the rm plus-r option.
For security reasons, all files are owned and protected. File Access permission or file mode) contains the same 10 characters as mentioned earlier:
The first character indicates the file type. The most common is-represents a file, d represents a directory, and l represents a link.
The next nine characters are access permissions for three user categories: file owner characters 2-4, user group (5-7), and others (8-10 ), r indicates the read permission, w indicates the write permission, and x indicates the execution permission on a file. Break number-if any of the nine locations appears, this operation is prohibited for users of this category.
You can use the chmod command to set the access permission through the character symbol or binary mask. To use the binary mask, you must convert the character representation of the three permission groups to the binary format and convert it to the octal format:
User Type: other user groups of the owner
Character representation: rwx r-x r --
Binary: 111 101 100
Octal representation: 7 5 4
Grant the write permission to the user group. You can use:
Chmod g + w test. sh or chmod 774 test. sh
Use the umask command to set local file permissions in the/etc/init. dev file within the system or in the. profile file by default. This command indicates that the default permission is obtained by subtracting 777 from the number:
$ Umask 022
This will generate a default 755 File Permission for all new files created by the user.
You can use chown to modify the File Ownership:
$ Chown bluher ls. out
Here, bluher is the new file owner. Similarly, the Group membership will be modified as follows:
$ Chgrp devgrp ls. out
Here, devgrp is a new user group.
Ls does not provide text and binary information. To learn this information, you can use the file * command.
Rename a file
Two popular methods to assign multiple names to a file are using links and alias commands. Alias can be used to create a more convenient name for a longer command:
$ Alias ll = 'LS-l'
$ Ll
Note the use of single quotes, which enables BASH to pass the project to the alias, rather than estimate it by itself. Aliases can also be abbreviated as long path names:
$ Alias jdev9i =/jdev9i/jdev/bin/jdev
For more information about alias and Its Anti-command unalias, see the "shell builtin commands" sub-part on the BASH man page. In the last example, an environment variable is defined to achieve the same result.
$ Export JDEV_HOME =/jdev9i/jdev/bin/jdev
$ Echo $ JDEV_HOME
/Jdev9i/jdev/bin/jdev
$ JDEV_HOME
The link allows several file names to reference a single source file in the following format:
Ln [-s] fileyouwanttolinkto newname
Separate ln command to create a hard link to the file, and use the-s option to create a symbolic link. In short, a hard link can hardly be separated from the original file except that the inode of the two files will be the same ). Symbolic Links are easy to differentiate because they appear in a long file list and use-> to indicate the source file. l indicates the file type.
Related Articles]
- Linux file command proficiency guide (1)
- Linux file command proficiency Guide (2)
- Linux file command proficiency Guide (3)