7/29/2019 The Linux Bash Shell
1/4
The Linux Bash ShellA few shell commands
Time [command] - tells you how long the system took to execute the [command]command
pwd shows current working directorySet - various options for the Linux shell. Use this command to customize theshell.
Running Programs
exec myproc - Exec is used to execute a command when you want the programto replace the shell process. When the program terminates it will terminate theshell. Normally running a program by calling its location will start anotherprocess along the shell.
./program - will run the program named "program" inside of your current workingdirectory (. means current working directory)
To run the program "program" located in /home/user/ type /home/user/programthis will execute the program (. only executes if your in the working directory yourcurrent in).
You can execute a program just by typing the programs complete path inside ofthe shell. /home/user/program
Note: Program will only run if it's marked as executable with permissions
Shell Short Cuts:crtl + R - in shell allows you to search .history file. (pressing repeatedly willkeep searching till you find the command your looking for)crtl + P - Does the same as the up arrow crtl + N - does the same as the down arrow crtl + G terminates the search function (escape does the same thing)Crtl + S - Searchs forward in the command history. crtl + A - Move cursor to start of line crtl + E - Move cursor to end of linecrtl +B - move backward within a linecrtl + F - move forward within a linecrtl +D - deletes characters and moves down the linecrtl + K - deletes the entire linecrtl + X + backspace - deletes all characters from cursors current positionbackcrtl + T - transpose text moves character down the liESC then c will convert the letter above the cursor to upper case
7/29/2019 The Linux Bash Shell
2/4
ESC then u will convert the entire word to uppercaseeschistory c will clear all of your history. Good for if your trying to hidecommand line passwords enetered.
Shell Customization and Configuration
Each user home directory contains .bashrc and .profile as the main configurationfiles in bash/etc/profile and /etc/bash.bashrc are the global customizations for all user shells
Environment Variables
Set environment variables at the command line by typing
$: export VARIABLE=whatever
View all environment variables by typing env at the command line
To delete an environment variable use unset variable name (without $)
Redirection OperatorsAllows you to manipulate standard output and standard error to different files.
- Specified file will be used for standard input and standard output Creates a new file (or overwrites existing) for both standard output ANDstandard error.2>> - appends standard error to an already existing file if the file does not exist itis created.2>-createsoroverwritesafiletoappendstandarderror.
>>Appendsstandardoutputtoafileorcreatesthefileifitdoesnotcurrentlyexist.
>createsanewfileoroverwritesanexistingfileforstandardoutput
clue:2representsstandarderror
DataPipes:Apipewillredirectthefirstprogramsstandardoutputtothesecondprogramsstandardinput.Thisisusedbyusingthe|bar.
ProgramsForManipulatingtext
7/29/2019 The Linux Bash Shell
3/4
Tee-readfromstandardinputandwritetostandardoutputandfiles
Example:program|teefile.txt
Xargs-buildandexecutecommandlinesfromstandardinput
Example:ls|greptest|xargsrmWillremoveallfilesnamedtestinthefolder.
`-backtickworkssimilartothexargscommand
Combinefileswithcatbytyping:catfile1.txtfile2.txt>newfile.txt
Catisatoolforcombiningfilesspecificallyandisshortforthewordconcatenate
Catnwillnumberthelinesofafile
JoiningFiles-join:joinlinesoftwofilesonacommonfield
-tcharuseCHARasinputandoutputfieldseparator.
-1FIELDjoinonthisFIELDoffile1
-2FIELDjoinonthisFIELDoffile2.
-iwillignorecasewhenusingthejoincommand
Paste-mergelinesoffiles
expand-converttabstospaces
od-dumpfilesinoctalandotherformats
sort-sortlinesoftextfiles-Bydefaultthesortcommandusesthefirstfield.Youcanusekoptionseparatedbycommastochangewhatfielditsortson
split-splitafileintopieces
example:splitl2file1.txtname
resultsinsplittingthefileeverytwolinesandplacingtheminnameanamebnamecfornumberoflinesby2.
TR-Translate,squeeze,and/ordeletecharactersfromstandardinput,writing
tostandardoutput.
Example:trtestblah
7/29/2019 The Linux Bash Shell
4/4
FILEFORMATTINGCOMMANDS
Fmt-simpleoptimaltextformatter
nl-numberlinesoffiles
VIEWINGFILES
Head-outputthefirstpartoffiles,echosfirst10linesofthefile.
-ctospecifythenumberofbytestoview
-ntospecifythenumberoflinestoview.
tail-outputthelastpartoffiles
lessisusedtopagethroughfiles.Mostmanpagesarelaunchedwithlessandyou
canuselesstolaunchandviewfiles.Itisnotusedforeditingjustviewing.ThesamecommandsofVIapplytoless.
Cut-PrintselectedpartsoflinesfromeachFILEtostandardoutput.
-ccutsspecifiedlistofcharactersfrominputfile
wcwordcountofaselectedfile.
Sed-isastreameditor.Astreameditorisusedtoperformbasictexttransformationsonaninputstream(afileorinputfromapipeline).Whileinsomewayssimilartoaneditorwhichpermitsscriptededits(suchased),sedworksby
makingonlyonepassovertheinput(s),andisconsequentlymoreefficient.Butitissedsabilitytofiltertextinapipelinewhichparticularlydistinguishesitfromothertypesofeditors.
$FCEDITAND$EDITORareenvironmentvariablesthatdefinethedefaulttexteditors.