Linux Cheat Sheet

Linux Cheat Sheet

Day 12 of 90daysofdevops

Git & GitHub Cheat Sheet

Basic Linux commands

CommandDescription
lsLists all files and directories in the present working directory
ls -RLists files in sub-directories as well
ls -aLists hidden files as well
ls -alLists files and directories with detailed information like permissions, size, owner, etc.
cdTo change to a particular directory
cd ..Move one level up
cd ~Navigate to the HOME directory
cd /Move to the root directory
cat > filenameCreates a new file
cat filenameDisplays the file content
cat file1 file2 > file3Joins two files (file1, file2) and stores the output in a new file (file3)
mv file "new file path"Moves the files to the new location
mv filename new_file_nameRenames the file to a new filename
sudoAllows regular users to run programs with the security privileges of the superuser or root
rm filenameDeletes a file
manGives help information on a command
historyGives a list of all past commands typed in the current terminal session
clearClears the terminal
mkdir directory-nameCreates a new directory in the present working directory or at the specified path
rmdir directory-nameDeletes a directory
mvRenames a directory
apt-getUsed to install and update packages

File Permission commands

CommandsDescription
ls -lto show file type and access permission
rread permission
wwrite permission
xexecute permission
-=no permission
chown userFor changing the ownership of a file/directory
chown user:group filenamechange the user as well as a group for a file or directory

User management commands

CommandDescription
sudo adduser usernameTo add a new user
sudo passwd -l 'username'To change the password of a user
sudo userdel -r 'username'To remove a newly created user
sudo usermod -a -G GROUPNAME USERNAMETo add a user to a group
sudo deluser USER GROUPNAMETo remove a user from a group
chmod 777 filenameChange the mode of the file to 775
chmod -R 700 filenameRecurs­ively chmod folder to 700

File Permission Numbers

CommandDescription
The first digit is owner permis­sion, the second is group and the third is everyone.
Calculate permission digits by adding the numbers below.
4read (r)
2write (w)
1execute (x)

Environment Variables command

CommandDescription
echo $VARIABLETo display the value of a variable
envDisplays all environment variables
VARIABLE_NAME=variable_valueCreate a new variable
UnsetRemove a variable
export Variable=valueTo set the value of an environment variable

Bash Variables

CommandDescription
envShow enviro­nment variables
echo $NAMEThe output value of $NAME variable
export $Name=valueSet $NAME to the value
$PATHExecutable search path
$HOMEHome Directory
$SHELLCurrent shell

Search File

CommandDescription
grep -iCase insens­itive search
grep -rRecursive search
grep -vInverted search
grep -oThe show matched part of a file only
find /dir/ -name name*Find files starting with the name in dir
find /dir/ -user nameFind files owned by name in dir
find /dir/ -mmin numFind files modified less than num minutes ago in dir
whereis commandFind binary / source / manual for command
locate fileFind the file (a quick search of system index)

Process command

CommandDescription
topDetails on all Active Processes
psGive the status of processes running for a user
ps PIDGives the status of a particular process
pidofGives the Process ID (PID) of a process
kill PIDKills a process
dfGives free hard disk space on your system
freeGives free RAM on your system
niceStarts a process with a given priority
reniceChanges the priority of an already running process

VI Editing Commands

CommandDescription
iInsert at cursor (goes into insert mode)
aWrite after the cursor (goes into insert mode)
AWrite at the end of the line (goes into insert mode)
ESCTerminate insert mode
wqSave & Exit
uUndo last change
UUndo all changes to the entire line
oOpen a new line (goes into insert mode)
ddDelete line
3ddDelete 3 lines
DDelete the contents of the line after the cursor
CDelete the contents of a line after the cursor and insert new text. Press the ESC key to end insertion.
dwDelete word
4dwDelete 4 words
cwChange word
xDelete the character at the cursor
rReplace character
ROverwrite characters from cursor onward
sSubstitute one character under the cursor and continue to insert
SSubstitute the entire line and begin to insert at the beginning of the line
~Change case of individual character

Thank You,

Abhisek Moharana