File operations are very basic and important content in the program, while paths, files, directories, and I/O are common topics in file operations, I would like to summarize these common problems and try to provide some solutions for each problem.
File operations are very basic and important in the program, and the path, files, directories and I/O are common topics in the file operation, here want to summarize these common problems, for each problem, as far as possible to provide some
many times when using the Linux shell, we need to handle the file name or directory name, the usual operation is to extract the file name from the path, extract the directory name from the path, extract the file suffix name, and so on. For example,
First, use ${}1, ${var##*/}The purpose of this command is to remove the variable var from the left side of the last '/' character and its left side of the content, return from the left side of the last '/' (excluding the character) to the right of
1:OS. Listdir (PATH) // path is the Directory
The function is equivalent to executing the Dir command in the path directory. The returned result is of the list type.PrintOS. Listdir ('..')
2:OS. Path.Walk(Path, visit, ARG)
Path: the
1:os.listdir (Path)//path as a directory
function is equivalent to executing the dir command in the path directory, returning to the list type
Print Os.listdir ('.. ')
2:os.path.walk (Path,visit,arg)
Path: Is the directory that will be
Read Catalogue
Begin
Path action on a string of pathsGet suffixCan merge pathsGet file nameDirectory and DirectoryInfo operations on directoriesDetermine if a directory existsCreate a DirectoryDelete DirectoryGet all subdirectories
Linux Directory ConfigurationAfter learning about the types and attributes of each file, and how to change the information about file properties/permissions, let's see why every Linux distributions their profiles, executable files, and every
1:os.listdir (path)//path as Directory
function is equivalent to executing the dir command in the path directory, returning to the list type
Print Os.listdir ('.. ')
2:os.path.walk (Path,visit,arg)
Path: Is the directory that will be traversed
Visit:
7.4 "Linux learning is not difficult" file/directory Management (4): cd command Change working directory pathUse the CD command to change the user's working directory path. Working directory paths can use absolute or relative path names, absolute
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.