Linux
Linux is the most popular server OS, and runs most servers and many devices.
Linux is an open source OS. An operating system is the software that directly manages a system's hardware and resources, like CPU, memory, and storage. The OS sits between applications and hardware and makes the connections between all of your software and the physical resources that do the work.
the code was written from scratch so that the system would act very much like a Unix system, but would not contain any Unix code.
Linux sees everything as a file or a process, and the files are arranged in a hierarchical directory structure with a single tree. The kernel is the hub of the Linux operating system. Security is a feature of the core system and the kernel has a firewall, so that a Linux computer can more efficiently run the programs that you need to get things done.
command line
the command line, aka terminal, is a text input and output environment.
the command line running Bash, is a text based interface to the system. Within a terminal you have a shell. The shell is a part of the OS that defines how the terminal will behave, and the shell handles executing commands for you. The most common shell is called Bash. We use the Bash command line interface (terminal) on Unix/Linux.
login as:
the login program checks the username and password, and then starts another program called the shell.
the shell
the shell is a master program that coordinates the execution of other programs. The shell is a user interface between the user and the kernel which interprets the commands from the keyboard and gives them to the operating system to perform. It is a command line interpreter. The commands are themselves programs; ls, cd, mv, pwd.
[usernm@linuxbox ~]$
the shell prompt appears whenever the shell is ready to accept input.
cmd
learn
use PuTTY on a Windows box to access a remote server.
ls list the contents of a dir cd change dir mkdir make dir mv rename or move files pwd print working dir
cmd
. this dir, the "." notation refers to the working dir cd return to the home dir cd ~ return to the home dir cd .. change dir up 1 level, go to the parent dir cd /apfrd/here change dir to the here dir the absolute pathname from root dir, represented by leading slash in the pathname pwd print working dir ls list files and directories ls -l list long, show additional info ls -a list all, including hidden files ls design list all files in the design dir ls ./design same as above, dot refers to the working dir ls /abc/de list all files in this dir, absolute path from the root dir ls | spell list pipe spellcheck file determine what kind of data a file contains, determine file type: txt, jpg /foo search for files in a dir, search pattern foo n search repeat forward, go to next match N go to previous match 0 go to begin of line (num zero) $ go to end of line (Shift + $) space bar down 1 page b up 1 page g go to beginning of file G go to end of file yy yy copy line p p paste the line dd dd delete the current line dw delete current word D delete everything on the line to right of the cursor x delete character under the cursor u u undo last change U capital U undo all changes to entire line Ctrl+c command out clear, to get out of (>) :w save the file, but do not quit vi :wq write quit :q! quit without saving less cmd.php to read large text files, read only, q quit mkdir dir1 make a dir named dir1 cp filed filed.bak copy file named filed to filed.bak in the same dir cp -i file1 file2 copy with interactive -i option, you will be prompted before overwriting file2 cp file1 dir1/ copy file1 into dir1 cp file1 dir2/behive copy file1 into dir2 and rename the file behive cp -r dir1 dir2/ copy recursively cp dir1/* dir2/ copy all files in dir1 into dir2, dir2 must already exist mv file1 file2 rename file1 to file2, or dir1 to dir2 mv file1 dir2/ move file1 into dir2, dir2 must already exist mv dir1 abc/ move dir1 to a new location abc/dir1 mv dir1/* dir2/ move all files in dir1 into dir2 using wildcard * for all files mv dir1/* . move all files in dir1 to working dir rm file1 remove a file named file1 rm file1 file2 file3 remove a few files rm ./foo remove any file with foo rm \' kills the apostrophe file rm -ir dir1 rm interactive rm *[!cehg] deletes all that do not end with c,e,h,g rmdir dir1 remove a dir named dir1 rm -rf dir1 remove a dir, recursive and force (for a dir that is not empty)
help find help for find man find manual help for find, q to quit dig www.abc.com +short DNS lookup utility, domain information groper
cat
cat view_this writes contents to screen (Ctrl+D to exit) less view_this writes contents to screen 1 page at a time (Spacebar to next page, PageUp, PageDown, q quit) head writes first 10 lines tail writes last 10 lines h,j,k,l left, down, up, right or use the arrow keys e, j, Down, or Enter move forward one line y, k, or Up move backward one line f, Space, or Page Down move forward one page b, or Page Up move backward one page :e file_name examine a new file :n examine the next file :p examine the previous file h, or ? display help q quit
[wildcard]
* matches any characters, 0 or more char ? matches any single character, exactly 1 char [abcde] matches any character that is a member of the set abcde [a-e] exactly one character in the given range [!abcde] matches any character that is not listed [!a-e] matches any character that is not a member of the set range a-e {debian,linux} exactly one entire word in the options given moves all the HTML files, that have the word "linux" in their names, from the working directory into a directory named dir1: $ mv *linux*.html dir1 displays all files that begin with d and end with .txt: $ less d*.txt The following command removes all files whose names begin with junk., followed by exactly three characters: $ rm junk.??? With this command you list all files or directories whose names begin with hda, followed by exactly one numeral: $ ls hda[0-9] This lists all files or directories beginning with hda, followed by exactly two numerals: $ ls hda[0-9][0-9] The following lists all files or directories whose name starts with either hd or sd, followed by any single character between a and c: $ ls {hd,sd}[a-c] This command copies all files, that begin with an uppercase letter, to directory dir2: $ cp [A-Z]* dir2 This deletes all files that don't end with c, e, h or g: $ rm *[!cehg]
[man]
man find manual help for find spacebar nextscreen b back q quit
[find]
> find . -name lostfile -print start in the current dir (.) -name option makes the search case sensitive, find lostfile, print onscreen
[sed]
sed is a stream editor, like search and replace. sed does not change the input file, you must save output as another file. s substitute g make a global change, replace all instances of pattern >sed 's/pattern/replacement/g' file.php > outputfile.php >sed 's/dog/cat/g' file.php (replace dog with cat)
d delete > sed 'start,end' file.php > sed '2,3d' file.php (deletes line 2 and including all of line 3)
grep
g/re/p is a command line utility. global search with the regular expression and printing all matching lines. apple, banana, cherry, date.
found cherry Array ( [2] => cherry [3] => date )
preg_grep -Return array entries that match the pattern array preg_grep(string $pattern, array $input) This function traverses the input array, testing all elements against the pattern. $fruit = array('apple','banana','cherry','date'); $pattern = '/^[c,d]/i'; //beginning of line starts with c or d, case insensitive $pattern = '/^(\d+)?\.\d+$/'; $output = preg_grep($pattern, $fruit); //$fruit array print_r($output);
grep 'string' file grep 'design' * //find all files in a directory with design in the filename grep 'redeem' /home/design/*.php //search for the string in the design dir (in any .php file) grep 'string' . //just search the current dir grep -i 'this string' file.php //-i ignore case grep "\>[A-Za-z].*" file //search for any word which begins with a letter upper or lower case . matches any one characters * matches 0 or more of the previous characters .* matches any number or type of characters $pattern = '/^[a,b]/i'; //start with a or b [a,b], b thru d [b-d] [^] does not match any characters listed \< beginning of a word \> end of a word
learn
Linux command line interface, cli and bash scripting.
mywiki.wooledge.org/BashGuide linuxjourney.com/ shellcheck.net/ explainshell.com/