Showing posts with label cheatsheet. Show all posts
Showing posts with label cheatsheet. Show all posts

Monday, October 26, 2009

Howto Unzip .gz, tar.gz, .zip Files in Linux, Quick Examples

$ gzip myfile.txt
____zip (creates myfile.gz, deletes myfile.txt)
$ gzip -r mydir
___ zip several files--doesn't package! (creates .gz versions of each file in mydir. Not gzip and gunzip don't group several files together into one file, for that you need tar)
$ gunzip myfile.gz
___ unzip (creates myfile.txt, deletes myfile.gz)

$ tar -xzfv foo.tar.gz
___ unzip and extract (note: tar by itself just groups / archives files, it doesn't compress. Using the z option causes it to use gzip/gunzip to also compress / uncompress files.)
___ x/c: extract, use c to create an archive
___ z: use gzip/gunzip to also compress (you end up with .gz files)
___ f: operate on a file and not typed input
___ v: print out files it's operating on verbosely
$ tar -cf foo.tar mydir.tar mydir/
___ archive folder (add option z to also compress)

$ zip -r test.zip mydir
____zip (replace mydir with * to zip up everything in the cur dir)
$ unzip test.zip
____unzip

Text Editing / Viewing Files in Linux (quick examples)

$ nano myfilename
____basic navigation commands are displayed (page up + down), no need to remember!
$ cat myfilename
____prints contents out, no editor
$ less myfilename
____view file text, no editing
____G : end of file,
____ctrl-v : page down, (works in man listings)
____ctrl-b : page up, (works in man listings)
____/text : forward search
____?text : backward search:
____F : go to end, display new data, (good for watching logs)
$ tail -n 200 development.log
____prints last 200 lines, -f keeps the file open and prints more as the file grows

Find Files / Search in Linux: Quick Examples

$ find / -name myfilename
____look in the root directory + mounted drives

$ find / -mtime -2
____find all files modified in the last two days

$ find . -name '?foo*'
____find all files in current and sub directories that start with foo (wildcard) (have to use ' ' with *)

$ find . -iname AbCd
____case insensitive

$ find / -user scott
____find files owned by scott (can do groups and permissions, too)

$ find / -type f
____find files, not directories. d is for directories, l is for sym links.

$ find / -name foo 2>/dev/null
____hide "permission denied errors". You could also just do $ sudo find ...

$ find . -maxdepth 2
____only go 2 directories deep

$ find . -size +20k -size -1M
____size is greater than 20k, less than 1M. note lower case k.

$ find . -exec grep -iH dog {} \;
____find files containing text (dog), i means case insensitive, sub l for H to get only file names
$ locate
____an indexed version of find, may not have recent files