www.muppix.co explore directories [begin end last days minutes size greater] back to topwww.muppix.co explore filenames [begin end filename hidden myextension last days minutes size greater 2K 2M] back to topdf -h ## names & sizes of all connected hard-drives on this version of linux. TIP: goto using these harddrive names df . ## current hard-drive (mydrive) name, size & available find . -type d ## select all subdirectory (mydir) names find . -type d -ls | fgrep -i 'mydir' ## select all directories & subdirectories with 'mydir' somewhere (in between ) in its name , include the times last saved and access, ignore case find . -type d -name "mydir*" -ls ## select all directories & subdirectories beginning with 'mydir' , include the saved times and access find . -type d -name "*mydir" -ls ## select directories & subdirectories ending in 'mydir' ,include the saved times and access find -type d -name ".*" ## select all hidden subdirectory names du . | sort -n ## sort by size each directory (mydir) and subdirectory ie: you've run out of space & need to delete stuff (try doing that in Windows..) du . | awk '{if(($1+0) > 2)print $0}' ## directory (mydir) and subdirectory sizes greater than 2 du . | awk '{if(($1+0) < 2)print $0}' ## directory (mydir) and subdirectory sizes less than 2 find . -type d -mtime -2 ## select directory and subdirectory with files saved in last 2 days (2 months = 62 days, 2 years = 730 days) find . -type d -mtime -2 -ls ## select directory and subdirectory (mydir) with files saved in last 2 days, include size, saved dates find . -type d -mmin -2 -ls ## select directory and subdirectory with files saved in last 2 (second) minutes
select lines with 'mytext' in files [filename begin end ignore case number aswell mysecondtext] back to topfind . -iname "*" -ls ## select all filenames (include size/date information) in subdirectories. TIP: to just show the filesnames, also add this at end: | cut -d'.' -f2- find . -type f -print ## selects all files names from all subdirectories find . -exec ls -al {} \; ## select files and subdirectories , include so-called hidden files find . -type f -printf '%s %t %p\n' | sort -rk 1 -n ## select files in subdirectories, sizes and saveddates, sorted by size find . -type f -exec ls -s {} \; | sort -n ## select files in subdirectories, sorted by size find . -name \*.pdf -print ## filenames, myextension is pdf, in all subdirectories, include just the filesnames & subdirectory name/path find . -name "*.myextension" -ls ## filenames with myextension in all subdirectories, include size, date, path find . -iname "*myfile*" -ls ## select filenames with 'myfile' in between/somewhere in the filename (include size/date & subdirectory/path information) in all sub directories. ignore case find . -iname 'myfile*' -ls ## select only filenames beginning with 'myfile' (ignore case) find . -iname '*myfile' -ls ## select only filenames ending in 'myfile' (ignore case) find . -type f -printf '%T@ %s %t %p\n' | sort -rk 1 -n | awk '{$1="";print $0}' ## select all files in subdirectories, sizes and saved dates. sorted by date ls -lgo --sort=extension ## sorting files by extension/version, only this directory find . -exec ls -al {} \;|rev|sed 's/\./#/1'|rev|sort -t"#" -k2|tr '#' '.' ## Sorting files by extension , sundirectories find . -type f -print | egrep '(.jpg|.gif|.png)' ## select jpg or gif or png (myextention) files in any subdirectory find . -type f -print | fgrep -i myfile ## select files with the name 'myfile' somewhere/between in it (ignore case) in all directories . show full path find . -size +2 -print ## files greater 2K in size find . -size -2 -ls ## files less 2K in size find . -size +2k -size -2M -print ## select files in all subdirectories between 2,000 & 2Megs find . -size +2k -size -2M -ls ## select files in all subdirectories , size between 2K & 2Mb. Each k is 1024 bytes, include sizes, saved date, path find . -mtime -2 -name "*" -ls ## files in subdirectories saved in last 2 days find . -mtime +2 -print ## files saved in last 2 days or older find . -mtime 0 -ls ## select files and directories saved between now and 1 days ago (last 24 hours) find . -mmin +2 -mmin -10 ## files in subdirectories saved between last 2 minutes and 10 minutes ago find . -newer myfile.txt -ls ## select files saved after the time that myfile.txt was saved find . -mtime +2 -size +8 -print ## files saved in last 2 days or more aswell as greater 8K in size) find . -mtime +2 -size +8 -ls ## files saved last 2 days or more aswell as greater 8K in size) include date, size
select line with 'mytext' [begin end before after aswell or mysecondtext mythirdtext word ignore case] back to topTIP: goto the top level of the data using 'cd', use the command below and save it to a temporary file in a directory where you can save it. ie: fgrep -rai 'mytext' * >/cygdrive/c/muppix/myfile.txt ####! ## fgrep -rai 'mytext' * ## select lines with 'mytext' in all files in all subdirectories (entire hard drive / network), ignore case, include filename TIP: cant use wildcard, like *.txt !! egrep -rai 'mytext|mysecondtext|mythirdtext' * ## select lines with 'mytext' or 'mysecondtext' or 'mythirdtext', ignore case, in all directories fgrep -raic mytext m | fgrep -v ':0' ## how many times is 'mytext is found in files in all subsirectories, ignore case find . -type f -print0 | xargs -0 grep -ai "mytext" ## select 'mytext' (ignore case) from all subdirectories & select the directories, filenames & the lines if 'mytext' appears (most comprehensive but can take a while to process ) find . -name '*myfile[ABC]*' -print | xargs grep -aHE 'mytext' ## select files with 'myfileA,myfileB or myfileC somewhere in the filename in subdirectories, and only those lines with 'mytext' ie: using the Regex '^Mytext' find . -name '*myfile' -print0 | xargs -0 grep -aHE 'mytext' ## select only filenames ending in 'myfilename' (myextension) and select 'mytext' find . -name "*.myextension" -exec cat {} \; ## select all lines in all the files with myextension. ie: glue together all '*.txt' files into one single file find . -name "*.myextension" -exec grep -H '' {} \; ## select lines with myextension in all subdirs & include filename. ie: glue together all '*.txt' files into one single file find . -name '*myfile*' -print0 | xargs -0 grep -aHE '^mytext' ## select 'mytext' at beginning of the line, but only in files with 'myfile' between/in its filename. find . -name "*.myextension" | xargs fgrep -a 'mytext' ## select 'mytext' in files with myextension find . -name 'myfile*mytext' -print0 | xargs -0 grep -a [alnum] ## all lines of filenames beginning with 'myfile' aswell as 'mytext' in the filename in all subdirs find . -name "*.txt" -exec awk '{if ($1 ~/[A-Z][A-Z]/) print $0}' {} \; ## in any subdirectory for files with 'txt' extension, select lines if there are atleast 2 consecutive uppercase characters somewhere on the line find . -name "*.txt" -exec egrep -H "\b[0-9]{2,}\b" {} \; ## select lines in any subdirectory if there is an integer of atleast 2 consecutive number /digits ie: 09 or 10 or 9999 (but not 2.5) find . -type f -print0 | xargs -0 egrep '(mytext|mysecondtext|mythirdtext)' ## select lines in subdirectories with 'mytext' or 'mysecondtext' or 'mythirdtext' find . -type f -print0 | xargs -0 grep -o "mytext.*mysecondtext" ## select lines with 'mytext' aswell as 'mysecondtext' find . -print | xargs grep -iaC2 'mytext' ## select 'mytext' from all files/subdirectories, and also select 2 (second) lines above and below 'mytext' (ignore case) find . -print | xargs grep -aB2 'mytext' ## select 'mytext' in all files & subdirectories , and also select 2 (second) lines above 'mytext' Address Pattern find . -print | xargs grep -aA2 'mytext' ## select 'mytext' in all files & subdirectories , and also select 2 (second) lines below 'mytext' Address Pattern find . -print | xargs grep -aC2 'mytext' ## select 'mytext' in all files/ subdirectories , and also select 2 (second) lines above and below 'mytext' Address Pattern fgrep -H 'mytext' */*/* ## select lines with 'mytext' in all files but only the third level subdirectories below this one, include filenames find . -mtime -2 -size -2k -name 'myfile*' -print | xargs grep -ias 'mytext' ## select 'mytext (ignore case) in files saved in last 2 days, size less than 2K (not greater than 2K) , but only for filenames beginning with 'myfile' find . -mtime +2 -size +2k -name '*myfile' -print | xargs grep -ias 'mytext' ## select 'mytext (ignore case) in files saved in last 2 days or more, size greater than 2K, but only for filenames ending with 'myfile' find . -mtime -2 -print | xargs grep -ias 'mytext' ## lines containing 'mytext' in files saved in last 2 days find . -mmin -2 -print | xargs grep -ias 'mytext' ## lines containing 'mytext' in files saved in last 2 minutes find . -mmin -2 -size -10k -print | xargs grep -ias 'mytext' ## files saved todays date, in last 2 minutes , size less than 10K (not greater than 10K) fgrep -rif /cygdrive/c/muppix/mylist.txt * ## select lines from a list of text/words in the file mylist.txt, (mytext or mysecondtext or ThirdText etc) all subdirectories from here on, ignore case TIP:on a Windows PC, ensure you run dos2unix dos2unix on mylist.txt! find . -exec grep -if /cygdrive/c/muppix.mylist.txt {} \; ## select lines from a list of text/words in the file c:/mytext/mylist.txt, (mytext or mysecondtext or ThirdText etc) all subdirectories from here on, ignore case TIP:on a Windows PC, ensure you run dos2unix dos2unix on mylist.txt! find . -name "*.txt" -exec grep -iHf /cygdrive/c/muppix.mylist.txt {} \; ## select lines from a list of text/words in the file c:/muppix.mylist.txt, (mytext or mysecondtext or ThirdText etc) all subdirectories from here on, only for files with "txt" as myextension, ignore case , show filenames. TIP:on a Windows PC, ensure you run dos2unix dos2unix on mylist.txt!
select a section of lines [lines above below mytext after blankline between mysecondtext] back to topTIP: now you have your temporary file such as 'myfile.txt', type 'cat myfile.txt | ' followed by a command shown below. ie: cat myfile.txt | fgrep -i 'mytext' | wc ####! ## fgrep -i 'mytext' ## select line with 'mytext' ignore case. ie: could match MytEXT mytext or MYTEXT etc fgrep 'mytext' ## select if 'mytext' anywhere on the line fgrep 'mytext' | fgrep 'mysecondtext' ## select line with both 'mytext' aswell as 'mysecondtext' in any order on the line fgrep -i 'mytext' | fgrep -i 'mysecondtext' ## select line with 'mytext' aswell as 'mysecondtext' on the line (ignore case) fgrep -i 'mytext'| fgrep -i 'mysecondtext' |fgrep -i 'mythirdtext' ## select line with 'mytext' aswell as 'mysecondtext' aswell as 'mythirdtext' in any order (ignore case) fgrep -e 'mytext' -e 'mysecondtext' ## select either 'mytext' or 'mysecondtext' egrep -i 'mytext|mysecondtext|mythirdtext' ## select line with 'mytext' or 'mysecondtext' or 'mythirdtext', ignore case fgrep -if mylist.txt ## select any of the texts in the file mylist.txt 'mytext' or 'mysecondtext' or 'mythirdtext' etc TIP: in Windows ensure you run dos2unix on mylist.txt, so Linux can read it fgrep '^mytext' ## select line that begin with 'mytext' TIP:may first want to ensure there are no leading spaces fgrep '^mytext[ABCD]' ## select line that begin with (range) 'mytextA' or 'mytextB' or 'mytextC' or 'mytextD' fgrep 'mytext$' ## select line ending with 'mytext' egrep '/[,'\.\?]' ## select the punctuation character '.' and '?' These are special characters. To use the character as literal character, it has be preceded by backslash. egrep '^[ABCD]' ## select line that begin with character 'A','B','C' or 'D' (range) egrep '^[^ABCD]' ## delete line that begin with character 'A','B','C' or 'D' (range) grep '([A-Za-z][A-Za-z])' ## select line with 2 character US state names, surrounded by round braces. mychar '(' , range A-Za-z , range A-Za-z, mychar ')' fgrep -iw 'myword' ## select line with the word 'myword', ignore case. so will select 'MYWord' or 'myWORD', but wont select 'mywords' or 'allmyword' awk '$0 ~/mytext.*mysecondtext/' ## select line where 'mytext' is before 'mysecondtext', 'mysecondtext' after 'mytext' awk '$0 ~/mytext.*mytext/' ## select line where 'mytext' appears twice or more often - second occurrence egrep 'mytext(.*?)mysecondtext' ## select line if the text 'mytext' is then followed/before/after somewhere on the same line with 'mysecondtext' ie: egrep '@(.*?)\.' ie: email address must have '@' aswell as '.' later on the line awk '$0 ~/mytext.*mysecondtext.*mythirdtext/' ## line with 'mytext' before 'mysecondtext' aswell as followed after by 'mythirdtext'. ie: line with many occurrence of mychars/delimiters such as '|' egrep '/[,'\.\?]' ## select the punctuation character '.' and '?' These are special characters. To use the character as literal character, it has be preceded by backslash. egrep '\bmytext\w*\b' ## select line with word/column beginning with 'mytext' ie: 'mytextualisation ' egrep '\b\w*mytext\b' ## select line with word/column ending in 'mytext'. ie: find words/columns ending in 'ion' 'ing' awk '{if ($2 ~/^[A-Z]{2,}/) print $0}' ## select line if second column begins with 2 consecutive uppercase characters (range) after / before grep '^\b[[:upper:]]\{2\}' ## select line that begin with a word of atleast 2 uppercase characters (range) awk '{if ($0 ~/[A-Z][A-Z][0-9][0-9]/) print $0}' ## select line with 2 consecutive uppercase characters and 2 numbers anywhere on the line (range) egrep 'mytext\>' ## select line with words that end with 'mytext' ie: egrep 'ing\>' will find 'beginning' '(starting)' '--+[going]' egrep '\b(\w+)\s+\1\b' ## select line with words that are duplicated, any word immediately followed/after by same second word egrep 'mytext(.*?)\mytext' ## select line if 'mytext' appears atleast twice duplicated - also for a second time on each line sed -n '/\([a-zA-Z][a-zA-Z]*\) \1/p' ## select line if any text is duplicated, any text after/before the same second text egrep '[A-F][g-k][0-9][0-9]' ## select words/text anywhere on line beginning with a range of characters A or B,C,D,E,F followed/after by a second character of g or h,i,j,k aswell as followed by a number and a second number fgrep -w 'myword' ## select line with the exact word 'myword' on the line, so wont select line with 'mywords' or 'allmyword' for example
delete lines [begin end above below duplicate blanklines] back to topawk 'IGNORECASE=1;{print $0;if (match($0,"mytext"))exit}' ## select begin lines above and including 1st occurrence of 'mytext',(ignore case) delete lines below awk '{print $0; if (match($0,"mytext")) exit}' ## select begin lines above and including 'mytext', delete lines below awk '{if(match($0,"mytext"))exit;print $0}' ## select begin lines above 'mytext' (but not including mytext) delete 'mytext' and all lines below/end awk '{print $0; if (match($0,"^mytext")) exit}' ## select begin lines above and including 'mytext', if 'mytext' is at beginning of line. delete lines below awk '{print $0; if (length($0)==0) exit}' ## select the beginning lines (above) upto the beginning blankline, delete lines below beginning blankline TIP:may need to use command to delete/trim all ending/trailing spaces of each line sed '/mytext/,/<\/p>/d' ## select beginning lines above 'mytext', delete lines below 'mytext' sed -n '/mytext/,$p' ## select lines below 'mytext' to end of file, including 'mytext'. delete beginning lines above 'mytext' sed '/^mytext/,/<\/p>/d' ## if 'mytext' at the beginning of the line, delete this line & lines below. select beginning lines above 'mytext' sed -n '1!G;h;$p' | awk '{print $0;if (length($0)==0) exit}' | sed -n '1!G;h;$p' ## select lines below the final ending blankline , delete lines up to the final ending blankline awk '/^$/ {p=1;next}; p==1 {print $0}' ## delete lines up to the beginning blankline, select lines below beginning blankline TIP:may need to use command to delete ending spaces of each line awk '/^$/ {p++;next}; p>1 {print $0}' ## select lines below the second blankline. (delete lines above the second blankline) awk '/mytext/{p++;next}; p>1 {print $0}' ## select lines below the second 'mytext'. (delete lines above the second 'mytext') awk '{print $0; if (match($2,"mytext")) exit}' ## select begin lines above and including 'mytext', if 'mytext' is in second column. delete lines below awk 'match($0,"mytext"),match($0,"mysecondtext")' ## select section of lines between / below 'mytext' and 'mysecondtext' awk '$2=="mytext",$2=="mysecondtext" ' ## select section of lines between the beginning line with 'mytext' in second column to 'mysecondtext' in second column awk 'NR>=2&&NR<=20' ## select section lines between second (fixed) line to line 20 (fixed) ie: cat -n |awk 'NR>=2&&NR<=20' awk '{if ((p==0)&&match($0,"mytext")){p=3} else {if(p<=2) {print $0} else {if ((p==3)&&match($0,"mysecondtext")) p=1}}}' ## delete section lines between begin 'mytext' and 'mysecondtext' tr '\n' '£' | sed 's/mytext.*mysecondtext//g' | tr '£' '\n' ## delete section lines between begin 'mytext' and end occurrence of 'mysecondtext'
delete 'mytext' in the line [begin end before after between number second mychar mydelimiter word occurrence] back to toptouch myfile.txt >myfile.txt ## empty-out entire contents/delete all lines in myfile.txt sed '1 d' ## delete just the beginning (fixed) line, select below beginning line sed '$d' ## delete just the end (fixed) line, select lines above fgrep -iv 'mytext' ## delete line if 'mytext' is somewhere on the line (ignore case) TIP: first dble check which line will be deleted by running: fgrep -i 'mytext' fgrep -v 'mytext' ## delete line if 'mytext' is somewhere on the line TIP: dont ignore case & also first check which lines will be deleted by running: fgrep 'mytext' grep -v '^mytext' ## delete lines that begin with 'mytext' grep -v 'mytext$' ## delete lines that end with 'mytext' egrep -v 'mytext|mysecondtext' ## delete lines with 'mytext' or 'mysecondtext' egrep -iv 'mytext|mysecondtext' ## delete line with 'mytext' or 'mysecondtext' anywhere on the line (ignore case) fgrep -vif mylist.txt ## delete lines if any of the texts in the file mylist.txt are found, 'mytext' etc TIP: in Windows ensure you run dos2unix on mylist.txt awk 'BEGIN{}{print l;l=$0}END{if($0 !~/mytext/){print$0}}'|sed '1 d' ## if 'mytext' somewhere in the end line, delete the line awk '{if((NR=1)&&($0 ~/mytext/)){}else{print $2}}' ## if 'mytext' somewhere in the begin line, delete the line awk '{if($0~/mytext/&&/mysecondtext/){""}else{print $0}}' ## delete line with 'mytext' aswell 'mysecondtext' anywhere on the line egrep -v 'mytext(.*?)mysecondtext' ## delete lines with 'mytext' before 'mysecondtext' ('mysecondtext' after 'mytext' awk NF ## truly delete blanklines which may have some spaces or tabs or no spaces at all sort -u ## sort & delete duplicate lines (dont maintain the original order & is a lot faster) sort | uniq -d ## select only the duplicate lines, ie: those lines that occur twice or more awk '!x[$0]++' ## delete duplicate lines, but maintain the original order ( without sorting) select begin occurrence of each line sed '/mytext/,/mysecondtext/d' ## delete lines that begin with 'mytext' aswell as end 'mysecondtext' ie: xml tags: sed '/
/,/<\/myxml>/d' awk '!($2 in a){a[$2 ];print $0}' ## delete duplicate lines, based on duplicates in second column only, select begin occurrence of 2nd column,preserve order of lines sed '/mytext/,/<\/p>/d' ## delete lines below 'mytext' , select beginning lines above 'mytext' sed '/^mytext/,/<\/p>/d' ## delete lines below 'mytext' is in the beginning of the line, select beginning lines above 'mytext' sed '/./,/^$/!d' ## delete multiple/duplicate/consecutive blanklines except the beginning line; also deletes blanklines from beginning and end sed '/^$/N;/\n$/N;//D' ## delete multiple/duplicate/consecutive blanklines except the beginning and second sed '1,2d' ## delete the (fixed) beginning and second lines, select lines below second line, to the end line sed '2,8d' ## delete between second line to eigth line : (fixed) lines 2 3 4 5 6 7 8 head -n -2 ## delete second (fixed) lines from end sort -n | uniq -c ## how many/occurrence of duplicate lines - pivot tablesed 's/mytext//g' ## delete 'mytext' on the line if found awk '{$2="";print $0}' ## delete second column / word (delimiter is spaces by default) awk '{$1=$2=$3=$NF=""; print $0}' ## delete begin , second , third, end column sed 's/mytext//2' ## delete only the second occurrence of 'mytext' on each line sed 's/mytext.*//g' ## select everything before 'mytext' on the line, (delete 'mytext' & everything after) sed 's/.*mytext//g' ## delete everything before 'mytext' on the line, (select text after 'mytext') awk '{$NF="";print $0}' ## delete end word / end column awk -v v="," 'BEGIN{FS=OFS=v}{$NF="";print $0}' ## delete end word / end column with comma ',' as mydelimiter cut -c 3- ## delete beginning and second characters (fixed)(delete before 3rd & select after second characters) sed 's/.$//' ## delete end character (fixed) on each line sed 's/..$//' ## delete the end 2 (fixed) characters on each line. (end & second from end character) sed 's/,$//' ## delete end character if its a comma ( is mychar) awk '{$1="";print $0}' ## delete beginning word / column sed -e 's/^[ \t]*//' ## left align /justify, delete beginning/leading spaces and or tabs on each line sed 's/,$//' ## delete end character if its a comma ( is mychar) awk '{$1="";print $0}' ## delete beginning word / column sed 's/[ \t]*$//' ## delete spaces or tabs at end of each line. right align. also deletes extra spaces on blanklines sed 's/^[ \t]*//;s/[ \t]*$//' ## delete leading/beginning space aswell as ending/trailing spaces on the line(left align, trim ) sed -n -e 's/.*mytext\(.*\)mysecondtext.*/\1/p' ## select between 'mytext' to end occurrence of 'mysecondtext' on each line. will find 'anymytext to the somemysecondtext' sed -n -e 's/.*\bmytext\b\(.*\)\bmysecondtext\b.*/\1/p' ## select text between the exact words 'mytext' and 'mysecondtext' on the same line, delete before 'mytext' and after 'mysecondtext' grep -o "mytext.*mysecondtext" ## select text between 'mytext' and 'mysecondtext' on the line. delete before 'mytext' aswell as after 'mysecondtext', include mytext & mysecondtext sed 's/mytext.*mysecondtext//g' ## delete the text between 'mytext' and 'mysecondtext' sed 's/mytext/#+#/2'|sed 's/#+#.*//g' ## delete everything after second occurrence of 'mytext', select everything before 2nd occurrence of 'mytext' sed 's/mytext/#+#/2'|sed 's/.*#+#//g' ## delete everything before second occurrence of 'mytext', select everything after 2nd occurrence of 'mytext' sed 's/[^` ]*mytext*[^ ]*//g' ## delete words/columns anywhere on the line, with 'mytext' somewhere inside/between the word ie: will delete words such as 'allmytext' or 'mytexting' or 'mytext' awk -v OFS=" " '$1=$1' ## delete/replace multiple/duplicate/consecutive spaces with single space/blank tr -d 'a' ## delete 'a' characters ('a' is mychar/mytext) tr -d 'abc' ## delete all occurrence of any of these 3 single (mychar) character 'a','b' or 'c' (ie: also delete 'abc', dan' etc) delete multiple/duplicate characters tr -d '"' ## delete double quote character (mychar/mytext) tr -d "'" ## delete single quote character (mychar/mytext) sed 's/^.*mytext//' ## delete everything on the line before the end occurrence of 'mytext' including 'mytext' . select everythings after end occurrence of 'mytext' on line rev | cut -d '/' -f2- | rev ## delete everything on the line after the end occurrence of '/' (mychar) , select everything before end mydelimiter ('/') ie: select path of the full filename /tmp/mydir/mysubdir/myfile.txt rev|sed 's/mychar/@/g' |cut -@ '/' -f2- |rev ## delete everything on the line after the end occurrence of 'mychar' , select everything before end 'mychar' tr -dc '\11\12\40-\176' ## delete non-printable punctuation characters sed 's/[^a-z0-9A-Z]/ /g' ## replace punctuation with space (delete all punctuation) tr '[:punct:]' ' ' ## replace punctuation with space (delete all punctuation) tr -dc '[:digit:]' ## delete all text/characters, select numbers tr '[:digit:]' ' ' ## delete all numbers, select all characters TIP: see section on [:digit:] for other groups of characters