Scripting - Chapter 6: The Filesystem
There are a couple of good ways to manipulate your files and directories in Bash. We'll give you the most important commands for writing PlayOnLinux scripts.
Contents
PlayOnLinux temporary directories
You can use a temporary directory for your script when it runs. To do that:
Syntax:
POL_System_TmpCreate "NameOfTemporaryDirectory"
Example:
POL_System_TmpCreate "MozillaFirefox"
It will create a variable $POL_System_TmpDir that will contain the path of the temporary directory. In this directory, you'll be free to store and modify all the files you want, for the whole script duration.
It is recommended for install scripts to first check (as far as possible) that all needed resources are available before prefix creation, and installation itself. POL_System_TmpCreate can become very useful to this end, because it doesn't require any prefix to already exist.
Delete the temporary directory
Syntax:
POL_System_TmpDelete
Example:
POL_System_TmpDelete
Other filesystem commands
Switching directory
Syntax:
cd "path"
Example:
cd "/path/to/a/directory"
cd "$HOME" # Switch to user's personal directory
cd "$CDROM" # Switch to CD/DVD directory
cd "$POL_System_TmpDir" # Switch to temporary directory
Removing a file or directory
Syntax:
rm "filename"
rm -r "directory"
Example:
rm "$POL_System_TmpDir/file.txt"
rm -r "$POL_System_TmpDir/directory"
If they are any remaining files and/or subdirectories in the directory you're removing, they'll also be removed for good.
Copying a file or a directory
Syntax:
cp "SourceFile" "TargetFile"
cp -r "SourceDirectory" "TargetDirectory"
Examples of file copy:
cp "/home/user/file.txt" "/home/user/copy_of_file.txt"
cp "/home/user/file.txt" "/home/user/data/file.txt"
cp "$CDROM/file.txt" "$POL_System_TmpDir/file.txt"
Example of directory copy:
cp -r "/home/user/My Folder" "/home/user/Desktop/Test/"
Moving or renaming a file or directory
Syntax:
mv "/home/user/file.txt" "home/user/data.txt"
mv "/home/user/file.txt" "/home/user/Desktop/file.txt"
mv "/home/user/file.txt" "/home/user/Desktop/data.txt"
1st command will rename the file file.txt to data.txt.
2nd command will move the file.
3rd command will move AND rename the file.
Previous: Chapter 5: Wine