# File and Directory Tools
- `pwd` shows presenting working directory
- `cd target` change directory to target
- if `cd` only, we move to user's home directory or `~`
- `ls` lists contents of current directory
- `touch file.text` creates file.text or updates last modified time
- `mkdir dir` creates dir folder
- `rmdir target` removes folder target if empty
- `mv source dest` moves source file to dest
- `cp source dest` copies source file to dest
- `rm target` to remove target file
- `rm -ri folder` to recursively remove a folder with interactivity
- `rm -rf *` removes everything in current directory
- `tree` shows ASCII tree hierarchy for current directory ![[images/Pasted image 20250806172900.png]]
- `find options search_path expression` searches the path based on the input expression
- `-name` for pattern matching with regular expression support ![[images/Pasted image 20250802172111.png]]
- `-perm` displays files with matching permission string (either octal or symbolic are supported inputs) ![[images/Pasted image 20250802172203.png]]
- `-size` displays files with matrxhing size
- `find tmp -size 0` finds files in temp directory that are 0 size
- `-empty`, `-readable`, `-writable`, `-executable`
- `-fstype`
- `locate options expression` searches across `/var/lib/mlocate`
- uses globbing by default
- adds * to beginning and end of expression
- -r for regular expression in place of pattern
- -c for count of files that match pattern
- -i for case insensitive
- -q for quiet mode w/o errors
- `ldd target` displays a list of all shared libraries that a given executable or shared library depends on
# File Metadata
- `file target` shows file type for target
- `stat target` shows detailed metadata for target
- `which target` outputs location where target is stored ![[images/Pasted image 20250802134527.png]]
- `type target` shows info associated with target ![[images/Pasted image 20250802134535.png]]
- `wc file_name` shows lines, word, byte counts for file ![[images/Pasted image 20250802134810.png]]
- `du -h` to show size of files in current directory
- `du -hs target` to show size of target file
- `du -h --threshold=100M` shows all files and directories over 100MB
# Links
- hard link
- `ln first second`
- second points to same inode as first
- if one file is deleted, the other still exists
- if either file is modified, both are modified
- symbolic link
- `ln -s first second`
- second file points to first file
- if either file is modified, both are modified
- if first file is deleted, the second becomes a dead link
- dead links are a potential malware vector
- `readlink -f target_link` shows root of a symbolic link
- -v for verbose output
- useful when there's a long chain of symbolic links