Other Information - Basic Linux Commands 

Page / - last modified by COARE Admin on Thu, 02/13/2020, 5:31 PM 

Basic Linux Commands 
last modified by COARE Admin
on Thu, 02/13/2020, 5:31 PM

Table of Contents
Command Prompt Basics
Manipulating Directories
Listing Files
Moving Files
Removing Files
Copying Files
Viewing Files
Text Editor
Extract and Compress Files
Downloading Files from the Internet
Transferring of Files from Local Machine to Server (Vice Versa)
Multiplexer for Terminal Sessions on One Window

Table of Contents
•	Command Prompt Basics
•	Manipulating Directories
•	Listing Files
•	Moving Files
•	Removing Files
•	Copying Files
•	Viewing Files
•	Text Editor
•	Extract and Compress Files
•	Downloading Files from the Internet
•	Transferring of Files from Local Machine to Server (Vice Versa)
•	Multiplexer for Terminal Sessions on One Window
The following are some of the Linux commands and their purposes:
Command Prompt Basics
Command	Description	
pwd	show current working directory	
man man	displays manual information on the manual command	
man <command>	displays manual information on <command>	
clear	clears the screen	
exit	exits the command interpreter	
history	show which commands you ran	
Manipulating Directories
Command	Description	
cd	go to home directory	
cd ..	go to the previous/parent directory	
cd <directory>	go to specific directory	
mkdir <directory>	create directory	
rmdir <directory>	remove empty directory	
Listing Files
Command	Description	
ls	list files and sub directories in the current directory excluding hidden files	
ls -a	list all files and sub directories, including hidden files	
ls -l	long list of files and sub directories displaying the permissions, owner, group, size, date, time, name	
ls -lh	long list of files and subdirectories with human-readable size	
ls -lt	long list of files and sub directories sorted by time	
ls -lr	long list of files and sub directories in reverse order	
ls -ltrh	long list of files and sub directories sorted by time, in reverse order, with human readable size	
Moving Files
Command	Description	
mv <source> <dest>	move file/directory <source> to a file/directory <dest>	
mv -i <source> <dest>	move file/directory <source> to a file/directory <dest>
prompt before overwriting if it exists	
mv -f <source> <dest>	move file/directory <source> to a file/directory <dest>
overwrite <dest> if it exists	
mv <file-old> <file-new>	change file/directory name to a new file/directory name	
Removing Files
Command	Description	
rm <file>	remove file <file>	
rm -i <file>	remove file <file> prompt before removing	
rm -r <directory>	remove directory <directory>	
rm –rf <directory>	remove all sub directories and files	
Copying Files
Command	Description	
cp <source> <dest>	copy file <source> to file <dest>	
cp -i <source> <dest>	copy file <source> to file <dest> prompt before overwriting <dest> if it exists	
cp -r <source> <dest>	copy directory <source> to directory <dest>
copy all sub directories and files	
Viewing Files
Command	Description	
cat <file>	concatenate file/s and print on screen	
more <file>	view single page at a time	
less <file>	view single page at a time with scrolling	
head <file>	print top of file on screen	
tail <file>	print bottom of file on screen	
tailf	Print bottom of file on screen then follows new input appended to the file	
Text Editor
Command	Description	
nano <file>	edit file using nano	
Ctrl+O	write out	
Ctrl+X	exit editor	
 	
vim <file>	edit file using vim/vi	
i	insert text	
Esc u	undo the last change	
Ctrl+R	redo the last change	
Esc dd	delete current line	
Esc :x	exit, saving changes	
Esc :q	exit as long as there have been no changes	
Esc :q!	exit and ignore any changes	
Esc :set nu	show line numbers	
Esc /<text>	search	
Extract and Compress Files
Command	Description	
tar -xvzf <file.tar.gz>	extract gzip files verbosely	
tar -xvjf <file.tar.bz>	extract bzip2 files verbosely	
tar -xvJf <file.tar.xz>	extract xz/lzip files verbosely	
tar -cvf <file.tar> <file/folder-to-compress>	compress tar file verbosely	
unzip <file.zip>	unzip zip file	
Downloading Files from the Internet
Command	Description	
wget <URL>	download	
wget -c <URL>	resume download	
wget -i <filename>	download multiple files

Note: Filename should contain all URLS for the files	
Transferring of Files from Local Machine to Server (Vice Versa)
Command	Description	
rsync	remote and file synchronization tool	
rsync -avhP <user@ip-address:/src/path> <dst-path>	copying files from a remote server to a local machine

-a archive
-v verbose mode
-h human-readable
-P progress	
rsync -avhP <src-path> <user@ip-address:dst-path>	copying files from local to remote server	
rsync -avhP -partial <src-path> <dst-path>	ensuring copy won’t start again after disconnection	
 	 	
scp	secure copy (remote file copy program)	
scp –rv <user@ip-address:src-path> <dst-path>	copying files from a remote server to a local machine
-r recursively copy entire directories
-v verbose mode	
scp -rv <src-path> <user@ip-address:dst-path>	copying files from local to remote server	
Multiplexer for Terminal Sessions on One Window
Command	Description	
screen –S <name>	create screen session	
screen -ls	list active screen sessions	
screen –dr <id/name>	reattach to screen	
screen -S <id> -X quit	kill complete screen session	
 	
Once inside screen shell, this will now be controlled by keyboard shortcuts	
Ctrl+\+c	add a session	
Ctrl+\+k	kill a session	
Ctrl+\+n	move to next session	
Ctrl+\+p	go back to previous session	
Ctrl+\+d	detach screen session	
Ctrl+\+[	copy/scroll mode	
Ctrl+\+]	paste buffer	

Thank you for rating this Wiki page.
You may choose to provide a more detailed feedback for this page using the form below or by contacting us here. Otherwise, click Close. 
Name 
 
Comment 

         

           

               Close
               Submit