Below is a brief guide for basic usage of a Linux shell (command line). Once you’ve mastered the commands to move between directories and search for files, using a shell will become very efficient!
A few commands to restart common services:
(CentOS) service sshd restart
(Debian) /etc/init.d/ssh restart
(CentOS) service httpd restart
(Debian) /etc/init.d/apache2 restart
(CentOS) service cpanel restart
(CentOS) service mysql restart
(Debian) /etc/init.d/mysql restart
For detailed information on any of the commands below, type “man [command]” at the command line.
top - Displays a summary of all running processes, with CPU and memory usage for each.
kill -9 PID - Kills a process. Use ‘top’ to find the PID of a running process.
grep root /etc/passwd - Shows all matches of root in /etc/passwd.
grep -v root /etc/passwd - Shows all lines that do NOT match root.
find /etc -name config - Lists all files in /etc containing ‘config’ in their name.
rm filename.ext - Deletes filename.ext.
rm -f filename.ext - Deletes filename.ext, bypassing confirmation.
tar xvfz file.tar.gz - Extracts a .tar.gz file.
bzip2 filename.ext - Zips filename.ext to filename.ext.
bz2. bunzip2 filename.ext.bz2 - Unzips filename.ext.bz2 to filename.ext
cp - Copy file.
mv - Moves a file, and can also change a filename.
chown - Change ownership permissions on a file.
mkdir - Creates a new directory with the name you specify, ex. ‘mkdir downloads’
cd - Change directory, for example to move to the directory /root, do “cd /root”
ls - List all files in the current directory.
netstat -an – Shows all open connections to the server.
ifconfig - Shows info for all configured network interfaces.
df -h : Displays a summary of total and used disk space.
passwd - Change your account password. If logged in as root, you can specify a user, e.g. “passwd user”
vi - A basic text editor included with all Linux distributions.
touch - Generates an empty file, ex. ‘touch index.php’ will create a blank index.php.
This article is also available in the VPS6 Knowledgebase: http://vps6.net/my/knowledgebase/2/General-Linux-Shell-Usage-and-Basic-Commands.html