quickreference:unix
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| quickreference:unix [2022/04/30 15:08] – [Create Swap file] rodolico | quickreference:unix [2025/02/05 00:12] (current) – [Shell (mainly BASH)] rodolico | ||
|---|---|---|---|
| Line 4: | Line 4: | ||
| ===== Systems Administration ===== | ===== Systems Administration ===== | ||
| + | |||
| + | ==== Partitioning large drives ==== | ||
| + | |||
| + | Drives greater than 2 Terabytes are not handled well by the standard //fdisk// application, | ||
| + | |||
| + | This assumes we have a drive, sdg, that we want to set up with gpt and create one partition on. That partition will set up on optimal sector boundries, and use all of the space available. | ||
| + | |||
| + | <code bash> | ||
| + | # remove all old file system information. Not necessary, but I do it just because I can | ||
| + | wipefs -a /dev/sdg | ||
| + | # make this a gpt disk. Will wipe out any other partitioning scheme | ||
| + | parted /dev/sdg mklabel gpt | ||
| + | # make a new partition on optimal sector boundries. This is a primary partition, and starts | ||
| + | # at the beginning of the disk (0%) and goes to the end of the disk (100%) | ||
| + | # I put that in quotes as, from what I've read, the percent symbol does not work well | ||
| + | # within the bash command line | ||
| + | # note, we are not telling it what file system to use, so it defaults to Linux | ||
| + | parted -a optimal /dev/sdg mkpart primary ' | ||
| + | # display the information on the disk | ||
| + | parted /dev/sdg print | ||
| + | # format as ext4, no reserved space, and a disk label marked ' | ||
| + | mkfs.ext4 -m0 -Lbackup /dev/sdg | ||
| + | |||
| + | </ | ||
| + | ==== Rapidly wipe multiple hard drives ==== | ||
| + | |||
| + | Nothing beats DBAN [https:// | ||
| + | |||
| + | <code bash wipedrives.sh> | ||
| + | #! / | ||
| + | |||
| + | # for truly not sensitive information, | ||
| + | for drive in a b c d e f g | ||
| + | do | ||
| + | | ||
| + | done | ||
| + | # but, to really remove in a way that takes tons of effort to recover, do this also | ||
| + | for drive in a b c | ||
| + | do | ||
| + | echo Cleaning sd%drive | ||
| + | dd if=/ | ||
| + | done | ||
| + | </ | ||
| + | |||
| + | I had 7 drives to wipe, and this takes about 5 hours per drive, so a total of 35 hours. I realized I could probably run all 7 processes in parallel since, on my system, the drive controller is a lot faster than any individual drive So I decided to use the //screen// command and see if I could make that work. | ||
| + | |||
| + | <code bash wipedrives2.sh> | ||
| + | #! / | ||
| + | |||
| + | for drive in a b c d e f g h | ||
| + | do | ||
| + | | ||
| + | done | ||
| + | </ | ||
| + | |||
| + | Basically, we're using a bash for loop to grab all the drive names (I just used the last letter), running screen and immediately detaching the new process after telling it to run //bash -c// and the command after it in quotes (so it would not interpret the pipes in our current, non-screen shell). I'm running this right now, and //pv// is predicting it will be done in 11.5 hours, or less than a third of the time. BUT, it is really heating up the office with 7 drives being continuously written to at the same time. | ||
| + | |||
| + | **Warning**: | ||
| + | |||
| + | <code bash> | ||
| + | # find any mdadm volumes running on Linux | ||
| + | cat / | ||
| + | # assuming it showed you md127 was running (normal) | ||
| + | mdadm --stop /dev/md127 | ||
| + | # it should stop the MD array and make the individual drives accessible | ||
| + | </ | ||
| + | |||
| ==== Rename Server ==== | ==== Rename Server ==== | ||
| Line 17: | Line 84: | ||
| <code bash> | <code bash> | ||
| # change the host name, and the postfix name if that is installed | # change the host name, and the postfix name if that is installed | ||
| - | sed -i.old ' | + | sed -i.old ' |
| + | / | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | / | ||
| / | / | ||
| # update the aliases, if they exist | # update the aliases, if they exist | ||
| Line 164: | Line 237: | ||
| ===== Shell (mainly BASH) ===== | ===== Shell (mainly BASH) ===== | ||
| + | ==== Here Documents ==== | ||
| + | |||
| + | Most unix users are familiar with echo' | ||
| + | |||
| + | A **here document** is a way of having multiple lines processed at one time. In many cases, you can have similar functionality using quotes, but here documents are more robust. | ||
| + | |||
| + | For example, a simple test of a newly built mail system might include creating a file with all of the headers necessary, then passing that to // | ||
| + | |||
| + | <code bash> | ||
| + | sendmail user@example.com << EOF | ||
| + | To: user@example.com | ||
| + | from: root@example.org | ||
| + | Subject: test | ||
| + | |||
| + | This is a test | ||
| + | EOF | ||
| + | </ | ||
| + | |||
| + | The entire block above is one command. Here is the breakdown. | ||
| + | |||
| + | - //sendmail user@example.com// | ||
| + | - //<<// | ||
| + | - //EOF// is the tag which will mark the end of the text for the here document | ||
| + | - Everything up to the EOF is the actual string to be passed to sendmail | ||
| + | - //EOF// at the end marks the end of the here document. **Note**: there must be no leading or trailing whitespace. The tag must be exactly as entered after the << (case sensitive), and must be the only thing on the final line. | ||
| + | |||
| + | This only touches the surface of here documents. See [[https:// | ||
| ==== Find files within date range containing text ==== | ==== Find files within date range containing text ==== | ||
| Line 173: | Line 273: | ||
| This is very fast, since the find command rapidly decreases the number of messages which must be scanned (he has almost 300k e-mails in various folders, and it took less than 2 seconds). | This is very fast, since the find command rapidly decreases the number of messages which must be scanned (he has almost 300k e-mails in various folders, and it took less than 2 seconds). | ||
| + | |||
| + | ==== Find newest files in a directory tree ==== | ||
| + | |||
| + | This will go through an entire directory tree under the current directory and locate the newest 5 files. | ||
| + | |||
| + | <code bash> | ||
| + | find . -type f -exec stat --format '%Y :%y %n' " | ||
| + | </ | ||
| + | |||
| + | * Change //find .// to //find / | ||
| + | * Change //head// to //head -n 10// to grab the newest 10 files. | ||
| + | * You can add any kind of filter also, so entering //-iname ' | ||
| + | |||
| ==== Count all files in directory tree(s) ==== | ==== Count all files in directory tree(s) ==== | ||
| Line 323: | Line 436: | ||
| * https:// | * https:// | ||
| * https:// | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
quickreference/unix.1651349283.txt.gz · Last modified: 2022/04/30 15:08 by rodolico
