add a bunch of scripts
This commit is contained in:
4
.obsidian/app.json
vendored
Normal file
4
.obsidian/app.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"alwaysUpdateLinks": true,
|
||||
"showUnsupportedFiles": true
|
||||
}
|
||||
1
.obsidian/appearance.json
vendored
Normal file
1
.obsidian/appearance.json
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{}
|
||||
33
.obsidian/core-plugins.json
vendored
Normal file
33
.obsidian/core-plugins.json
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"file-explorer": true,
|
||||
"global-search": true,
|
||||
"switcher": true,
|
||||
"graph": true,
|
||||
"backlink": true,
|
||||
"canvas": true,
|
||||
"outgoing-link": true,
|
||||
"tag-pane": true,
|
||||
"footnotes": false,
|
||||
"properties": false,
|
||||
"page-preview": true,
|
||||
"daily-notes": true,
|
||||
"templates": true,
|
||||
"note-composer": true,
|
||||
"command-palette": true,
|
||||
"slash-command": false,
|
||||
"editor-status": true,
|
||||
"bookmarks": true,
|
||||
"markdown-importer": false,
|
||||
"zk-prefixer": false,
|
||||
"random-note": false,
|
||||
"outline": true,
|
||||
"word-count": true,
|
||||
"slides": false,
|
||||
"audio-recorder": false,
|
||||
"workspaces": false,
|
||||
"file-recovery": true,
|
||||
"publish": false,
|
||||
"sync": true,
|
||||
"bases": true,
|
||||
"webviewer": false
|
||||
}
|
||||
183
.obsidian/workspace.json
vendored
Normal file
183
.obsidian/workspace.json
vendored
Normal file
@@ -0,0 +1,183 @@
|
||||
{
|
||||
"main": {
|
||||
"id": "c14fb7788bb86e58",
|
||||
"type": "split",
|
||||
"children": [
|
||||
{
|
||||
"id": "b277dc0ec57ac4e5",
|
||||
"type": "tabs",
|
||||
"children": [
|
||||
{
|
||||
"id": "bd0227a0bc51fda3",
|
||||
"type": "leaf",
|
||||
"state": {
|
||||
"type": "empty",
|
||||
"state": {},
|
||||
"icon": "lucide-file",
|
||||
"title": "New tab"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"direction": "vertical"
|
||||
},
|
||||
"left": {
|
||||
"id": "10ee71e8f52d892a",
|
||||
"type": "split",
|
||||
"children": [
|
||||
{
|
||||
"id": "63a8cd2db9e08095",
|
||||
"type": "tabs",
|
||||
"children": [
|
||||
{
|
||||
"id": "50dd7c7842ea0193",
|
||||
"type": "leaf",
|
||||
"state": {
|
||||
"type": "file-explorer",
|
||||
"state": {
|
||||
"sortOrder": "alphabetical",
|
||||
"autoReveal": false
|
||||
},
|
||||
"icon": "lucide-folder-closed",
|
||||
"title": "Files"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "96368e722c01fada",
|
||||
"type": "leaf",
|
||||
"state": {
|
||||
"type": "search",
|
||||
"state": {
|
||||
"query": "",
|
||||
"matchingCase": false,
|
||||
"explainSearch": false,
|
||||
"collapseAll": false,
|
||||
"extraContext": false,
|
||||
"sortOrder": "alphabetical"
|
||||
},
|
||||
"icon": "lucide-search",
|
||||
"title": "Search"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "ecb77e1599effc54",
|
||||
"type": "leaf",
|
||||
"state": {
|
||||
"type": "bookmarks",
|
||||
"state": {},
|
||||
"icon": "lucide-bookmark",
|
||||
"title": "Bookmarks"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"direction": "horizontal",
|
||||
"width": 300
|
||||
},
|
||||
"right": {
|
||||
"id": "cf899824f83d0bec",
|
||||
"type": "split",
|
||||
"children": [
|
||||
{
|
||||
"id": "5b1763d858d0e9ab",
|
||||
"type": "tabs",
|
||||
"children": [
|
||||
{
|
||||
"id": "5a0c75072484915d",
|
||||
"type": "leaf",
|
||||
"state": {
|
||||
"type": "backlink",
|
||||
"state": {
|
||||
"collapseAll": false,
|
||||
"extraContext": false,
|
||||
"sortOrder": "alphabetical",
|
||||
"showSearch": false,
|
||||
"searchQuery": "",
|
||||
"backlinkCollapsed": false,
|
||||
"unlinkedCollapsed": true
|
||||
},
|
||||
"icon": "links-coming-in",
|
||||
"title": "Backlinks"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "85c23228c3824809",
|
||||
"type": "leaf",
|
||||
"state": {
|
||||
"type": "outgoing-link",
|
||||
"state": {
|
||||
"linksCollapsed": false,
|
||||
"unlinkedCollapsed": true
|
||||
},
|
||||
"icon": "links-going-out",
|
||||
"title": "Outgoing links"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "b58ae060bc33155e",
|
||||
"type": "leaf",
|
||||
"state": {
|
||||
"type": "tag",
|
||||
"state": {
|
||||
"sortOrder": "frequency",
|
||||
"useHierarchy": true,
|
||||
"showSearch": false,
|
||||
"searchQuery": ""
|
||||
},
|
||||
"icon": "lucide-tags",
|
||||
"title": "Tags"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "502c9508500b0f41",
|
||||
"type": "leaf",
|
||||
"state": {
|
||||
"type": "outline",
|
||||
"state": {
|
||||
"followCursor": false,
|
||||
"showSearch": false,
|
||||
"searchQuery": ""
|
||||
},
|
||||
"icon": "lucide-list",
|
||||
"title": "Outline"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"direction": "horizontal",
|
||||
"width": 300,
|
||||
"collapsed": true
|
||||
},
|
||||
"left-ribbon": {
|
||||
"hiddenItems": {
|
||||
"switcher:Open quick switcher": false,
|
||||
"graph:Open graph view": false,
|
||||
"canvas:Create new canvas": false,
|
||||
"daily-notes:Open today's daily note": false,
|
||||
"templates:Insert template": false,
|
||||
"command-palette:Open command palette": false,
|
||||
"bases:Create new base": false
|
||||
}
|
||||
},
|
||||
"active": "50dd7c7842ea0193",
|
||||
"lastOpenFiles": [
|
||||
"rename-nested-file-to-parent.md",
|
||||
"remove-timestamps.md",
|
||||
"remove-n-chars-from-name.md",
|
||||
"remove-n-chars-from-name_handle-duplicates.md",
|
||||
"recursively-extract-artist-from-filename.md",
|
||||
"print-all-files-and-folders.md",
|
||||
"print-all-files-and-folders-to-file.md",
|
||||
"move-files-to-year-and-month-dirs.md",
|
||||
"move-file-into-dir-with-same-name.md",
|
||||
"move-file-in-dir-with-same-name.md",
|
||||
"find-short-videos.md",
|
||||
"filename-as-metadata-title.md",
|
||||
"bulk-move.md",
|
||||
"bring-files-up-one-dir.md",
|
||||
"auto-fill-missing-artist-tags.md"
|
||||
]
|
||||
}
|
||||
21
add-prefix-to-file.md
Normal file
21
add-prefix-to-file.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# Prefix
|
||||
|
||||
> Add prefix to files
|
||||
|
||||
```bash
|
||||
for f in *; do
|
||||
if [ -f "$f" ]; then
|
||||
mv "$f" "PREFIX - $f"
|
||||
fi
|
||||
done
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
> Add prefix to dirs
|
||||
|
||||
```bash
|
||||
for d in */ ; do
|
||||
mv "$d" "PREFIX - $d"
|
||||
done
|
||||
```
|
||||
50
auto-fill-missing-artist-tags.md
Normal file
50
auto-fill-missing-artist-tags.md
Normal file
@@ -0,0 +1,50 @@
|
||||
# Auto fill missing Artist/Title Tags
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
DIRECTORY="/path/to/dir"
|
||||
LOGFILE="/path/to/dir/logfile.log"
|
||||
|
||||
artist_like_attributes=( "ARTISTS" "ARTIST SORT ORDER" "ALBUM ARTIST" "ALBUM ARTIST SORT ORDER" )
|
||||
title_like_attributes=( "ALBUM" )
|
||||
|
||||
find "$DIRECTORY" -type f \( -iname "*.flac" -o -iname "*.mp3" -o -iname "*.opus" \) | while IFS= read -r file; do
|
||||
echo "Processing file: $file" >> $LOGFILE
|
||||
|
||||
artist=$(ffprobe -v error -show_entries format_tags=artist -of default=noprint_wrappers=1:nokey=1 "$file")
|
||||
title=$(ffprobe -v error -show_entries format_tags=title -of default=noprint_wrappers=1:nokey=1 "$file")
|
||||
|
||||
if [ -n "$artist" ]; then
|
||||
metadata_to_set=()
|
||||
|
||||
for attribute in "${artist_like_attributes[@]}"; do
|
||||
value=$(ffprobe -v error -show_entries "format_tags=$attribute" -of default=noprint_wrappers=1:nokey=1 "$file")
|
||||
|
||||
if [ -z "$value" ]; then
|
||||
metadata_to_set+=(-metadata "$attribute=$artist")
|
||||
fi
|
||||
done
|
||||
|
||||
for attribute in "${title_like_attributes[@]}"; do
|
||||
value=$(ffprobe -v error -show_entries "format_tags=$attribute" -of default=noprint_wrappers=1:nokey=1 "$file")
|
||||
|
||||
if [ -z "$value" ]; then
|
||||
metadata_to_set+=(-metadata "$attribute=$title")
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${#metadata_to_set[@]} -ne 0 ]; then
|
||||
temp_file=$(dirname "$file")/temp_$(basename "$file")
|
||||
|
||||
ffmpeg -i "$file" -c copy "${metadata_to_set[@]}" -y "$temp_file" && mv -f "$temp_file" "$file"
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Successfully updated: $file" >> $LOGFILE
|
||||
else
|
||||
echo "FFmpeg failed for: $file" >> $LOGFILE
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
||||
```
|
||||
11
bring-files-up-one-dir.md
Normal file
11
bring-files-up-one-dir.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# Bring files up one dir
|
||||
|
||||
> Bring files up by one level from their nested dirs
|
||||
|
||||
```bash
|
||||
find . -mindepth 2 -type f \( -name "*.mkv" -o -name "*.mp4" -o -name "*.avi" \) -exec sh -c '
|
||||
for file do
|
||||
mv -- "$file" "$(dirname "$file")/.."
|
||||
done
|
||||
' sh {} +
|
||||
```
|
||||
14
bulk-move.md
Normal file
14
bulk-move.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# Bulk Move
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
INPUT_FILE="folders_and_files_to_move.txt"
|
||||
DESTINATION_DIR="/path/to/dir"
|
||||
|
||||
while read -r dir; do
|
||||
mv "$dir" "$DESTINATION_DIR"
|
||||
done < "$INPUT_FILE"
|
||||
|
||||
echo "All specified directories have been moved to '$DESTINATION_DIR'"
|
||||
```
|
||||
105
ffmpeg.md
Normal file
105
ffmpeg.md
Normal file
@@ -0,0 +1,105 @@
|
||||
# Ffmpeg
|
||||
|
||||
> Convert mkv to gif
|
||||
```bash
|
||||
ffmpeg -i "input.mkv" -vf "fps=10,scale=320:-1:flags=lanczos" -c:v gif -f gif "output.gif"
|
||||
```
|
||||
|
||||
```bash
|
||||
ffmpeg -i "input.mkv" -vf "fps=30,scale=1920:-1:flags=lanczos" -c:v gif -f gif "output.gif"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
> Convert mkv to gif and get rid of that pattern
|
||||
```bash
|
||||
ffmpeg -i "input.mkv" -vf palettegen palette.png
|
||||
ffmpeg -i "input.mkv" -i palette.png -lavfi "fps=30,scale=1920:-1:flags=lanczos [x]; [x][1:v] paletteuse=dither=none" "output.gif"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
> Convert mkv to mp4
|
||||
```bash
|
||||
ffmpeg -i "input.mkv" -codec copy "output.mp4"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
> Detect silence
|
||||
```bash
|
||||
ffmpeg -i "Song.flac" -af silencedetect=noise=-30dB:d=5 -f null - 2>&1 | grep 'silence_'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
> Check tags
|
||||
```bash
|
||||
ffprobe -v error -show_entries format_tags -of default=noprint_wrappers=1 "Song.flac"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
> Extract aac from avi
|
||||
```bash
|
||||
ffmpeg -i input-video.avi -vn -acodec copy output-audio.aac
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
> Increase volume of mp3
|
||||
```bash
|
||||
ffmpeg -i input.mp3 -af volume=1.5 output.mp3
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
> Convert DTS to AAC
|
||||
```bash
|
||||
ffmpeg -i "Movie [DTS] [1080p].mp4" -c:v copy -c:a aac -b:a 256k "Movie [AAC] [1080p].mp4"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
> Check for errors
|
||||
```bash
|
||||
ffprobe -v error -show_entries frame=pkt_pts_time -of csv=p=0 "input.mp4" > errors.log
|
||||
ffmpeg -v error -i "output.mp4" -c copy -f null - 2> errors2.log
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
> Get audio channels + languages of a file
|
||||
```bash
|
||||
ffprobe -v error -select_streams a -show_entries stream=index,codec_type,channels,channel_layout,codec_name,codec_long_name:stream_tags=language -of default=noprint_wrappers=1 "input.mkv"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
> Cut up to certain timestamp
|
||||
```bash
|
||||
ffmpeg -i "input.mkv" -to 01:37:49 -c copy -map 0 "output.mkv"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
> Cut starting from specific timeframe
|
||||
```bash
|
||||
ffmpeg -i "input.mp4" -ss 00:05:28 -c copy -avoid_negative_ts 1 "output.mp4"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
> Extract single frame within timeframe close to keyframe
|
||||
```bash
|
||||
ffmpeg -ss 00:02:07 -to 00:02:10 -i "input.mp4" -vf "select='eq(pict_type,PICT_TYPE_I)'" -vsync vfr thumbnail_%03d.png
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
> Extract single frame at specific timestamp
|
||||
```bash
|
||||
ffmpeg -ss 00:00:03 -i "input.mp4" -vf "select='eq(pict_type,PICT_TYPE_I)'" -frames:v 1 output.png
|
||||
```
|
||||
|
||||
---
|
||||
18
filename-as-metadata-title.md
Normal file
18
filename-as-metadata-title.md
Normal file
@@ -0,0 +1,18 @@
|
||||
# Filename as metadata title
|
||||
|
||||
> Set the title in the metadata of all mp4 files based on the respective filename
|
||||
|
||||
```bash
|
||||
for FILE_PATH in *.mp4; do
|
||||
if [ ! -f "$FILE_PATH" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
BASE_NAME=$(basename "$FILE_PATH" .mp4)
|
||||
TEMP_FILE="${FILE_PATH}_temp.mp4"
|
||||
|
||||
ffmpeg -i "$FILE_PATH" -c copy -metadata title="$BASE_NAME" "$TEMP_FILE" && mv "$TEMP_FILE" "$FILE_PATH"
|
||||
done
|
||||
|
||||
echo "Metadata title set for all MP4 files in directory"
|
||||
```
|
||||
31
find-short-videos.md
Normal file
31
find-short-videos.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# Find short Videos
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
DIR="/path/to/dir"
|
||||
DURATION_THRESHOLD_SECONDS=300
|
||||
IGNORED_FOLDERS=("backdrops")
|
||||
OUTPUT_FILE="short_video_dirs.txt"
|
||||
|
||||
> "$OUTPUT_FILE"
|
||||
|
||||
find . -type f -name "$DIR/*.mp4" | while read -r file; do
|
||||
parent_dir=$(dirname "$file")
|
||||
|
||||
for ignored_folder in "${IGNORED_FOLDERS[@]}"; do
|
||||
if [[ "$parent_dir" == *"$ignored_folder"* ]]; then
|
||||
continue 2
|
||||
fi
|
||||
done
|
||||
|
||||
length=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$file")
|
||||
length=$(printf "%.0f\n" "$length")
|
||||
|
||||
if [ "$length" -lt "$DURATION_THRESHOLD_SECONDS" ]; then
|
||||
grep -qxF "$parent_dir" "$OUTPUT_FILE" || echo "$parent_dir" >> "$OUTPUT_FILE"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Operation complete. The list of parent directories has been saved to $OUTPUT_FILE."
|
||||
```
|
||||
20
move-file-into-dir-with-same-name.md
Normal file
20
move-file-into-dir-with-same-name.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# Move file into dir with same name
|
||||
|
||||
> Move all mp4 files into a dir with the same name as the file
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
find . -maxdepth 1 -type f -iname *.mp4 -exec bash -c '
|
||||
for file in "$@"; do
|
||||
# Extract the base name without the extension
|
||||
base="${file%.mp4}"
|
||||
|
||||
# Create a new directory with the base name
|
||||
mkdir -p "${base}"
|
||||
|
||||
# Move the MP4 file into the newly created directory
|
||||
mv "$file" "${base}/"
|
||||
done
|
||||
' bash {} +
|
||||
```
|
||||
22
move-files-to-year-and-month-dirs.md
Normal file
22
move-files-to-year-and-month-dirs.md
Normal file
@@ -0,0 +1,22 @@
|
||||
# Move files to year and month dirs
|
||||
|
||||
> Extract date from folder name and move into year and month separated sub dirs
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
for dir in */; do
|
||||
if [[ -d "$dir" ]]; then
|
||||
if [[ $dir =~ ([0-9]{4}-[0-9]{2}-[0-9]{2}) ]]; then
|
||||
date=${BASH_REMATCH[1]}
|
||||
year=${date:0:4}
|
||||
month=${date:5:2}
|
||||
|
||||
mkdir -p "$year/$month"
|
||||
mv "$dir" "$year/$month/"
|
||||
else
|
||||
echo "The directory '$dir' does not contain a valid date."
|
||||
fi
|
||||
fi
|
||||
done
|
||||
```
|
||||
41
print-all-files-and-folders.md
Normal file
41
print-all-files-and-folders.md
Normal file
@@ -0,0 +1,41 @@
|
||||
# Print all files and folders
|
||||
|
||||
> Save all file and folder names in a directory to a file
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
OUTPUT_FILE="directory_contents.txt"
|
||||
|
||||
> "$OUTPUT_FILE"
|
||||
|
||||
echo "Listing all files and folders in current dir"
|
||||
|
||||
for item in /*; do
|
||||
if [ -f "$item" ]; then
|
||||
echo "$(basename "$item")" >> "$OUTPUT_FILE"
|
||||
elif [ -d "$item" ]; then
|
||||
echo "$(basename "$item")" >> "$OUTPUT_FILE"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Contents have been written to $OUTPUT_FILE."
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
> Get all file and folder names in a directory
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
echo "Listing all files and folders in current dir"
|
||||
|
||||
for item in /*; do
|
||||
if [ -f "$item" ]; then
|
||||
echo "$(basename "$item")"
|
||||
elif [ -d "$item" ]; then
|
||||
echo "$(basename "$item")"
|
||||
fi
|
||||
done
|
||||
```
|
||||
31
recursively-extract-artist-from-filename.md
Normal file
31
recursively-extract-artist-from-filename.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# Recursively extract artist from filename
|
||||
|
||||
> Used to extract the first artist name, assuming it sits between the first " - " and second " - "
|
||||
|
||||
```bash
|
||||
#!/bin/sh
|
||||
|
||||
SEARCH_DIR="/path/to/dir"
|
||||
OUTPUT_FILE="artist_names.txt"
|
||||
|
||||
cd "$SEARCH_DIR" || exit
|
||||
|
||||
> "$OUTPUT_FILE"
|
||||
|
||||
find . -type f -name '* - *' | while read -r file; do
|
||||
intermediate_string=$(echo "$file" | sed -n 's/.* - \(.*\) - .*/\1/p')
|
||||
|
||||
artist=$(echo "$intermediate_string" | \
|
||||
sed -e 's/ x .*//i' \
|
||||
-e 's/ X .*//i' \
|
||||
-e 's/ ft\. .*//i' \
|
||||
-e 's/ feat\. .*//i' \
|
||||
-e 's/ & .*//i' \
|
||||
-e 's/, .*//i' \
|
||||
-e 's/ + .*//i')
|
||||
|
||||
echo "$artist" >> "$OUTPUT_FILE"
|
||||
done
|
||||
|
||||
cd - || exit
|
||||
```
|
||||
89
regex-stuff.md
Normal file
89
regex-stuff.md
Normal file
@@ -0,0 +1,89 @@
|
||||
# Regex Stuff
|
||||
|
||||
> Remove everything from first `?` (including) in filenames recursively
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
START_DIR="."
|
||||
|
||||
find "$START_DIR" -type f -print0 | while IFS= read -r -d '' file; do
|
||||
dir=$(dirname "$file")
|
||||
base=$(basename "$file")
|
||||
new_base="${base%%\?*}"
|
||||
|
||||
if [[ "$base" != "$new_base" ]]; then
|
||||
mv -n "$file" "${dir}/${new_base}"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "File renaming complete."
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
> Extract from strings in file
|
||||
|
||||
```bash
|
||||
grep -oP "href='\K[^']+?(?=')" "Bookmarks.html" > urls.txt
|
||||
grep -oP "HREF=\"\K[^\"]+?(?=\")" "Bookmarks2.html" > urls2.txt
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
> Replace something in dir name
|
||||
|
||||
```bash
|
||||
search_string="REPLACE ME - "
|
||||
replace_string=""
|
||||
|
||||
for d in */ ; do
|
||||
d="${d%/}"
|
||||
|
||||
if [[ "$d" == *"$search_string"* ]]; then
|
||||
new_d="${d/$search_string/$replace_string}"
|
||||
|
||||
mv -- "$d" "$new_d"
|
||||
fi
|
||||
done
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
> Replace anywhere, case insensitive
|
||||
|
||||
```bash
|
||||
for f in *; do
|
||||
if [ -f "$f" ]; then
|
||||
newname=$(echo "$f" | sed 's/some\.string/A new String/gi')
|
||||
|
||||
mv -- "$f" "$newname"
|
||||
fi
|
||||
done
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
> Replace something at beginning of filename
|
||||
|
||||
```bash
|
||||
for f in *; do
|
||||
if [ -f "$f" ]; then
|
||||
newname=$(echo "$f" | sed 's/^some\.string/A new String/')
|
||||
mv -- "$f" "$newname"
|
||||
fi
|
||||
done
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
> Replace anywhere in filename
|
||||
|
||||
```bash
|
||||
for f in *; do
|
||||
if [ -f "$f" ]; then
|
||||
newname=$(echo "$f" | sed 's/BEFORE/After/gi')
|
||||
mv -- "$f" "$newname"
|
||||
fi
|
||||
done
|
||||
```
|
||||
51
remove-n-chars-from-name.md
Normal file
51
remove-n-chars-from-name.md
Normal file
@@ -0,0 +1,51 @@
|
||||
# Remove N chars from name
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
TARGET_DIR="."
|
||||
REMOVE_N_CHARS=8
|
||||
|
||||
for dir in "$TARGET_DIR/*/"; do
|
||||
dir="${dir%/}"
|
||||
|
||||
new_dir="${dir:$REMOVE_N_CHARS}"
|
||||
|
||||
mv -- "$dir" "$new_dir"
|
||||
done
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
TARGET_DIR="."
|
||||
REMOVE_N_CHARS=8
|
||||
|
||||
generate_unique_dir_name() {
|
||||
local base_name=$1
|
||||
local counter=2
|
||||
local new_name
|
||||
|
||||
while true; do
|
||||
new_name="${base_name}_${counter}"
|
||||
if [[ ! -d "$new_name" ]]; then
|
||||
echo "$new_name"
|
||||
break
|
||||
fi
|
||||
((counter++))
|
||||
done
|
||||
}
|
||||
|
||||
for dir in "$TARGET_DIR/*/"; do
|
||||
dir="${dir%/}"
|
||||
new_dir="${dir:$REMOVE_N_CHARS}"
|
||||
|
||||
if [[ -d "$new_dir" ]]; then
|
||||
new_dir=$(generate_unique_dir_name "$new_dir")
|
||||
fi
|
||||
|
||||
mv -- "$dir" "$new_dir"
|
||||
done
|
||||
```
|
||||
18
remove-timestamps.md
Normal file
18
remove-timestamps.md
Normal file
@@ -0,0 +1,18 @@
|
||||
# Remove timestamps
|
||||
|
||||
> Remove timestamps from files and folders
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
for file in [0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]*; do
|
||||
if ! [[ $file =~ ^[0-9][0-9]-[0-9][0-9]-[0-9]{4}\ [0-9]{1,2}#[0-9]{2}\ (AM|PM)\ -\ ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
newname=$(echo "$file" | sed -E 's/^[0-9]{2}-[0-9]{2}-[0-9]{4} [0-9]{1,2}#[0-9]{2} (AM|PM) - //')
|
||||
mv -- "$file" "$newname"
|
||||
done
|
||||
|
||||
echo "Files have been renamed."
|
||||
```
|
||||
23
rename-nested-file-to-parent.md
Normal file
23
rename-nested-file-to-parent.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# Rename nested file to parent
|
||||
|
||||
> Go through all folders, check if mp4 is in there. If so, rename the mp4 to the same as it's respective parent folder
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
for dir in */; do
|
||||
if [[ -d "$dir" ]]; then
|
||||
dir_name="${dir%/}"
|
||||
mp4_file=$(find "$dir" -maxdepth 1 -type f -name '*.mp4' | head -n 1)
|
||||
|
||||
if [[ -n "$mp4_file" ]]; then
|
||||
new_filename="${dir_name}.mp4"
|
||||
|
||||
mv -n "$mp4_file" "${dir}/${new_filename}"
|
||||
echo "Renamed '$mp4_file' to '${dir}/${new_filename}'"
|
||||
else
|
||||
echo "No .mp4 file found in $dir"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
```
|
||||
Reference in New Issue
Block a user