Command Line. Tar, Sed, Awk, Grep, Find,

today i learnt how to
use tar to compress into an archive:
tar -caf nameOfArchive.tar file1 file2 fileN

to extract:
tar -xf nameOfArchive.tar -C folder
i also learnt how to use sed to substitute
sed “s/wordtoSub/subword/” file

also learnt about grep and find.

find is to find a file within the folders:

find . -name “*.jpg”

find and copy files:

find -name “*.jpg” -print0 | xargs -0 cp -t folder/
//the -print0 and -0 is to ignore spaces and special characters.
// -print will make everything on one line.
grep is to find text within a file:

grep “the” filename

grep -i “the” filename

grep -E “[hijk]” filename

grep -E “\w{6,}” filename
// grab words with 8 or more chars.
I also learnt a valuable lesson in Lynda’s lesson for command line – i learnt how to awk into a log file.

Need to refresh memory on awk.
awk ‘{print $2}’ filename

Remember it’s single quotes, double doesn’t work at all – does nothing.

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s