Bash - Directory

Bash Liste Des Attaques Ovh

About

directory management with bash.

Structure

File System Hierarchy Standard (FHS)

Management

Current

See Bash - (Current|Working) Directory

Get

the space by directory recursively

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

the space for one directory

For one directory:

du -hs
13G 

where the options mean:

  • s: summary
  • h: human readable

the top disk usage by directory

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:

  • du list the subdirectory with the disk usage
  • grep filters the result for only the logs subdirectory
  • sort sort the result
  • tail shows only the 10 last lines

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

Loop through children

  • files
#!/bin/bash
for filename in /$baseDir/dirPath/*.txt; do
    echo $filename
done
  • directory
for childPath in /my/directory/path/*; do
    if [ -d "$childPath" ]; then
      REPO_DIRS+=("$childPath")
    fi
done

Check if a path is a directory

if [ -d /my/path ]; then
  echo 'This is a directory'
else
  echo 'This is not a directory'
fi

make a zip file

see also: zip

tar -pczf myDirectory.tar.gz myDirectory/

move a directory

mv /path/to/source /path/to/dest

where:

  • mv = move Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.

Transfer a directory

Transferring folders

  • rsync
  • or with the following pipeline (compress, buffer, transfer and uncompress)
tar cf - [source-path] | mbuffer -m 1024M | ssh [server] '(cd /[destination-path]; tar xf -)' 

copy a directory

cp -r /Path/To/sourceDirectory /Path/To/TargetDirectory

where:

  • cp = copy
  • r = recursive

It will create the target directory.

Delete a directory

  • Remove an empty directory
rmdir directoryName
  • Remove a directory and all sub without prompting
rm -rf letters/

Rename a directory

mv myDirectoryName MyNewDirectoryName

Create directory

  • With parent
mkdir -p  /parentDoesnExist/myDir





Discover More
Bash Liste Des Attaques Ovh
Bash - Conditional Expression

A predicate or boolean expression is known in Bash as a Conditional Expression. It is a command that returns an exit status of 0 or 1. The conditional expression is part of the compound expression. ...
Bash Liste Des Attaques Ovh
Bash - Conditional Operator

Conditional Operator are option like syntax (ie -x) that are used in a conditional expression -f to check if the path is a file -d to check if the path is a directory -n to check if a variable/parameter...
Bash Liste Des Attaques Ovh
Bash - dirs (list of remembered directories)

Stack/list of remembered directories. You can change of directories and return to the directory from which you came. Without options, displays the list of currently remembered directories. ...
Bash Liste Des Attaques Ovh
Linux - find command

Search, print information and takes actions on files in a directory hierarchy. Find use stat to extract its information File Metadata Synbol Default Description '-H', '-L' and '-P' options control...
Bash Liste Des Attaques Ovh
Linux - ls (List directory content)

ls is a Linux Command utility that lists the contents of a directory ll is an alias of “ls -la” You can also list files and directories with the find command This script will: list the...



Share this page:
Follow us:
Task Runner