Make Your File Chores Faster, Easier, and Safer with Terminal Tools + The Chat
Konrad Krawczyk
Human-Computer Interaction | MSc Industrial Design TU Delft | NYU Shanghai
If you do your job on your computer, you almost certainly do "file chores".?
Think of sending, converting, sharing, uploading, waiting for an upload to complete, resizing, compressing, timestamping, etc. File chores are digital tasks that aren't very generative, aren't directly related to your profession, but eat up a sizable portion of your workday.?
Whether you work with just text, audio, video, 3d modeling, or all of these, mishandling file formats, locations, and sizes can be a productivity nightmare. At worst, we end up like Dan Egan from Veep, who sent the wrong State of the Union draft to the president's teleprompter because the drafts were spread out over 5 computers, and he couldn't bring his USB stick on time.
Or let's say you have a visa photo in a .heic format. The gov website says it has to be a .jpEg, under 200KB. You have 10 minutes, otherwise, the application closes for security reasons.
You google: "heic to jpeg online converter" and click on the first result.?
At that moment, do you really want to submit your named face picture to https://FunkyShrekConvert3r.su? Probably not. But you do it anyway. Your data is compromised already, and then the website asks you to register for "exciting" premium features, such as downloading the photo in question.
You don't have to do this again.
Terminal + Chat = top match
Of all the things made easier by The Chat, digital chores like file conversions/resizing/compression have to be the No. 1. There's a command line tool for nearly everything. Ask GPT for guidance, and you will never have to use a crappy ad-infested online converter again.?
??*Command Line Warning*???
The command line, or terminal on Mac, is a powerful tool. It probably won't let you wreak havoc on your OS (watch out for sudo), but it will let you delete your documents without a warning. Learn the basic commands. When in doubt, make a copy of the file you're working on, and store it in a different location.
Watch out for:?
You'd be best off looking at a quick cmd crash course, like this one. Once you learn it, it will be worth it. It will make your work faster and safer.
One more thing: if you're using a Mac, the one thing you'll need to install extra packages is homebrew. Download the .pkg file from here: https://github.com/Homebrew/brew/releases/tag/4.1.22
On Windows, you can use Winget instead. This tutorial is slightly Mac-biased, but rest assured you can use the same or similar packages on Windows.
The Workflow (tl;dr: just ask)
Let's see what we can do.
You have this .heic file, right? Let's ask ChatGPT:
How can I convert my file called input.heic to a PNG smaller than 200 KB using command line on (PC/Mac)?
And here it goes with an answer. Not really rocket science, but wait to see just what you can do with this approach.
Sometimes the initial command will require you to install an additional package or two. That usually doesn't take long. More often than not, the right commands are already on your computer. Now let's get to some specific tasks you can accomplish with this workflow.
What you can do this way:
Bulk File Sorting (mv, cp, mkdir etc)
File?sorting?is?a?breeze?with?command?line?tools?like?mv?(move),?cp?(copy), and?mkdir?(make?directory). Here's?how?you?can?use?them:
- To?move?a?file:?mv?source?destination
- To?copy?a?file:?cp?source?destination
- To?create?a?new?directory:?mkdir?directoryname
Boring. But it gets useful when you learn the wildcard character (the * asterisk). Let's say you want to move all your pngs into a ~/pngs folder. (Looking at you, screenshot hoarders.)
You go:?
cd ~/Desktop
mkdir pngs
mv *.png pngs
Done.
Bulk File Renaming
Here, the approach will look slightly different. Let's say you have a folder full of weird names of pictures from Google. You can number them like this:
ls?|?cat?-n?|?while?read?n?f;?do?mv?"$f"?"$n-$f";?done
This?command?does?the?following:
-?ls?lists?all?files?in?the?current?directory.
-?cat?-n?numbers?each?line.
-?while?read?n?f;?do?mv?"$f"?"$n-$f";?done?reads?the?number?and?filename, then?renames?the?file?with?the?number?as?a?prefix.
Note?that?this?command?will?rename?all?files?and?directories?in?the?current?directory. If?you?want?to?rename?only?files, you?can?modify?the?command?like?this:
find?.?-maxdepth?1?-type?f?|?cat?-n?|?while?read?n?f;?do?mv?"$f"?"./$n-$(basename?$f)";?done
This?command?uses?find?.?-maxdepth?1?-type?f?to?list?only?files?in?the?current?directory.
Video Editing (converting, cropping, speeding up, compression). (ffmpeg)
ffmpeg?is?a?powerful?tool?for?video?editing?tasks?like?converting, cropping, speeding?up, and?compression. Install it like:
brew install ffmpeg
To?convert?a?video from mp4 to avi:?
ffmpeg?-i?input.mp4?output.avi
To?crop?a?video. (Saved me hours of uploading and re-rendering):
ffmpeg?-i?input.mp4?-filter:v?"crop=out_w:out_h:x:y"?output.mp4
For example, if you want to crop a 100x100 area starting at coordinates (12, 34), you would use crop=100:100:12:34.
领英推荐
To?speed?up?a?video:?
ffmpeg?-i?input.mp4?-filter:v?"setpts=0.5*PTS"?output.mp4
To?compress?a?video:?
ffmpeg?-i?input.mp4?-vcodec?libx265?-crf?28 output.mp4
Image Editing (format conversions, compression, resizing) (ImageMagick)
ImageMagick?is?a?software?suite?to?create, edit, and?compose?bitmap?images. It?can?read, convert?and?write?images?in?a?variety?of?formats. This one doesn't come built-in, you can download it likewise:
brew install imagemagick
To?convert?an?image from jpg to png:?
convert?image.jpg?image.png
To?resize?an?image:?
convert?-resize?50%?image.jpg?image_small.jpg
To?compress?an?image:?
convert?-quality?85%?image.jpg?image_compressed.jpg
Audio Editing (sox)
sox?is?a?command?line?utility?that?can?convert?various?formats?of?computer?audio?files?into?other?formats. Install it like:
brew install sox
To?convert?an?audio?file from wav to mp3:?
sox?input.wav?output.mp3
To?change?the?global volume:?
sox?input.wav?output.wav?vol?0.5
Document conversions (Pandoc)
Pandoc?is?a?universal?document?converter. It?can?convert?files?from?one?markup?format?into?another.
brew install pandoc
To?convert?a?markdown?file?to?a?word?document:?
pandoc?-s?input.md?-o?output.docx
PDF editing (resizing, splitting) (GhostScript)
GhostScript?is?a?high-performance?PDF?interpreter?for?editing?PDF?files.
brew install ghostscript
To?resize?a?PDF:?
gs?-sDEVICE=pdfwrite?-dCompatibilityLevel=1.4?-dPDFSETTINGS=/ebook?-dNOPAUSE?-dQUIET?-dBATCH?-sOutputFile=output.pdf?input.pdf
To?concatenate?PDFs:?
gs?-dBATCH?-dNOPAUSE?-q?-sDEVICE=pdfwrite?-sOutputFile=output.pdf?input1.pdf?input2.pdf
Compressions (zip, tar, unar, bzip2)
Zipping / unzipping is very straightforward. In general compression tools are the simplest to use in a command line interface. It is still useful as occasionally it's impossible to extract an archive in certain formats through the GUI. If you have a Mac, you will need to do the following to unpack a .rar:
brew install unar #if not installed yet
unar archive.rar
YouTube downloading (youtube-dl)
That was my biggest surprise. youtube-dl?is?a?command-line?program?to?download?videos?from?YouTube.com?and?other?video?sites.
brew install youtube-dl
To?download?a?video:?
youtube-dl?video_url
***
This list is not exhaustive at all. In fact, I don't even know 99% of the things the aforementioned tools can do. But it's stunning to see the kinds of knowledge that GPT unlocks for a very broad audience. What I sketched out here is a workflow with some pointers to help you make the best use of it, so that your files are safe - and your client gets the right .pdf.
Senior Embedded and Software Engineer / Technical Leader
1 年Cool list :) convert and ffmpeg being my favorites here as they are so powerful yet often overlooked