Shell Commands
Following are the commands that will make you familiar with Shell.
echo
'echo' is a command to print out messages on your console, like the print() function in any programming language
echo 'Hello shello!!'
output:
Hello shello!!
echo $COLUMNS X $LINES
output:
80 X 24
Note that it is case sensitive, the variables needs to be called uppercased
ls
and cd
ls means list, it lists all the files and folders in a particular folder.
cd means change directory, the last will change the directory/folder/file you are accessing.
ls
ls -l // it will list the working directory/files and shows more information on each of the folder/files like name, date, size etc
ls -l *.txt // it will list all the files with txt extension
cd /path/to/desired/folder // will change the working directory to provided path
cd .. // will change the working directory to its immediate parent directory
cd frontend // will change the working directory to frontend directory
pwd
(Printing working Directory)
Sometimes the terminal you are using will not show you the directory you are at the moment, that is when you use pwd command.
pwd
mkdir
, mv
(Organising Files)
mkdir: stands for make directory mv: stands for move
mkdir Desktop/folder_name // it would create a new directory
mv file.txt new_folder // it would move file.txt to the provided folder ie: new_folder
mv Desktop/new_folder/*.pdf Desktop // it would move all the pdfs to Desktop directory
curl
(Download)
This is the way to download files inside shell env,
curl -L -o dictionary.txt 'https://tinyurl.com/zeyq9vc'
It would hit the tinyurl and saves its response inside dictionary.txt after following redirects. -L: specifies follow redirects as well
cat
, less
(File View)
cat: is short for catenate or concatenate.It reads the file and output its content less: shows you piece by piece of a file, you can scroll down page to see line by line
cat dictionary.txt
less dictionary.txt
rm
, rmdir
(Removing files)
rm: is short for removing files rmdir: is short for remove directory
rm dictionary.txt
rmdir curldata/dictionary.txt
grep
, wc
(Search and Pipes)
grep: global regular expression print, which means it can be used to see the received input matches a specified pattern. wc: word count
grep shell dictionary.txt
bombshell
bombshells
bushelled
cockleshell
eggshell
grep shell dictionary.txt | less
curl -L 'https://tinyurl.com/zeyq9vc' | grep fish | wc -l
curl -L 'https://tinyurl.com/zeyq9vc' | grep -c fish
Another way of doing that is giving the grep a '-c' to count the number of 'fish' words found.
grep -c ibo dictionary.txt
grep will look for the word ibo inside dictonary.txt file and output its count
Environment variables and shell
As other programming languages, shell has its own syntax to give variables values (=) and to call ($) these variables
numbers='one two three'
echo $numbers
echo $PWD
Controlling the shell prompt
There are many different types of shells which can be used by Linux terminals.By default, The Bourn Again SHell, or bash for short is used. Upon logging in, several login scripts are run which loads a users personal preference. One of these scripts is .bashrc
To edit your .bashrc file use a command line editor like vim or nano:
vim ~/.bashrc
nano ~/.bashrc
export PATH=$PATH:<path/to/dir>
source <path/to/env>/bin/activate
alias ll="ls -l"