Linux Basics Commands Cheat Sheet for CentOS 7

Linux Basic Commands Cheat Sheet Quick Review for Linux Shell / Terminal / Console.

Print Working Directory

Print the name of the current working directory
[root@techbrown~]# pwd

List of Files and Directories

To see the list of files and directories
[root@techbrown~]# ls <options> <arguments>

-l – Long list including attributes
-a – All files and directories including hidden
-d – For a particular file or directory
-R – Recursive to see the tree structure

Creation of files

Files can be created by using any of the three methods given below:

  • Cat command
  • Touch command
  • Vi editor
Cat (Concatenation) Command
Creating and displayed text files
[root@techbrown~]# cat <option> <arguments><filesname>
To create a file
[root@techbrown~]# cat > <filename>
To view the contents of a file
[root@techbrown~]# cat <files=name>
To append or add to an existing file
[root@techbrown~]# cat >> <filename>
To combines the data of two or more files into a third file
[root@techbrown~]# cat <first file> <second file> >> <third file>
Touch Command
To create a zero byte file
[root@techbrown~]# touch <filename>
To create multiple zero byte files
[root@techbrown~]# touch <first file> <second file> <third file>
To change the time stamp of a file or directory
[root@techbrown~]# touch <directory or filename>
Vi Editor
To create file
[root@techbrown~]# vi <filename>

Creating Directories

To create a directory
[root@techbrown~]# mkdir <directory name>
To create multiple directories
[root@techbrown~]# mkdir <first dir> <second dir> <third dir>
To create nested directories
[root@techbrown~]# mkdir –p <first dir>/<second dir>/<third dir>
Navigation of Directories
To change the directory
[root@techbrown~]# cd <path of the directory>
To change directory one level back
[root@techbrown~]# cd ..
To change directory two levels back
[root@techbrown~]# cd ../..
To change to the last working directory
[root@techbrown~]# cd –
To change to the users home directory
[root@techbrown~]# cd

Help or Manual Page

To view the manual page of a command
[root@techbrown~]# man <command>


To copy a file or directory
[root@techbrown~]# cp <options> <source file> <destination>

-r – Recursive (to copy the directory along with its contents)
-v – Verbose
-p – Copy with permissions

Moving and Renaming

To move a file or directory to a different location
[root@techbrown~]# mv <source file or directory> <destination>
Rename a file or directory
[root@techbrown~]# mv <old name> <new name>


To remove or delete an empty directory
[root@techbrown~]# rmdir <directory name>
To remove or delete a file or directory
[root@techbrown~]# rm <option> <file or directory name>

-r – Recursive (directory along with contents)
-f – forcefully

Some other commands

To see the date
[root@techbrown~]# date
To see the calendar
[root@techbrown~]# cal

File Viewing Commands

To view the contents o f a file screen-wise
[root@techbrown~]# less <file name>
To view the top lines of a file
[root@techbrown~]# head <filename>
[root@techbrown~]# head -5 <filename>
To view the bottom line of a file
[root@techbrown~]# tail <filename>
[root@techbrown~]# tail -3 <filename>

VI editor modes

VI editor has three modes of operations

  • Command Mode
  • Insert mode
  • Ex Mode (Extended Command Mode)
Insert Mode

I – Insert the text at the current cursor position.
l – Insert the text in beginning of a line
a – Adds the text after the current cursor position
A – Adds the text at the end of a line
o – Insert the text one line below current cursor position
O – Insert the text one line above current cursor position

Ex mode

:q – Quit without saving
:q! – Quit forcefully without saving
:w – Write (save)
:wq – Save and quit
:wq! – Save and quit forcefully
:se nu – sets line numbers
:se nonu– Remove line numbers
:84 – The cursor goes to line 84

Command Mode

dd – Deletes a line
ndd – Deletes ‘n’ lines
yy – Copies a line
nyy – Copies ‘n’ lines
p – Put (pastes the deleted or copied text)
u – Undo(you can undo 1000 times)
G – Moves the cursor to the last line of the file
Congratulations now you have ready to use Basic Linux Commands on Terminal or Console.



Cheat Sheet CentOS 7
Command Description Comments (optional)
sudo Runs a commands as Super User A very important commands as it allows you to do literally everything.
yum Lets you install software and packages Often used with the sudo commands.
ls List Directory Contents Lists everything in the current directory.
cd Change Directory Used to switch directories.
pwd Display pathname Displays the current pathname.
mv Rename or move files Moves/renames files or directories.
cp Copy files or directory
mkdir Make Directory Create a folder in your current directory.
rm Delete files or folders
who Checks who is logged on Shows all online users.
clear Clear terminal window Clears the complete window of your terminal.
systemctl (start/stop/enable/disable) Manages OS services and start-ups
firewall-cmd CentOS Firewall Critical system function (security).
nano Text editor Not installed with minimum install.
tar Unzips tar archives(+more)
unzip Unzips an archived folder Commonly used with .zip files.
chmod Change file permissions
chown Changes owner of a file or folder

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.