Linux Commands - Essentials


##############
#File Commands
##############

ls                  # - Directory Listing
ls -al              # - Formatted listing with hidden files
cd dir              # - Change directory to dir
pwd                 # - Print Working Directory (Show Current Directory)
mkdir dir           # - Create a Directory dir
rm file             # - Delete File
rm -r dir           # - Delete a Directory
rm -f file          # - Do force delete of file
rm -rf dir          # - Do force delete of directory dir
cp file1 file2      # - Copy file1 to file2
cp -r dir1 dir2     # - Copy dir1 to dir2; Create dir2 if it doesn't exists
mv file1 file2      # - Rename / Move file1 to file 2
ln -s file link     # - Create Symbolic Link 'link' to 'file'
touch file          # - Create or Update file
cat > file          # - Place standard output to file
more file           # - Outputs contents of file
head file           # - Outputs the first 10 line of file
tail file           # - Outputs the last 10 lines of file
tail -f file        # - Output the contents of file as it grows


#Open all Files in Directory
cat * | less
cat File* | less


##########
# SEARCH
##########

grep pattern files        # - Search for patterns in files
grep -r pattern dir       # - Search recursively for pattern in a Directory

#Search for word in list of files
command | grep pattern    # - Search for pattern in the output of command
EX : cat Files* | grep -i "Error"


#Find file with grep sourcetype
egrep -R sourcetype .

#Fine file in directory and Display Output
fine . -name "filename" -exec echo {} \; -exec cat {} \; | less


###############
# System Info
###############

date          # - Shows current date and time
cal           # - Show the Month's Calendar
uptime        # - Show current uptime
w             # - Who is online
finger user   # - dispaly information about user
uname -a      # - Show Kernel Information
cat /proc/cpuinfo   # - CPU Information
cat /proc/meminfo   # - Memory Information
df            # - Disk Usage
du            # - Show Directory space usage
whereis app   # Show possible location of app
which app     # Show which app will be run by default

#####################
# Process Management
#####################

ps                  # - Display your currently active processes
top                 # - Display all running processes
kill pid            # - Kill process 'pid'
killall proc        # - Kill all processes named proc
bg                  # - List Stopped or Background Jobs
fg                  # - Brings the most recent job to foreground

#######
# SSH
#######

ssh user@host         # - Connect to host as user
ssh -p port user@host # - Connect to host on port as user

###############
# Installation
###############

./configure
make
make install

###############
# Users
###############

sudo adduser <username> sudo              #Add User to sudo group