#Shortcut to OPEN terminalctrl+alt+t#Shortcut to CLOSE terminalctrl+d#Kill the terminal proccesscltr+c#Auto completion of files namesuseTABwhileyouaretypinganynameoffile
Shortcuts
ctrl+A#move your cursor to the beginning of the linectrl+E#move your cursor to the End of the linealt+C#convert Capital character of word on Uppercase and rest on Lowercasealt+L#convert all characters beggining from the cursor on Lowercasealt+U#convert all characters beggining from the cursor on Uppercasectrl+K#Cut the text from the cursor to the end of the line (Kill text)ctrl+U#Cut the text from the cursor to the beggining of the linectrl+Y#Paste the text that you did cut (Yanking text)
Basic terminal commands
help
help command will help us how to use a parameters
helpcdhelprmcd--helprm--help
man
manual page of commands (like help, but better graphical)
mancp
whatis
short description of linux commands
history
show history of commands used in terminal
the whole bash history is in file ~/.bash_history
history#show you whole history of terminalhistory20#limited by number like 5, 20, 100 ...history-c#clean whole history (be careful)!412#if u type it in console just it use 412 command from history list412 ->gitclonehttps://github.com/testerBartek/GIT#to look on file with historygedit~/.bash_history
pwd
print working directory
cd
change directory
cdDesktop/#path to cdcd..#previos level of directory cd/#go to root dir cd~#go to home/USER dircd-#back to previous dir (in memory)
echo
print a wrote text
echotexttoprint>testtoprint
gedit
graphical text editor
create a new file and start to edit
edit current file
gedittest#open a text editor#you can close it, write something, save#after you close editor, you can back to terminal
nano
terminal text editor
nanotest#open file in terminal#you are allow to edit it#^G ^O ^W => ctrl+G ctrl+O ctrl+W ...
cat / tac
show text in the same window of terminal
cattest#normal texttactest#reverse
head / tail
head print first lines from the file
tail print the last lines from the file
[TIP] to create 30 or more lines of numbers use command:
for((i=1;i<=30;i++)); doecho $i >>30lines; done
tail30lines#tail FILE_NAMEhead30lines#head FILE_NAME#default command print 10 linestail-530lines#-5 it's parameter how much lines to printhead-830linestail-n530lines
wc
show line number , word number , byte/character numbers
wctest#wc FILE_NAME960390test#9 -> line number#60 -> word number#390 -> character numberswc-l#only show line numberwc-w#only show word numberwc-c#only show character numberwc-L#show the characters of the longest line!
ls
list a directory content
# Basic ls commandsls# list a dirls/# list root dirls~# list home dirls..# list previous dir files
ls-i# inode numberls-l# file size in bytes, date and time of modifications
ls-a# show every files (.hidden too)ls-t# show by last modificated filesls-r# reverse order (normal ls from A to Z, with -r from Z to A)ls-R# showing every dir and everything what is inside
hidden files always have dot "." before name like .hidden
#every parameters we could mixls-ali=ls-ail=ls-ial=ls-ila=ls-lia=ls-lails-tr# reverse timels-ltr# reverse time and show file sizels-latR# show .hidden files, file sizes, show by last modificated files#and every files inside directories
ln
Hard Link
the same inode number
the exactly same size of file
lnexamplehardlink1
Soft Link
(it's the same as shortcut in windows)
different inode number
smaller file size - only 8 bites
ln-sexamplesoftlink1
Create soft link to directory is possible but hard link isn't.
Files commands
touch
change timestamp of a file on current date and time
rm-ifile1#ask about remove the filerm-iRdir1#ask to remove every single file
rm-ffile1#remove force filerm-fRdir1#remove force dir #you can use it on not existing file #and logs don't give any information about this
rm-vfile1file2#remove file with information about itrm-vRdir1#remove directory with information about it
cp
copy files
#command scheme#cp file1 file2 ... file99 ... dir1 [the last is destination]cpfile1file2#copy file1 and paste in file2cpfile1file2dir1#copy file1 file2 and paste it in dir1cp-Rdir2dir1#copy dir use -Rcp-ifile1file2#ask about overwirte filescp-vrdir1dir2#show logs about the files
Be careful file could be overwrite !
mv
move files
renaming files
mvoldfilenamenewfilename#changing name of filemvhiddenfile.hiddenfile#make hidden filemvfile1file2dir1#move file1 and file2 to directorymv-ifile1dir1#ask to confirm overwrite file
file
check properties and file extension
filefile1catearthfilefile1
which / type
which -> print path to another command like cp / ls ...
[display an Executable's location]
type -> print path to another command and show is this command is shell builtin
Types of commands:
1. Executable Programs
2. Shell builtins
3. Shell scripts
4. Alias
Filenames with space and special characters
Create file and directory with space or special characters
mkdir'text with space'mkdir"text with space2"touchtext\ with\ space3touch'$%@ text with special characters $!@#'mkdir $\%\>\special\ charactermkdir \\ #show only 1. \
Own commands
multiple commands
use more than 1 command in one time
1stcommand; 2ndcommand; ...;nthcommand1stcommand&&2ndcommand&&...&&nthcommand#if command is incorrect the rest of commands will not execute#USABLE#1. create dir 2. create file 3. move file to new directorymkdirdir1; touchfile; mvfiledir1
wildcards
'*' and '?'
wildcard is a symbol that represents one or more characters
symbol '*' represents (matches) ANY characters
symbol '?' represents (matches) a SINGLE character
cp [abcd]* dir1 #copy files which start on letters a,b,c,dcp [!abcd]* dir1 #copy files which aren't start on letters a,b,c,dcp [1-3]* dir1 #copy files which start on numbers from 1 to 3 [1,2,3]cp [[:upper:]]* dir1 #copy files which start from UPPER lettercp [[:lower:]]* dir1 #copy files which start from low lettercp*[[:digit:]]dir1#copy files which ends on numbercp [[:alpha:]]* dir1 #copy files which starts on any letter (upper and lower)cp [[:alnum:]]* dir1 #copy files which emds on alhpabet or numeric
aliases
help to works faster with use specific own commands
alias#type list of created aliasalias newcommandname="YourCommand"#create aliasaliasnewcommandname#use definied aliasunaliasnewcommandname#delete aliasgedit~/.bashrc#file with aliases (edit / delete ...)