The Basics – The command line
When you log in to a Linux system using SSH or open a terminal window from a Linux desktop, you are running a “shell” program. Basically, a shell is a program that processes the commands you type. It is very common to use Linux by entering commands in a shell. This is called “working from the command line”. In this brief guide, we’ll cover a number of useful commands and tools that will help you become more proficient at using the command line.
There are two common shells in Linux: bash and tcsh. Since bash has become the most common shell, we’ll be using bash in all the examples that follow.
The Shell Prompt
When the shell is ready for you to enter a command, it displays a “prompt”. Usually, the prompt will be something simple like:
bash$
To enter a command, you just type it after the prompt and hit <return>. For instance, you can find out today’s date and the current time by typing the command date like so:
bash$ date
Wed Jan 13 22:10:52 CST 2016
Basic Shell Commands – Changing Directories
In Linux, a “directory” is what Windows users usually call a “folder”. It’s basically a location in the file system for storing files. Directories are organized hierarchically starting with the directory called / at the top of the “directory tree”. There several common directories you should be aware of:
/usr/bin
– This is where the most common user programs are located.
/home/{username}
– Home directories are usually found under /home. For most Linux users, their home directory is /home/{username}, where {username} is the account name.
/tmp
– this is a temporary directory where you can put files that you don’t intend to keep.
/etc
– This is a path to where most of the configuration files that Linux uses are stored.
The cd Command
The cd command is one of the most common commands you will use. It allows you to different directories. It’s pretty simple, just type cd {destination}
where {destination} is the path you want to move to. Here are some examples:
cd /tmp
– Move to the /tmp directory.cd ..
– Move to the directory above your current directory.cd ../docs
– Move up one level, then down to the directory called “docs”.
The pwd Command
The pwd
goes hand in hand with the cd
. The pwd
command shows you where you currently are located in the directory tree. For example, to see what directory you are in type:
bash$ pwd
/home/johnd
bash$ cd ..
bash$ pwd
/home
Using ssh
Using SSH
ssh username@hostname
Display manual pages
man <command>
Examples
man yum
man chkconfig
Run a command as root
sudo <command>
Update system
sudo yum update
List all available pages
sudo yum list
Install one or more packages
sudo yum install <package1> [<package2>] […]
Add a local user account
sudo useradd <username>
Change Password
passwd
or
sudo passwd [<username>]
Edit firewall
system-config-securitylevel
List all services
sudo chkconfig –list
Set a service to start on boot
chkconfig <name> on
Examples
sudo chkconfig httpd on
sudo chkconfig mysqld on
Set up a LAMP Stack (Linux Apache MySQL PHP )
$ sudo yum install httpd mysql mysql-server php php-mysql
$ sudo chkconfig httpd on
$ sudo chkconfig mysqld on
$ system-config-securitylevel # Open port port in firewall for http
$ reboot