Skip to main content

Posts

Showing posts with the label find

awk: Find and Replace text

Syntax awk options > ' Program ' Input-File1 Input-File2 ... awk -f PROGRAM-FILE options > Input-File1 Input-File2 ... If no Input-File is specified then `awk' applies the Program to "standard input", (piped output of some other command or the terminal. Typed input will continue until end-of-file (typing `Control-d') Basic functions The basic function of awk is to search files for lines (or other units of text) that contain a pattern. When a line matches, awk performs a specific action on that line. The Program statement that tells `awk' what to do; consists of a series of "rules". Each rule specifies one pattern to search for, and one action to perform when that pattern is found. For ease of reading, each line in an `awk' program is normally a separate Program statement , like this: pattern { action } pattern { action } ... e.g. Display lines from my_file containing the string "123" or "ab...

Common UNIX Find Commands

One of the most useful utilities in the UNIX systems resources directory is the find command. System administrators use this powerful utility frequently. Here are a few common tasks performed by the ubiquitous find command. I'll add more as time goes on. # cd /export/home/esofthub Find a file or directory # find . -name TEMP -print or # find . -name TEMP -exec echo {} \; Find core files in this directory tree and remove them # find . -name "core" -exec rm -f {} \; Find junk directories and remove their contents recursively # find . -name "junk" -exec rm -rf {} \; Find files not starting with "junk" OR not ending with "log" # find . ! \( -name "junk*" -o -name "*log" \) -print Find a pattern in a file using the recursive grep (ignore case) # find . -type f | xargs grep -i  MYPATTERN # find . -name '*.sh' -exec grep -i  MYPATTERN  {} \; Find files modified in the past 7 days # find . -mtime -7 -type f Find files owne...

Howto find Disk usage of Packages in ubuntu

The following command help you to find the disk space used by different packages in ubuntu open a terminal window and run the command dpkg-query --show --showformat='${Package;-50}\t${Installed-Size}\n' | sort -k 2 -n | grep -v deinstall | awk '{printf "%.3f MB \t %s\n", $2/(1024), $1}' That will sort the packages by size, putting the largest ones on the bottom. you can pipe(|} the output for last 10 by using | tail -n 10 at the end of the command