From LedHed's Wiki
Revision as of 18:52, 20 January 2009 by Ledhed (Talk | contribs)

Jump to: navigation, search

Linux Commands that I rarely use and often forget.

Print Working Directory (pwd)

pwd = (Print Working Directory) Displays the current directory you're in.


Network Map (nmap)

nmap = (Network Map) Utility that displays open network ports.
Basic usage: nmap 192.168.0.1


String Filter (grep)

grep = Hard to explain, Filtering utility.
Basic usage: grep 'FilterString' filename
Usefull grep options:

-i 'FilterString'   =   case insensitive
-b #                =   Display # number of lines BEFORE a match
-a #                =   Display # number of lines AFTER a match
-v                  =   Invert Match or Exclusion
'FilterString1'\|'FilterString2'\|'FilterString3'  =  Multiple Filters


Remove Comments from files

grep -v '#' FileName1 > FileName2


Remove Whitespace from files

grep -v "^$" FileName1 > FileName2


List File/Directory Size

du = List the size of a file or Directory
Basic usage: du -hs <file or dir>
Usefull du options:

-h                  = human readable
-s                  = summarize (Display only total for each arguement)


File Comptession (tar)

Basic usage

to create a tar archive:

tar -pcvzf filename.tgz directory1/ directory2/

to extract an archive

tar -xvzf filename.tgz -C destination_directory/

Usefull tar options:

-x                  = extract
-c                  = create
-v                  = verbose (displays whats being archived or extracted on screen)
-j                  = use BZip format (.tar.bz2)
-z                  = use GZip format (.tar.gz or .tgz)
-p                  = Preserve file permissions
-f                  = File
-M                  = Multi-Volume
-L                  = Tape Length (or --tape-length=) accepts values in Kb.  Size = value x 1024

Span Multiple Files Example This will create multiple files 100MB in size (100 x 1024 = 102400)

tar -c -M -L=102400 --file=filename.part1.tar largefile.to.split.iso


When the first part is complete you will be presented a prompt like this:

Prepare Volume #2 for 'filename.part1.tar' and hit return:


To tell Tar that we want to continue with a new file we enter this:

n filename.part2.tar


Now you will be presented this prompt:

Prepare Volume #2 for 'filename.part2.tar' and hit return:

Notice the filename was accepted filename.part2.tar'. Now just press return

To Extract spanned tar files do this:

tar -x -M --file=filename.part1.tar largefile.that.was.split.iso


You will be prompted with this:

Prepare volume #2 for filename.part1.tar and hit return: n filename.part2.tar

Prepare volume #2 for filename.part2.tar and hit return: Now Press Retuen. Thats it.



More to come...