To list your files and directories — ls
With the listing you also want to see the attribute details of each file — ls – al
To switch over to another directory, you can use cd command
e.g
cd /usr/local/apache
for going to the apache directory under usr local
cd – for going to the last directory you were in
cd .. for going to the parent directory
for printing the contents of the file on the screen you can use cat
e.g cat abc.txt which will display the contents of the abc.txt on your screen
There are few very big log files, if you want to read only the end of the file, you can use the tail command
e.g
tail /var/log/messages
If you want to watch the file continuously while it is being updated you can use the -f option
with the tail command
e.g
tail -f /var/log/messages
If you want to just display 20 lines of the file on the screen then you can use the command
tail -20 /var/log/messages
You can also use the more command to open the file one screen at a time
e.g.
more /etc/userdomains
In this you can press the spacebar to go to the next screen and q for quit
Editors
I uses two of the editors pico and vi
pico /home/domain/public_html/index.html You can use this to edit the index page for the user's website.
vi /home/burst/public_html/index.html
Please, you need to go for their specified tutorials, before using them.
To look for the pattern in the files, you need to use the grep command
grep root /etc/passwd It will display all matches of root in /etc/passwd
If you want the revers, I mean you does not want display the lines, which does not contain particular pattern, for that you can use the -v option with the grep command
grep -v root /etc/passwd
To create an empty file, you can use the touch command
touch /home/domain/public_html/404.html This will create an empty file called 404.html in the directory /home/domain/public_html/
Sometimes, you need to access the fiile, which have got very long paths, for them for them you can use the ln command to create the links between the files and the directories
ln -s /usr/local/apache/conf/httpd.conf /etc/httpd.conf
Now you can edit /etc/httpd.conf rather than the original. changes will affect the orginal, however you can delete the link and it will not delete the original.
To delete a file you can use the rm command
rm abc.txt
it will be asking for the confirmation before actually deleting the abc.txt and
if you want that it does not ask you for the confirmation then you can use the -f option with the rm command
rm -f abc.txt
There is one option, -r, for deleting the subdirectories and directories, but, I will never suggest you to use this option.
If you want to see the last login's information, you can use the last command
last -20 This will show only the last 20 logins
If you want to see the hostname in the last filed, you can use -a option with this
last -20 -a
If you want to see, who is currently logged in and from where, then just type w on the command line.
netstat will show all current network connections.
netstat -an will show all connections to the server, the source and destination ips and ports.
netstat -rn It will show routing table for all ips bound to the server.
To display live system processes in a nice table, memory information, uptime and other useful info you can use the top command. This is excellent for managing your system processes, resources and ensure everything is working fine and your server isn't bogged down.
To sort by memory
top + m
To sort by CPU usage
top + p
If you wanted to just display currently running processes and their PID you can use the ps command (ps for process status)
A process ID is a unique number that identifies a process, with that you can use to kill or terminate a running program on your server (see kill command).
ps U username To show processes for a certain user
ps aux It will show all system processes
ps aux –forest : shows all system processes like the above but organizes in a hierarchy that's very useful!
file * This will prints out a list of all files/directories in a directory
du : shows disk usage.
du -sh : shows a summary, in human-readble form, of total disk space used in the current directory, including subdirectories.
du -sh * : same thing, but for each file and directory. helpful when finding large files taking up space.
wc : word count
wc -l filename.txt : tells how many lines are in filename.txt
cp : copy a file
cp filename filename.backup : copies filename to filename.backup
cp -a /home/domain/new_design/* /home/domain/public_html/ : copies all files, retaining permissions form one directory to another.
kill: terminate a system process
kill -9 PID wsshe: kill -9 431
kill PID EG: kill 10550
Use top or ps ux to get system PIDs (Process IDs)
e.g.
PID TTY TIME COMMAND
10550 pts/3 0:01 /bin/csh
10574 pts/4 0:02 /bin/csh
10590 pts/4 0:09 APP
Each line represents one process, with a process being loosely defined as a running instance of a program. The column headed PID (process ID) shows the assigned process numbers of the processes. The heading COMMAND shows the location of the executed process.
Putting commands together
Often you will find you need to use different commands on the same line. Here are some examples. Note that the | character is called a pipe, it takes date from one program and pipes it to another.
> means create a new file, overwriting any content already there.
>> means tp append data to a file, creating a newone if it doesn not already exist.
< send input from a file back into a command.
grep User /usr/local/apache/conf/httpd.conf |more
This will dump all lines that match User from the httpd.conf, then print the results to your screen one page at a time.
last -a > /root/lastlogins.tmp
This will print all the current login history to a file called lastlogins.tmp in /root/
tail -10000 /var/log/exim_mainlog |grep domain.com |more
This will grab the last 10,000 lines from /var/log/exim_mainlog, find all occurances of domain.com (the period represents ‘anything',
— comment it out with a so it will be interpretted literally), then send it to your screen page by page.
netstat -an |grep :80 |wc -l
Show how many active connections there are to apache (httpd runs on port 80)
mysqladmin processlist |wc -l
Show how many current open connections there are to mysql
mysqldump -u username -ppassword dbname > file.sql
MySQL Dump
tar -zxvf file.tar.gz
UnTAR file
mysql -uusername -ppassword database_name <file.sql
Importing MySQL database
Simplest way to know about executable files
If the /tmp *directory contains any of the executable file, all the sites stops. The simplest way to know executable file in a directory is by using *-F *option with *ls command, which distinguishes directory and executable files from ordinary files. The -F option causes a slash (/) to be appended to the filename for directories and an asterisk (*) to be appended to files which are executable. For example,
$ ls -F