Skip to main content

Posts

Showing posts with the label linux

Linux and Unix - Rsync

More Info: rsync <opt> <original path> <backup location> #This command does something similar to cp but instead it allows a few additional options and features. Using the option set you can use -v for verbose or -a for archive. The biggest difference is when you run it again it will only copy any new files to the destination. (Delta) This is a typical method of performing backups of Linux OS's.

Linux and Unix - Manipulating Files

Below is some common commands that I would like to know better so figured, why not and made a post about them: wc -w <file> #This counts the amount of words in a file. wc -l <file> #This counts the number of lines in a file. head <file> #This reviews the first set of text at the beginning of the file. It can be piped out to more using "| more" . tail <file> #Same as above but the end of thr file. This is commonly used to go ahead and tail a log file and watch it as it does stuff, for this however it requires the -f switch. grep <option> <keyword> <file(s)> #Here is where things get a little more complciated. With Grep you can either search files for certain keywords with no options or using options such as -<num> to view num of lines before and after where it was found, or -i for searching without case sensitivity. Keep in mind you can also search many files just using wildcards. sed '/<text...

Linux and Unix - Script and Screen

More for future me: script <filename> #This will basically start a file named whatever in thr location you specified with every command you entered. Once you are finished type Ctrl+D to stop recording the session and then you can go back and read your file. Keep in mind that script is not perfect and other cli based apps will get recorded too which may make your script output look a bit odd. Screen <option> #This is used when needing to switch or disconnect from multiple cli sessions. Using -list you can see all of the sessions, -r will allow you to reconnect to one and Ctrl+A and Quit will allow you to quit properly the session. If you only need to leave it temporarily using Ctrl+A and D which will just disconnect that screen session.

Linux and Unix - Script Building

Another dump of some information that i may need again in the future. Example Code: #!/bin/bash echo -e "What is your favorite color?" read choice echo "$choice is your favorite color." TLDR - Basically using read you can take text input. Echo will allow you echo is out to the prompt. You can also interact now with the variable $choice with other command such as grep or awk You can also use '-x' when executing your Bash Scripts to print it onscreen as it runs through in the event there is any errors or debugging needed.