(10 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
<br> | <br> | ||
<br> | <br> | ||
+ | |||
+ | == Print Working Directory (pwd) == | ||
+ | |||
pwd = (Print Working Directory) Displays the current directory you're in.<br> | pwd = (Print Working Directory) Displays the current directory you're in.<br> | ||
− | + | ||
+ | |||
+ | |||
+ | == Network Map (nmap) == | ||
+ | |||
nmap = (Network Map) Utility that displays open network ports.<br> | nmap = (Network Map) Utility that displays open network ports.<br> | ||
''Basic usage: nmap 192.168.0.1 '' | ''Basic usage: nmap 192.168.0.1 '' | ||
<br> | <br> | ||
− | + | ||
+ | |||
+ | |||
+ | == String Filter (grep) == | ||
+ | |||
grep = Hard to explain, Filtering utility.<br> | grep = Hard to explain, Filtering utility.<br> | ||
''Basic usage: grep 'FilterString' filename<br> | ''Basic usage: grep 'FilterString' filename<br> | ||
Line 15: | Line 26: | ||
-a # = Display # number of lines AFTER a match | -a # = Display # number of lines AFTER a match | ||
-v = Invert Match or Exclusion | -v = Invert Match or Exclusion | ||
− | 'FilterString1 | + | 'FilterString1\|FilterString2\|FilterString3' = Multiple Filters |
<br> | <br> | ||
+ | '''Remove Comments from files''' | ||
+ | grep -v '#' FileName1 > FileName2 | ||
+ | <br> | ||
+ | '''Remove Whitespace from files''' | ||
+ | grep -v "^$" FileName1 > FileName2 | ||
+ | <br> | ||
+ | '''Remove Comments and Whitespace''' | ||
+ | grep -v '#\|^$' FileName > FileName2 | ||
+ | |||
+ | |||
+ | == List File/Directory Size == | ||
du = List the size of a file or Directory<br> | du = List the size of a file or Directory<br> | ||
''Basic usage: du -hs <file or dir>''<br> | ''Basic usage: du -hs <file or dir>''<br> | ||
Line 22: | Line 44: | ||
-h = human readable | -h = human readable | ||
-s = summarize (Display only total for each arguement) | -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 | ||
+ | <br> | ||
+ | When the first part is complete you will be presented a prompt like this: | ||
+ | Prepare Volume #2 for 'filename.part1.tar' and hit return: | ||
+ | <br> | ||
+ | To tell Tar that we want to continue with a new file we enter this: | ||
+ | n filename.part2.tar | ||
+ | <br> | ||
+ | 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'' | ||
+ | <br> | ||
+ | <br> | ||
+ | To Extract spanned tar files do this: | ||
+ | tar -x -M --file=filename.part1.tar largefile.that.was.split.iso | ||
+ | <br> | ||
+ | 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. | ||
+ | |||
+ | |||
+ | == Symbolic Links (symlinks) == | ||
+ | ln -s path/to/target linkname | ||
+ | or if the linkname is going to be the same as the source filename then | ||
+ | ln -s path/to/target | ||
+ | This would create a symlink named target that would point to path/to/target ( target -> path/to/target )<br> | ||
+ | Note: This also works for directories. | ||
+ | |||
+ | |||
+ | == Find == | ||
+ | Find all conf files on your system | ||
+ | find / -iname "*.conf" | ||
+ | |||
+ | Find files who haven't been modified in 1 year | ||
+ | find / -type f -mtime +356 -print0 | ||
+ | |||
+ | -mtime = modified time | ||
+ | -print0 = needed to display files containing white space | ||
+ | -type f = files (not directories) | ||
+ | |||
+ | Find old files who haven't been modified in the past 2 years and display their total disk usage | ||
+ | find / -type f -mtime 730 -print0 | du --files0-from=- -hc | tail -n1 | ||
+ | |||
+ | |||
+ | |||
+ | == Turn off Linux Case Sensitivity == | ||
+ | shopt -u nocasematch | ||
+ | |||
+ | shopt -s nocasematch | ||
+ | |||
+ | |||
+ | == List Files/Directories by access time (atime) == | ||
+ | ls -l --time=atime | ||
+ | |||
+ | |||
More to come... | More to come... | ||
[[Category:Linux]] | [[Category:Linux]] |
Latest revision as of 21:45, 7 March 2014
Linux Commands that I rarely use and often forget.
Contents
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
Remove Comments and Whitespace
grep -v '#\|^$' FileName > 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.
Symbolic Links (symlinks)
ln -s path/to/target linkname
or if the linkname is going to be the same as the source filename then
ln -s path/to/target
This would create a symlink named target that would point to path/to/target ( target -> path/to/target )
Note: This also works for directories.
Find
Find all conf files on your system
find / -iname "*.conf"
Find files who haven't been modified in 1 year
find / -type f -mtime +356 -print0
-mtime = modified time -print0 = needed to display files containing white space -type f = files (not directories)
Find old files who haven't been modified in the past 2 years and display their total disk usage
find / -type f -mtime 730 -print0 | du --files0-from=- -hc | tail -n1
Turn off Linux Case Sensitivity
shopt -u nocasematch
shopt -s nocasematch
List Files/Directories by access time (atime)
ls -l --time=atime
More to come...