Files
rsmsn_blog/content/posts/useful-commands.md

2.2 KiB

title, date, tags, author, endbleGitInfo, showToc, TocOpen, draft, hidemeta, description, disableHLJS, disableShare, disableHLJS, hideSummary, searchHidden, ShowReadingTime, ShowBreadCrumbs, ShowPostNavLinks, ShowWordCount, ShowRssButtonInSectionTermList, UseHugoToc, cover
title date tags author endbleGitInfo showToc TocOpen draft hidemeta description disableHLJS disableShare disableHLJS hideSummary searchHidden ShowReadingTime ShowBreadCrumbs ShowPostNavLinks ShowWordCount ShowRssButtonInSectionTermList UseHugoToc cover
Useful Commands 2023-09-26T12:04:05-04:00
shell
script
command line
Me true true false true false A collection and living document of useful shell commands that I use. true false false false true true true true true true true
image alt caption relative hidden
useful_commands.png <alt text> <text> false true

This post will act a bit like a living document of all the useful commands and short scripts that I use regularly. Some will be as simple as ls | wc -l which counts the number of files in your current working directory, and others will be better suited to small scripts. As this grows, I will hopefully break these into more logical categories.

Find by File type

This command will find every file in your current working directory by the specified file extension.

find . -type f -name '*.txt'

As a bonus, if you wanted find everything except that file extension, you can add a ! before name. In other words:

find . type -f ! -name '*.txt'

I usually use commands like this to clean up files that I don't need, be it file extensions I don't need anymore, or anything with a specific word in its file name, so adding -delete at the end of the command lets me delete those files.

find . type -f -name '*.txt' -delete

List Files & Dir +

Using ls is a key command for anyone that works within a command line. If you've used ls before, then you've also likely used or created an alias for ls -la which will display the files, their user:group ownership, permissions (drwxrwxrwx) and dates created + modified.

What if you just want to found the number of files? Not measuring disk usage or free space, but the equivalent of len for an array, the array being your current working directory. Enter wc!

ls | wc- l