-
- Find file by filename:
find ./foo -name foo.txt
- Find file by filename starts with / contains (case insensitive):
find . -iname foo*
find . -iname *foo*
etc. - Find dir:
find ./foo -type d -name bar
- Find file by modification time:
find ./foo -mtime -X
or+X
where X = number of days. So, +1 would find files modified more than one day ago. - Search for text within mult files:
find ./ -type f -name "*.md" -exec grep 'foo' {} \;
- Find and replace text in a range of files:
find ./ -type f -exec sed -i '' 's/find/replace/g' {} \;
- Find files by size:
find . -type f -size +100M
- Find files by size & print size in KB (requires findutils):
gfind . -type f -size +3M -printf "%p %k KB\n"
- Find files by size & print size in bytes:
find . -type f -size +3M -exec stat -f "%z %N" {} \;
- Find files by size & print fileinfo including
-lh
formatted size:find . -type f -size +3M -exec ls -lh \{\} \;
- Find file by filename:
-
- Find text by file ext.:
grep 'foo' ./*.html
- Find text by file ext.:
-
- Resize all images in cwd with H / W cap:
sips -Z SOME_NUMBER *.jpg
- ImageMagick
- Resize all images in cwd maintaining aspect ratio - add padding where image does not fit
mogrify -resize 500x600 -background white -gravity center -extent 500x600 *
- Resize all images in cwd maintaining aspect ratio - add padding where image does not fit
- Resize all images in cwd with H / W cap:
-
- Zip entire dir:
zip -r name_of_new_zip_file.zip dir_to_zip
- Zip entire dir:
-
- from log path:
watch tail your_log_name_here.log
- from log path:
-
- Replace any spaces in dir/file names with underscores:
for f in *\ *; do mv "$f" "${f// /_}"; done
- Replace text in file names (this example depth=1):
for f in */*; do mv "$f" "${f//\.jpg\.jpg/\.jpg}"; done
- Batch rename files:
for i in *.jpg; do mv "$i" string_you_want_to_prepend"${i}"; done
- Replace any spaces in dir/file names with underscores:
Last active
August 18, 2019 17:53
-
-
Save suzmas/7c2ecf7ea41658f644cd3f1bdda6e240 to your computer and use it in GitHub Desktop.
Fun Unix commands
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment