Basic Linux Commands Print

  • 0

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:

Apache:

(CentOS) service httpd restart

(Debian) /etc/init.d/apache2 restart

 

cPanel:

(CentOS) service cpanel restart

 

MySQL:

(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.

 

Processes

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.

 

Search

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.

 

File Manipulation

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.

 

Directory Manipulation

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.

 

Network

netstat -an - Shows all open connections to the server.

ifconfig - Shows info for all configured network interfaces.

 

Misc

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.

 

Was this answer helpful?

« Back