Basic Linux Commands

Last modified by Administrator on Thu, 02/13/2020, 5:31 PM
Page Rating
0 Votes

The following are some of the Linux commands and their purposes:

Command Prompt Basics

CommandDescription
pwdshow current working directory
man mandisplays manual information on the manual command
man <command>displays manual information on <command>
clearclears the screen
exitexits the command interpreter
historyshow which commands you ran

Manipulating Directories

CommandDescription
cdgo 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

CommandDescription
lslist files and sub directories in the current directory excluding hidden files
ls -alist all files and sub directories, including hidden files
ls -llong list of files and sub directories displaying the permissions, owner, group, size, date, time, name
ls -lhlong list of files and subdirectories with human-readable size
ls -ltlong list of files and sub directories sorted by time
ls -lrlong list of files and sub directories in reverse order
ls -ltrhlong list of files and sub directories sorted by time, in reverse order, with human readable size

Moving Files

CommandDescription
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

CommandDescription
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

CommandDescription
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

CommandDescription
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
tailfPrint bottom of file on screen then follows new input appended to the file

Text Editor

CommandDescription
nano <file>edit file using nano
Ctrl+Owrite out
Ctrl+Xexit editor
 
vim <file>edit file using vim/vi
iinsert text
Esc uundo the last change
Ctrl+Rredo the last change
Esc dddelete current line
Esc :xexit, saving changes
Esc :qexit as long as there have been no changes
Esc :q!exit and ignore any changes
Esc :set nushow line numbers
Esc /<text>search

Extract and Compress Files

CommandDescription
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

CommandDescription
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)

CommandDescription
rsyncremote 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
  
scpsecure 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

CommandDescription
screen –S <name>create screen session
screen -lslist active screen sessions
screen –dr <id/name>reattach to screen
screen -S <id> -X quitkill complete screen session
 
Once inside screen shell, this will now be controlled by keyboard shortcuts
Ctrl+\+cadd a session
Ctrl+\+kkill a session
Ctrl+\+nmove to next session
Ctrl+\+pgo back to previous session
Ctrl+\+ddetach screen session
Ctrl+\+[copy/scroll mode
Ctrl+\+]paste buffer
Tags: