Search For Answers
How do I create a Symlink in Linux?
Last updated: March 28, 2011
To create a symlink in linux first make sure you are in the directory you want the link to appear so for example say you want the link in /etc:
cd /etc
Then create the link:
ln -s /path/to/source sym_link_name
This will create the symlink in etc:
/etc/sym_link_name
How do I change the root password in Linux?
Last updated: March 28, 2011
To change the root password in Linux you must be logged in as root.
Enter the passwd command from the command line:
passwd
The message will say:
Changing password for user root.
You will then be prompted twice for the password. Be sure to use a long strong password for root:
New UNIX password:
Retype new UNIX password:
You will not see what you type for security.
It's usually easier to cut and paste the new password each time from another window or document that attempting to type it without seeing what you are entering.
If you did it correctly you will see:
passwd: all authentication tokens updated successfully.
How do I change a user password in Linux?
Last updated: March 29, 2011
To change the a user password in Linux you must be logged in as root or as that user.
Enter the passwd and the username from the command line:
(make sure you add the username or you will be attempting to modify the root password)
passwd somename
The message will say:
Changing password for user somename.
You will then be prompted twice for the password. Be sure to use a long strong password:
New UNIX password:
Retype new UNIX password:
You will not see what you type for security.
It's usually easier to cut and paste the new password each time from another window or document that attempting to type it without seeing what you are entering.
If you did it correctly you will see:
passwd: all authentication tokens updated successfully.
What are some common Bash commands for Linux?
Last updated: March 28, 2011
Here are some common bash shell commands to make working with Linux easier.
alias Create an alias
awk Find and Replace text, database sort/validate/index
break Exit from a loop
builtin Run a shell builtin
cal Display a calendar
case Conditionally perform a command
cat Display the contents of a file
cd Change Directory
cfdisk Partition table manipulator for Linux
chgrp Change group ownership
chmod Change access permissions
chown Change file owner and group
chroot Run a command with a different root directory
cksum Print CRC checksum and byte counts
clear Clear terminal screen
cmp Compare two files
comm Compare two sorted files line by line
command Run a command - ignoring shell functions
continue Resume the next iteration of a loop
cp
Copy one or more files to another location
cron Daemon to execute scheduled commands
crontab Schedule a command to run at a later time
csplit Split a file into context-determined pieces
cut Divide a file into several parts
date Display or change the date & time
dc Desk Calculator
dd Data Dump - Convert and copy a file
declare Declare variables and give them attributes
df Display free disk space
diff Display the differences between two files
diff3 Show differences among three files
dir Briefly list directory contents
dircolors Colour setup for `ls'
dirname Convert a full pathname to just a path
dirs Display list of remembered directories
du Estimate file space usage
echo Display message on screen
ed A line-oriented text editor (edlin)
egrep Search file(s) for lines that match an extended expression
eject Eject CD-ROM
enable Enable and disable builtin shell commands
env Display, set, or remove environment variables
eval Evaluate several commands/arguments
exec Execute a command
exit Exit the shell
expand Convert tabs to spaces
export Set an environment variable
expr Evaluate expressions
factor Print prime factors
false Do nothing, unsuccessfully
fdformat Low-level format a floppy disk
fdisk Partition table manipulator for Linux
fgrep Search file(s) for lines that match a fixed string
find Search for files that meet a desired criteria
fmt Reformat paragraph text
fold Wrap text to fit a specified width.
for Expand words, and execute commands
format Format disks or tapes
free Display memory usage
fsck Filesystem consistency check and repair.
function Define Function Macros
gawk Find and Replace text within file(s)
getopts Parse positional parameters
grep Search file(s) for lines that match a given pattern
groups Print group names a user is in
gzip Compress or decompress named file(s)
hash Remember the full pathname of a name argument
head Output the first part of file(s)
history Command History
hostname Print or set system name
id Print user and group id's
if Conditionally perform a command
import Capture an X server screen and save the image to file
info Help info
install Copy files and set attributes
join Join lines on a common field
kill Stop a process from running
less Display output one screen at a time
let Perform arithmetic on shell variables
ln Make links between files
local Create variables
locate Find files
logname Print current login name
logout Exit a login shell
lpc Line printer control program
lpr Off line print
lprint Print a file
lprintd Abort a print job
lprintq List the print queue
lprm Remove jobs from the print queue
ls List information about file(s)
m4 Macro processor
man Help manual
mkdir Create new folder(s)
mkfifo Make FIFOs (named pipes)
mknod Make block or character special files
more Display output one screen at a time
mount Mount a file system
mtools Manipulate MS-DOS files
mv Move or rename files or directories
nice Set the priority of a command or job
nl Number lines and write files
nohup Run a command immune to hangups
passwd Modify a user password
paste Merge lines of files
pathchk Check file name portability
popd Restore the previous value of the current directory
pr Convert text files for printing
printcap Printer capability database
printenv Print environment variables
printf Format and print data
ps Process status
pushd Save and then change the current directory
pwd Print Working Directory
quota Display disk usage and limits
quotacheck Scan a file system for disk usage
quotactl Set disk quotas
ram ram disk device
rcp Copy files between two machines.
read read a line from standard input
readonly Mark variables/functions as readonly
remsync Synchronize remote files via email
return Exit a shell function
rm Remove files
rmdir Remove folder(s)
rpm Remote Package Manager
rsync Remote file copy (Synchronize file trees)
screen Terminal window manager
sdiff Merge two files interactively
sed Stream Editor
select Accept keyboard input
seq Print numeric sequences
set Manipulate shell variables and functions
shift Shift positional parameters
shopt Shell Options
shutdown Shutdown or restart linux
sleep Delay for a specified time
sort Sort text files
source Run commands from a file `.'
split Split a file into fixed-size pieces
su Substitute user identity
sum Print a checksum for a file
symlink Make a new name for a file
sync Synchronize data on disk with memory
tac Concatenate and write files in reverse
tail Output the last part of files
tar Tape ARchiver
tee Redirect output to multiple files
test Evaluate a conditional expression
time Measure Program Resource Use
times User and system times
touch Change file timestamps
top List processes running on the system
traceroute Trace Route to Host
trap Run a command when a signal is set(bourne)
tr Translate, squeeze, and/or delete characters
true Do nothing, successfully
tsort Topological sort
tty Print filename of terminal on stdin
type Describe a command
ulimit Limit user resources
umask Users file creation mask
umount Unmount a device
unalias Remove an alias
uname Print system information
unexpand Convert spaces to tabs
uniq Uniquify files
units Convert units from one scale to another
unset Remove variable or function names
unshar Unpack shell archive scripts
until Execute commands (until error)
useradd Create new user account
userdel Delete user account
usermod Modify user account
users List users currently logged in
uuencode Encode a binary file
uudecode Decode a file created by uuencode
v Verbosely list directory contents (`ls -l -b')
vdir Verbosely list directory contents (`ls -l -b')
watch Execute/display a program periodically
wc Print byte, word, and line counts
whereis Report all known instances of a command
which Locate a program file in the user's path.
while Execute commands
who Print all usernames currently logged in
whoami Print the current user id and name (`id -un')
xargs Execute utility, passing constructed argument list(s)
yes Print a string until interrupted
.period Run commands from a file
### Comment / Remark
Use top or ps ux to get system PIDs (Process IDs)
EG:
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.
tail -f /var/log/messages
This will show a live feed of what is getting added to the messages log.
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
How do I create an alias in CentOS?
Last updated: March 29, 2011
When you become comfortable in a shell environment you start to look for ways to speed up your workflow and a great way to do that is by using aliases. An alias allows you to enter a word that you define that represents a different word, phrase or command.
To create an alias in CentOS first you need to open your .bashrc file in an editor and add an alias declaration. Each user has their own .bashrc file and the aliases in each of those files only apply to those users when logged into their own account so the aliases for the root user will be in here:
/root/.bashrc
But the aliases for a user named bob would be in here:
/home/bob/.bashrc (if that was the user bob's home directory)
Ok lets look at the syntax.
A basic alias looks like this:
alias keyword='target'
Where keyword is the word you will enter and target is the word, phrase or command that will actually be entered in the shell.
Lets say you are logged in as root and you commonly wish to access a remote server via ssh. Open the .bashrc file in /root in your favorite text editor (we will use vi).
Add a new entry in this format:
alias myserver='ssh root@192.0.32.10'
save the file and close your shell. Open a new shell to be able to use the new alias and type myserver and then enter (or return) and it will be just as if you had typed ssh root@192.0.32.10
Each alias goes on it's own line in .bashrc and remember you won't be able to use the alias until you open a new shell.
How do I use the cal command in Linux?
Last updated: March 28, 2011
The cal command in Linux allow you to view a graphical calendar highlighting today's date.
At the command prompt enter:
# cal
You will see a calendar like this printed to the screen.

How do I use the cat command in Linux?
Last updated: March 28, 2011
The cat command in Linux allows you to view the contents of a file.
To use the cat command just use the following syntax:
# cat /some/directory/filename
For a very long file you will end up viewing the very end so you may wish to view it with more control with the pipe command and the less or more command.
Like this
# cat /some/directory/filename | less
# cat /some/directory/filename | more
How do I use the more command in Linux?
Last updated: March 28, 2011
The more command when working on the command line allows you to view the contents of a file one screen size section at a time allowing you to page through a long file. It is used in conjunction with the cat command where the cat command prints the file to screen and the more command controls how you view the contents.
You use the more command like this:
# more /some/directory/filename
You use the pipe command to pipe the output of the cat to the more command like this:
# cat /some/directory/filename | more
This will print the first screen full of data from that file to your screen. To view the next part of the file press the spacebar.
How do I use the less command in Linux?
Last updated: March 28, 2011
The less command when working on the command line allows you to view the contents of a file allowing you to navigate through a long file. You can use it directly on a file or in conjunction with the cat command where the cat command prints the file to screen and the less command controls how you view the contents.
You use the less command like this:
# less /some/directory/filename
You use the pipe command to pipe the output of the cat to the less command like this:
# cat /some/directory/filename | less
The less command will print the first screen full of data from that file to your screen.
To traverse the file press the following.
down arrow - scrolls down one line
up arrow - scrolls up one line
d - scrolls down half a page
b - scrolls up half a page
q - exit less
For more control of the less command check out the man pages by typing:
# man less
How do I change directories in Linux?
Last updated: March 27, 2011
The CD command is how you change directories when working in a command line environment in Linux.
The syntax for using the CD command is like this:
# cd /animal/mammal
That is if you are wishing to start from the root directory of the server. The / in the front designates that the directory navigation starts from the root directory even if your current working directory is deep in the directory structure.
If you are in a directory that contains other directories and you want to enter into one of them you would not use the initial slash and would start with the name of the directory you wish to enter.
# cd cat/kitten
Looking at the above example if the cat directory is in the mammal directory from the first example and you are in the mammal directory the following commands will do the same thing.
# cd /animal/mammal/cat/kitten
# cd cat/kitten
If you are in a directory and wish to go up one in the path use the following command:
# cd ../
If you wish to go up two use that twice like this:
# cd ../../
You can also go up a few and then down into another directory. Using the above directory examples and if you start in kitten you could do this:
# cd ../../dog/puppy
That takes you up one to cat and up one more to mammal and then down into dog and then into puppy directory.
If you wish to go to your home directory you would use this command:
# cd ~
When you change directories using the tilde symbol it will take you to the home directory of the user you are logged in as.
How do I use the chgrp command in Linux?
Last updated: March 29, 2011
The chgrp command is how you change the group attribute applied to a directory or file in Linux.
The syntax to use the chgrp command for a directory:
# chgrp groupname directoryname
The syntax to use the chgrp command for a file:
# chgrp groupname filename
Now you may ask. How do I change the group ownership of a directory recursively? That means the directory and all the directories and files inside it.
The syntax to us the chgrp command for a directory recursively requires the -R flag:
# chgrp -R groupname directoryname
How do I use the clear command in Linux?
Last updated: March 28, 2011
The clear command is helpful when working on the command line in Linux. If you have lots of screen clutter and want to shift it out of the way so your prompt is at the top of an empty page use the clear command like this:
# clear
How do I use the chmod command in Linux?
Last updated: March 28, 2011
The chmod command is how you change the permissions applied to a directory or file in Linux.
The syntax to use the chmod command for a directory:
# chmod 755 directoryname
The syntax to use the chown command for a file:
# chmod 644 filename
Now you may ask. How do I change the permissions of a directory recursively? That means the directory and all the directories and files inside it.
The syntax to us the chmod command for a directory recursively requires the -R flag:
# chmod -R 755 directoryname
With the above please note that you may not want the files to have that 775 permissions so if you just want to change the permissions of directories recursively but not touch the files in those directories you need to do something a little more advanced. If the public_html directory is a directory in your current working directory:
# find public_html -type d -exec chmod 775 {} \;
How do I copy files or directories in Linux?
Last updated: March 28, 2011
The cp command lets you copy files or directories in the command line interface in Linux.
The syntax for this command is:
# cp originalfilename nameofcopy
This is the most basic usage of this command and just makes a copy of a file in the same directory with a new name. This is a good way to make a backup of a file before you edit it so in case you make a major mistake you can easily delete the file you messed up and rename the backup back to the original name.
With cp you can also copy files from other locations in the filesystem to anywhere else in the filesystem.
For example if your current working directory is the root home directory you are in /root and if you want to copy a file from one directory to another you just use the absolute paths to those two locations in your copy command.
# cp /some/directory/originalfilename /some/other/place/nameofcopy
How do move or rename files or directories in Linux?
Last updated: March 28, 2011
The mv command lets you move or rename files or directories in the command line interface in Linux.
The syntax for this command if using it to rename a file is:
# mv filename newfilename
This is the most basic usage of this command and takes some getting used to at first as this is how you rename a file in Linux. You move the file to the same directory but with a new name.
The same goes for a directory rename:
# mv directoryname newdirectoryname
With mv you can also relocate files from your current working directory to anywhere else in the filesystem.
For example if your current working directory is the root home directory you are in /root and if you want to move a file from that directory to another you just use the absolute path to the destination in your move command.
# mv filename /some/other/place/filename
Or for a directory:
# mv directoryname /some/other/place/directoryname
How do I make a new directory in Linux?
Last updated: March 29, 2011
To make a new directory in Linux you use the mkdir command.
This is the syntax for this command:
# mkdir somenewdirectory
You can make that new directory anywhere you wish using an absolute path. For example if you are in the root user's home directory you are in /root but if you ant to make a new directory somewhere else in the filesystem use this syntax:
# mkdir /some/other/directory/newdirectoryname
How do I list the files in a directory in Linux?
Last updated: March 29, 2011
To list or view the files and contents in a directory in Linux you use the ls command.
The syntax for this command is:
# ls
This is the most basic version of this command and will just provide filenames in your current working directory in a linear format. This is ok if you just have a couple files but if you have lots of files it can be difficult to find what you are looking for. Don't worry you have lots of tools at your disposal to display those files and information about them in a variety of ways. To do this you use flags or options to the command and here are a few examples and what they do.
# ls -a (shows all contents in the directory even hidden files that start with a .)
# ls -l (shows the contents in a long list format)
# ls -S (sorts by file size)
# ls -R (lists subdirectories recursively)
# ls -t (sort by modification time)
Now the real power comes when you combine these options. For example if you want to list all the contents in your current directory in a list including hidden from largest to smallest with the sizes in human readable format (-h) use this syntax:
# ls -alhS
For more options check out the manual files:
# man ls
How do I see the bash history in Linux?
Last updated: March 28, 2011
To see the bash history in Linux use the history command.
# history
You can also view the contents of the history from the file itself. To view root's bash history:
# cat /root/.bash_history
How do I view disk usage in Linux?
Last updated: March 28, 2011
To view disk usage in Linux use the df command. The most common way to do this is with the -h option to make it easier to read.
# df -h
Here is an example of the output:

How do I determine disk usage on Linux?
Last updated: March 28, 2011
To determine disk usage at the file level in Linux use the du command.
# du
This is the basic usage of this command and returns the size of very single file and directory in your current working directory and below so if you run this command from the root directory of the server it may take a while to run and you are probably not going to want to wade through the results.
This is where options come in as you can be more precise and get the data you want.
# du -c (shows a grand total)
# du -h (human readable sizes)
# du -s (just lists total)
The most common is to combine them to see just the total in a human readable format.
# du -sh
How do I exit a shell session in Linux?
Last updated: January 07, 2011
To get out of or exit a shell session in Linux you use the exit command.
# exit
This will terminate the session and take you back to where you entered from.
For example if you are on server A and you SSH to server B, do some work and then use the exit command the session at server B will close and you will be back in your session at server A.
How do I see how much free memory I have in Linux?
Last updated: March 28, 2011
To see your available memory in Linux you can use the free command.
# free
To see the output in megabytes rather than the default kilobytes use the -m option:
# free -m
You can also see memory usage using the top command.
How do I see or change the hostname in Linux?
Last updated: March 28, 2011
To see or change the hostname in Linux use the hostname command.
To see the hostname:
# hostname
To see the FQDN:
# hostname -f
To change the hostname takes a few steps:
In this example we are changing example.example.com to changed.example.com
1) Open your /etc/hosts file in an editor (we use vi) and edit the long and short names.
From this:
To this:
2) Open your /etc/sysconfig/network file in an editor (we use vi) and edit the hostname.
From this:
To this:
3) Use the hostname command to declare the new hostname.
# hostname newhostname
Now restart your network to make the changes made to the network file take effect.
# service network restart
OR
# /etc/init.d/network restart
Now exit your shell session and re login to see the new hostname.
How do I modify a user password in Linux?
Last updated: March 28, 2011
To set or modify a users password in Linux use the passwd command.
To set the root password you just enter the command with no user declared and hit enter (or return). You will be asked twice for the password. each time you will enter it, then hit enter (or return) and you will not see anything entered as you type (or paste) for security. If you did this correctly ypur output when complete will look like this:

If for the root user you try to use a short insecure password you will get a warning.
To set or modify the password for a specific user you add their account name to the passwd command.
# passwd someuser
And then the process is the same as above.
You will need to be logged in as root to change the root password and to change other users passwords. If you are logged in as a specific user you can change your own password by declaring your username as listed above.
How do I determine where I am in the filesystem in Linux?
Last updated: March 28, 2011
Sometimes when working deep in the filesystem in a command line interface and after bouncing around a bit you can lose track of where you are.
To find out where you are in the filesystem you want to know what is called your current working directory and you do this by using the pwd command which stands for Print Working Directory.
# pwd
This will show you your full path from root.
How do I see what processes are running in Linux?
Last updated: March 27, 2011
To see what processes are running in Linux use the ps command.
# ps
There are many options to get a great deal of information out of the ps command. the most common is ps aux which lists all processes in a user oriented format
# ps aux
or to see a full version:
# ps auxf
How do I delete a file in Linux?
Last updated: March 28, 2011
To delete a file in Linux use the rm command.
Use this syntax to remove the file:
# rm filename
You will be asked to confirm by entering yes or no.
How do I delete a directory in Linux?
Last updated: March 28, 2011
To delete a directory in Linux you use the rmdir command.
# rmdir directoryname
This command will only work on an empty directory. This is to protect you from deleting content within that directory.
To delete a directory immediately and all its contents which is called deleting a directory recursively you use the rm command with a custom flag.
rm -rf directoryname
This command can be VERY dangerous. I repeat. This command can be VERY dangerous!!
if you accidentally add an extra space before the directory name you could experience unwanted dataloss.
The f option will force the deletion without you having to ok each deletion within the directory
How do I shut down my server in Linux?
Last updated: March 28, 2011
To turn off your server from the command line in Linux use the shutdown command.
# shutdown -h now
How do I reboot my server in Linux?
Last updated: March 28, 2011
To reboot your server from the command line in Linux you can use the reboot command.
# reboot
You can also use the shutdown command with the reboot option.
# shutdown -r now
How do I see the last part of a file in Linux?
Last updated: March 28, 2011
If you want to see just the last part of a file when working in the command line interface in Linux you use the tail command.
To use the tail command use this syntax.
# tail filename
To view the last x number of lines of the file use the n option with a quantity declaration so for example if you wish to viw the last 500 lines of a large file you would use this syntax.
# tail -n 500 filename
An excellent option of the tail command is the f option. This allows you to view the live output of the file and see the latest lines get added to the file in real time. This is a powerfull tool for troubleshooting issues especially when using this to view log files. An example would be if you where having an isse with your system that happened when a specific action occurred you could tail the system messages file with the f option and then watch as that error was added as it happened.
Here is what that command would look like.
# tail -f /var/log/messages
How do I run a traceroute in Linux?
Last updated: March 28, 2011
To run a traceroute in the command line interface in Linux you use the traceroute command.
To run a traceroute use this syntax.
# traceroute 192.0.32.10
Or
# traceroute example.com
The output will show you the hops across the internet to the destination.
How do I add a new user in Linux?
Last updated: March 28, 2011
To add a new user from the command line in Linux use the useradd command.
The syntax for this command is like this:
# useradd username
This will (depending on your system's default config) create the user and the users home directory usually at /home/username
If your system is not configured by default to create the user's home directory you can use the m option to do so upon account creation.
# useradd -m username
If you want to create the user but do not want to create the home directory use the M option.
# useradd -M username
How can I tell who is logged in in Linux?
Last updated: March 27, 2011
If you are using the command line interface in Linux and wish to know who is logged in use the users command.
# users
How do I tell what user I am logged in as in Linux?
Last updated: March 28, 2011
To determine what user you are logged in as use the whoami command.
# whoami
How do I see who is logged in in Linux?
Last updated: March 28, 2011
To see who is currently logged in to the system in Linux use the who command.
# who
How do I delete a user in Linux?
Last updated: March 28, 2011
To delete a user in Linux you use the userdel command.
# userdel someusername
If you wish to also remove their home directory and mail spool file at the same time use the r option.
# userdel -r someusername
How do I copy a directory and it's contents in Linux?
Last updated: March 28, 2011
To copy a directory and all it's contents in Linux use the cp command with the a option.
# cp -a source destination
Source is the name of your directory and destination is the name you wish for the copy.