Some related regular expressions and some temporary files are often used in shell scripts written in Python.) There are also some related files such as the/etc/passwd file, the following is an introduction to the relevant files we will use in the actual operations of writing shell scripts in gPython.
Sys. argv is a list that stores the command line parameters of the python program. Here, sys. argv [0] is the name of the program.
- Simple Procedure for generating dll-independent exe using Python
- Steps required to build a Python Web environment
- Note the Bug modification and. jam file when getting started with Python
- Convert a Python script to an executable program in windows
- Frequently Used functions when writing shell scripts in Python
You can't just say you don't want to practice it. Next we will write a simple script for copying files. My colleague who asked me to write a script two days ago had a directory of tens of thousands of files. He wanted to copy these files to other directories and could not directly copy the directory itself. He tried "cp src/* dest/" and reported a command line too long error. Let me write a script for Python. Start with python:
- import sys,os.path,shutil
- for f in os.listdir(sys.argv[1]):
- shutil.copy(os.path.join(sys.argv[1],f),
sys.argv[2])
Try the post in the linuxapp version-rename all the files in a folder to 10001 ~ 10999. You can write as follows:
- import os.path,sys
- dirname=sys.argv[1]
- i=10001
- for f in os.listdir(dirname):
- src=os.path.join(dirname,f)
- if os.path.isdir(src):
- continue
- os.rename(src,str(i))
- i+=1
The above is an introduction to the regular expression-related content that is frequently used to compile shell scripts in Python. I hope you will gain some benefits.