Linux Survival Kit

A list of the most common linux commands. If you are to handle Linux, Apache, or Vi for the first time this can help you

___________________________________________________
________..:::.. LINUX SURVIVAL KIT ..:::.._________


(Or how to type commands without really knowing what you're doing...
at first..)


________________________________________________________

man
manual
ex: man vi (shows vi manual)
________________________________________________________

uname -r
to see actual Linux kernel
________________________________________________________

reboot
shutdown -r now
both are to reboot
________________________________________________________

halt
shutdown -h now
both are to shutdown the machine
________________________________________________________

adduser username
to add an user

userdel username
to delete an user

passwd username
to change the password
________________________________________________________

[options]
-R recursive
-f folder
* all files
ex: cp -Rf SOURCE TARGET will copy all files and folder (recursive)
________________________________________________________

ls -la
Listing directories

ls -l
view the current permissions on files and directories

ls -a
to list hidden files
________________________________________________________

find

find a file: go to root folder
cd /
ex: find httpd.conf
find -name httpd.conf
find -name httpd.*

________________________________________________________

grep

find a string recursively inside files: find | xargs grep -r "mysql_query"

find recursively and display line number:
grep -r -n Something
________________________________________________________

sed

find and replace in file(s), in this example we want to
replace all calls to a funcion utf8_decode() but keeping
the parameter value

if I've got: utf8_decode($myMyStringValue);
I will get: $myStringValue; instead

sed -e 's/utf8_decode(\(.*\))/\1/g' my_file.php


cp

cp SOURCE TARGET
ex: cp httpd.conf httpd_copy.conf
________________________________________________________

mv
move/rename a file
ex: mv old_name new_name
________________________________________________________

rm

remove files/folders
ex: rm -Rf my_folder (Will remove my_folder and all folders and files under that name)

NEVER rm $Rf / (You will erase all folders & files from the root folder!!!)
________________________________________________________

chown
change owner of a file
ex: chown username. filename/directory
________________________________________________________

chmod
change permissions
ex: chmod xxx filename/directory
You will have to replace the xxx flags with the permissions you wish to change. You can either go by the numerical value or by the actuals.

Some common numerical values are:
755 - Read, Write, Execute for owner, read, execute for group and other.
644 - Read, Write for owner, read for group and other.
666 - Read, Write for all.
700 - Read, Write, Execute for owner, nothing for group, other.
________________________________________________________

mount
to mount a drive
ex to access to a cdrom drive:
mount /dev/cdrom /mnt/cdrom
mount /dev/cdrom /cdrom
________________________________________________________

pwd
shows path to actual directory
________________________________________________________

su -
Change to system user
________________________________________________________

rpm -Uvh filename.rpm
to install a program (RedHat, Mandrake, SuSE
________________________________________________________

diff
Compare TWO files
________________________________________________________

who
Shows who is connected
________________________________________________________

history
Shows a list of command typed for an user
________________________________________________________

apt-get install emacs
-- to install emacs (Debian)
________________________________________________________

dpkg -l|grep php
-- to see if something is installed and which versions (-l: list)
________________________________________________________

whereis
find a command
ex: whereis php5


some colour:Make "ls" command show colors without "--color=always" switch
edit the user .bashrc file
add or edit an alias
alias ls="ls --color=always"
Then give the command:
source .bashrc
That will reload .bashrc
________________________________________________________




_________________________
__TAR: ZIP/UNZIP FILES___


Create -> tar cvzf myfile.tgz origin_files (wildcards admitted)
See files -> tar tzf myfile.tgz
Extract-> tar xvzf myfile.tgz



____________
___APACHE___


/etc/init.d/apachectl start

/etc/init.d/apachectl restart

/etc/init.d/apachectl stop


--- OR ----

Find Apache bin directory:

1. go to root
cd /
2. Use Find command
find -name apache*
3. Command the service
/usr/local/apache2/bin/apachectl start



___________
___MySQL__

Command line

/usr/local/mysql/bin/mysql start

ps aux | grep mysql




::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
VI/VIM COMMANDS
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


Key: Action:

Enter command mode
i Enter insert mode to exit mode
R Enter overwrite mode
a Enter append mode
:w Save File
:q Exit vim without saving
x Delete the character under the cursor
dw Delete the current word
dd Delete the current line
d$ Delete everything Right of the cursor
yy Yank the current line onto the clipboard
yw Yank the current word onto the clipboard
p Paste the clipboard
u Undo
^r Redo
G Jump to bottom of file
/text Search for the textfrom the cursor



__________
___Mail___

cat /dev/null > /var/mail/root

Will delete all mail from user root.
_______________________________________________________

mutt

Launch email client on the command line
______________________________________________________
mailq -v

To check how many pending mail you have
_______________________________________________________
rm /var/spool/mail/*.*
rm /var/mqueue/*.*

Manually removed pending mails
_______________________________________________________

sendmail -v -q

Delete pending mails using sendmail command
_______________________________________________________

$ sendmail -qS -v domainname.com it will delete all mail from *@domainname.com

You can delete certain domain or user or recipient mail using the following command
________________________________________________________
$ sendmail -qR -v gmail.com
Delete mail from recipient gmail.com

________________________________________________________
$ find /var/spool/mqueue -type f -exec grep "Deferred: Connection refused" {} \; -exec rm -rf {} \;
Use find command to removed queues


:::::::::::::::::::::::::::::::::::::::::::::::::::
CONSOLE COLORS
:::::::::::::::::::::::::::::::::::::::::::::::::::


tput setf 4 ( set foreground color to 4)

tput setb 2 (set background color to 2)


* 0 Black
* 1 Red
* 2 Green
* 3 Yellow
* 4 Blue
* 5 Magenta
* 6 Cyan
* 7 White

//-- some other colors

"DarkGreen"
"Sienna"
"RoyalBlue"
"Blue"
"Black"
"Black"
"Purple"
"Wheat"


//-- OPEN EMACS WITH PRESET COLOURS

emacs -bg blue -fg magenta