[Ubuntu] Command Tips - achishis2/achishis2.github.io GitHub Wiki
Find location of installed library $ sudo dpkg -L packagename
System Info
$ sudo apt-get install sysinfo
$ sysinfo
Total size of current folder
$ du -sh
Size of each conatining folder
$ du -h --max-depth=1 (= du -sh *)
if you want to go deeper...
$ du -h --max-depth=2
If you want to know specific folder
$ du -h --max-depth=1 /<path>
disk free
$ df -h
check Ram clock
$ sudo lshw -C memory | grep clock
$ sudo dmidecode --type memory
$ free -m
grep word in file - Ignore case, print line number, recursively
$ grep -inR "text" /some/path/
find file Ignore case
$find . -name '*.extension'
Seach for a text within file
$ grep -R "text" /some/path/
Save output into file
$ grep -R "text" /some/path/ >> output.txt (make sure not to put an output file in the recursive path)
To avoid grepping the files which grep thinks to be binary, use the -I option:
$ grep -I "text" /some/path/
To ignore case
$ grep -i name file.txt
Find string recursively only some specific files
$ grep string -r . --include=*.myextension
$ grep string -r . --include=*.{myextension,myextension2}
$ grep "name=Oscar" -r . --include=*.js
* if you specify include it won't look in all the files, just the included
Find string recursively all files except some extensions
$ grep string -r . --exclude=*.{myextension2}
$ grep "Serializable" -rl . --exclude=*.{jar,class,svn-base,index}
Find string recursively all files including extensions and excluding others
$ grep string -r . --include=*.myextension --exclude=*.myextension2
$ grep string -r . --include=*.{myextension,myextension2} --exclude=*.{myextension3,myextension2}
$ grep "name=Oscar" -r . --include=*.{js,html} --exclude=*.js
*It won't look in the js files.
Find string recursively only some specific files and show only the filename
$ grep string -rl . --include=*.myextension
$ grep "name=Oscar" -rl . --include=*.js
Find files and find a string in them using find
$ find . -name '*.extension' -exec grep string +
$ find . -name '*.txt' -exec grep Mytext {} +
$ find . -type f \( -name '*.htm' -or -name '*.html' \) -exec grep -i "mystring" {}
Seach word(.doc) file
#!/bin/bash
export GREP_OPTIONS='--color=auto'
echo -e "\n
Welcome to scandocs. This will search .doc (NOT .docx) files in this directory for a given string. \n
Type in the text string you want to find... \n"
read response
find . -name "*.doc" |
while read i; do catdoc "$i" |
grep -iH --label="$i" "$response"; done
Display a list of all the currently installed packages
$ dpkg --get-selections
Display the exact package you need
$ dpkg --get-selections | grep php
Find the locations of the files within a packag
$ dpkg -L php5-gd
Find version of libgtk in your system
$ dpkg -l | grep libgtk