Skip to content

Instantly share code, notes, and snippets.

@AndrewSavetchuk
Last active September 8, 2025 00:09
Show Gist options
  • Select an option

  • Save AndrewSavetchuk/1c7de6794ad5fcf36dc85a7c7b8c6539 to your computer and use it in GitHub Desktop.

Select an option

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.

Copy Files Except .git folder

Copy all files (including hidden ones) from source/ to destination/, excluding the .git directory.

rsync -av --progress source/ destination/ --exclude='.git'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment