Skip to content

Instantly share code, notes, and snippets.

@AndrewSavetchuk
Last active March 17, 2024 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewSavetchuk/1c7de6794ad5fcf36dc85a7c7b8c6539 to your computer and use it in GitHub Desktop.
Save AndrewSavetchuk/1c7de6794ad5fcf36dc85a7c7b8c6539 to your computer and use it in GitHub Desktop.

Sort the Contents of a File

This command sorts the lines in the input.txt file:

sort ./input.txt

This command sorts the lines in the input.txt file and removes duplicates:

sort ./input.txt | uniq

This command sorts the lines in the input.txt file, removes duplicates and writes the output in the file:

sort ./input.txt | uniq > output.txt

Find Files

Find files in the current directory and its subdirectories with a name containing the specified string.

find . -name "*string*" -print

Find files in the current directory (not-recursive) with a name containing the specified string.

find . -maxdepth 1 -name "*string*" -print

Find files in the current directory (not-recursive) with a name containing the specified string, but avoid files with a name containing "readme".

find . -maxdepth 1 -name "*string*" ! -name "*readme*" -print

Count Files

Count files in the current directory.

find . -type f | wc -l

To include directories (and symbolic links) in the count, remove the -type f.

It's possible this command will overcount if filenames can contain newline characters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment