Linux

Linux is a family of open source software operating systems built around the Linux kernel. Linux runs most servers and many devices.

cmd   less   PuTTY sftp

Linux

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.

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. The commands are themselves programs; cd, ls, mv, pwd. On most Linux systems a program called bash acts as the shell program.

the shell is the command line interface (CLI). A command line is a way of talking about a shell running in a terminal.

[usernm@linuxbox ~]$
the shell prompt appears whenever the shell is ready to accept input.

cd .change dir
ls .list the contents of a dir 
mv .rename or move files 
pwd .print working dir
help find .help for find
man find .manual help for find, q to quit 
dig www.cocomas.com +short .DNS lookup utility, domain information groper  

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 /design	change dir to the design 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, what kind of file it is: txt, a bash script, jpg

less cmd.php	to read large text files, read only, q quit
/foo		search for files in a dir, search pattern foo
n		search repeat forward, go to next match
N		go to previous match
space bar	down 1 page
b		up 1 page
g		go to beginning of file
G		go to end of file

mkdir dir1		make a dir named dir1

cp file1 file1.bak	copy file named abc to abc.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 it beehive 
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 /lamp/linux/dir1/ move dir1 down to new location
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)

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
0			zero go to beginning of the line
$			end of the 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
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

 ^  beginning of a line
 $  end of a line
 .  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