directory management with bash.
See How you can work in Bash with the working directory (ie current, PWD, OLDPWD)
To get the space by directory, you can use the du command. It summarize disk usage of each FILE, recursively for directories.
With a redirection, you can export the result and find the directories that used the most space.
du mydirectory > du.csv
For one directory:
du -hs
13G
where the options mean:
The following command gives the top 10 subdirectory from the current directory by disk usage.
du | grep logs | sort -n | cut -f 2- | while read a; do du -sh "$a"; done | tail
3.3M ./instances/instance1/diagnostics/logs/OracleBIJavaHostComponent
6.3M ./instances/instance1/diagnostics/logs/OPMN/opmn
6.3M ./instances/instance1/diagnostics/logs/OPMN
14M ./instances/instance1/diagnostics/logs/OracleBIPresentationServicesComponent/coreapplication_obips1
14M ./instances/instance1/diagnostics/logs/OracleBIPresentationServicesComponent
25M ./instances/instance1/diagnostics/logs
40M ./Oracle_BI1/cfgtoollogs/oui
40M ./oracle_common/cfgtoollogs/oui
40M ./oracle_common/cfgtoollogs
40M ./Oracle_BI1/cfgtoollogs
where:
For OBI:
$fmw_home/user_projects/domains/bifoundation_domain/servers/AdminServer/logs
$fmw_home/user_projects/domains/bifoundation_domain/servers/bi_server1/logs
$fmw_home/instances/instance1/diagnostics/logs/OracleBIServerComponent/coreapplication_obis1
#!/bin/bash
for filename in /$baseDir/dirPath/*.txt; do
echo $filename
done
for childPath in /my/directory/path/*; do
if [ -d "$childPath" ]; then
REPO_DIRS+=("$childPath")
fi
done
if [ -d /my/path ]; then
echo 'This is a directory'
else
echo 'This is not a directory'
fi
if [ -n "$(ls -A "$GDRIVE_MOUNT_PATH")" ]; then
echo_err "Google Drive Mount Directory ($GDRIVE_MOUNT_PATH) is not empty."
exit 1
fi
see also: zip
tar -pczf myDirectory.tar.gz myDirectory/
mv /path/to/source /path/to/dest
where:
Transferring folders
tar cf - [source-path] | mbuffer -m 1024M | ssh [server] '(cd /[destination-path]; tar xf -)'
cp -r /Path/To/sourceDirectory /Path/To/TargetDirectory
where:
It will create the target directory.
rmdir directoryName
rm -rf letters/
Tip using rm with a variable should use the following expression to avoid deleting your whole disk if the variable my_variable is empty or not set
rm -rf "${my_variable:?}"/*
mv myDirectoryName MyNewDirectoryName
mkdir -p /parentDoesnExist/myDir