Some nice to know linux commands

February 23, 2015

Spending a lot of time in a cli means you will be searching how to get stuff done. Here are some nice commands to monitor folders and files. Find files that contain a string

$ find . -type f -exec grep -l “string to find” {} \;

This starts the search from the current directory, looks for files that contain the specified string, and then it prints their names. Count files in a folder

$ ls | wc -l

You can do this per type.

$ ls -l | grep ^- | wc -l
$ ls -l | grep ^d | wc -l
$ ls -l | grep ^l | wc -l

This can also be done recusively.

$ find . -type f | wc -l

Run a script every x seconds

$ watch -n 5 "ls | wc -l"

This will show the number of files in the current dir and update the output every 5 seconds. Sort a list of files

$ ls |sort -h

This will sort the results in a human-numeric-sort, meaning 99 is before 100.

comments powered by Disqus