├── README.md
└── screenshots
├── .DS_Store
├── alias.PNG
├── bash_profile.PNG
├── cat.PNG
├── cd.PNG
├── cp.PNG
├── env.PNG
├── grep.PNG
├── home.PNG
├── linux-file-system.jpg
├── ls.PNG
├── mv_move.PNG
├── mv_rename.PNG
├── path.PNG
├── pipe.PNG
├── ps1.PNG
├── pwd.PNG
├── sed.PNG
├── sort.PNG
├── uniq.PNG
├── user.PNG
└── wc.PNG
/README.md:
--------------------------------------------------------------------------------
1 | # Unix and Linux Command Line Tools
2 |
3 | ##
[Download PDF](https://drive.google.com/open?id=1EFYgDFmrbr0dYRzGsEO7E5vhZGFIGTAK)
4 |
5 | ### Symbols and Uses
6 | 1. **>** redirects standard output of a command to a file, overwriting previous content.
7 | 2. **>>** redirects standard output of a command to a file, appending new content to old content.
8 | 3. **<** redirects standard input to a command.
9 | 4. **|** redirects standard output of a command to another command.
10 |
11 | ### Some General terms and keywords
12 | 1. **sort**: sorts lines of text alphabetically.
13 | 2. **uniq**: filters duplicate, adjacent lines of text.
14 | 3. **grep**: searches for a text pattern and outputs it.
15 | 4. **sed** : searches for a text pattern, modifies it and outputs it.
16 | 5. **export** VARIABLE="Value" sets and exports an environment variable.
17 | 6. **USER** is the name of the current user.
18 | 7. **PS1** is the command prompt.
19 | 8. **HOME** is the home directory. It is usually not customised.
20 | 9. **PATH** returns a colon separated list of file paths. It is customised in advanced cases.
21 | 10. **env** returns a list of environment variables.
22 | *e.g., env | grep PATH*
23 |
24 | ### Now Understanding above commands or keywords and even more
25 |
26 | 1. **pwd command**: *pwd* stands for 'print working directory'. It prints the current directory.
27 | ``` terminal
28 | $ pwd
29 | ```
30 | 
31 |
32 | 1. **ls command**: *ls* stands for 'list directory content'. Display all the files and directories in the current directory.
33 | '-' this is known as a flag, we can add more specifications and properties to our commands using these flags like in case of *ls*. e.g.,
34 | ``` terminal
35 | $ ls -a -l -h -r
36 | ```
37 | * This will print all the files and directories in the current directory but -a flag will help us to display the hidden files and directories, -l helps us to show detailed format, -r shows in reverse order and -h for units of memory, B for Bytes etc.
38 |
39 | * **You can also do like:**
40 | ``` terminal
41 | $ ls -alhr
42 | ```
43 | 
44 |
45 | 1. **cd command**: *cd* stands for 'change directory' and helps us to change the directory.
46 | ``` terminal
47 | $ cd games/
48 | ```
49 | 
50 |
51 | 1. **clear command**: *clear* is used to clear the console screen
52 | ``` terminal
53 | $ clear
54 | ```
55 |
56 | 1. **cp command**: *cp* is used to copy single or multiple files in current or another directory.
57 | ``` terminal
58 | $ cp add.c programs/
59 | ```
60 | add.c file will be copied to programs directory which is present in current directory.
61 | 
62 |
63 | 1. **mv command**: *mv* is used to move or rename single or multiple files.
64 | ``` terminal
65 | $ mv add.c interger_add.c
66 | ```
67 | renaming add.c to integer_add.c
68 |
69 | 
70 |
71 | ``` terminal
72 | $ mv add.c programs/
73 | ```
74 | moving add.c file to programs directory
75 | 
76 |
77 |
78 | 1. **cat command**: *cat* stands for 'concatenate and print files'. It displays all the content of a file.
79 | ``` terminal
80 | $ cat add.c
81 | ```
82 | It can be also used for copying and creating a new file and if the file exists and still we are using cat command to copy content then the content of the new file will be deleted and the copied content will be there. Below if the new_add.c exists before then it's content will be deleted and it'll have the copied content of add.c file.
83 | ``` terminal
84 | $ cat add.c > new_add.c
85 | ```
86 | **If you want contents of both files then use >> operator instead of >**
87 | 
88 |
89 | 1. **wc command**: wc stands for words, character, and it prints the number of lines, words and characters and file name of a file.
90 | ``` terminal
91 | $ wc script.py
92 | ```
93 | 
94 |
95 | 1. **sort command**: sorts the content of a file in alphabetical order.
96 | ``` terminal
97 | $ sort names.txt
98 | ```
99 | 
100 |
101 | 1. **Pipe (|)**: Pipe ‘|’ this takes the command as standard output on the left of it and pipes it as a standard input to the command on its right.
102 | ``` terminal
103 | $ env | grep PATH
104 | ```
105 | 
106 |
107 | 1. **uniq command**: uniq stands for "unique" and filters out only adjacent, duplicate lines in a file and hence it will not remove those repeating lines which are not adjacent and are coming after some lines so to overcome this we can first sort the lines and then use the uniq command if we don’t want even a single line repeated.
108 | ``` terminal
109 | $ sort names.txt | uniq > sorted_names.txt
110 | ```
111 | 
112 |
113 | 1. **grep command**: grep stands for "global regular expression print". It searches in a files for lines that match a pattern and returns the results. It is also case sensitive. Here, grep searches for "cout" in code.cpp file and print all lines which contains it.
114 | ``` terminal
115 | $ grep cout code.cpp
116 | ```
117 | **Tip:** *grep -i flag will remove the case sensitivity of the pattern being searched.*
118 | 
119 |
120 | 1. **sed command**: sed stands for "stream editor". It accepts standard input and modifies it based on an expression, before displaying it as output data. It is similar to "find and replace".
121 |
122 |
123 | **Let's look at the expression 's/snow/rain/':**
124 |
125 |
126 | * s: stands for "substitution". It is always used when using sed for substitution.
127 | * snow: the search string, the text to find.
128 | * rain: the replacement string, the text to add in place.
129 | ``` terminal
130 | $ sed 's/snow/rain/' forests.txt
131 | ```
132 | but note one thing it will only replace the first snow word with rain if you want to do it in the whole file then you have to use
133 | ``` terminal
134 | $ sed 's/snow/rain/g' forests.txt
135 | ```
136 | 
137 |
138 | 1. **nano command**: nano is a command line text editor. It works just like a desktop text editor like TextEdit or Notepad, except that it is accessible from the command line and only accepts keyboard input. It can edit or create a new file for you.
139 | ``` terminal
140 | $ nano hello_world.js
141 | ```
142 | 1. Ctrl + O, saves a file, O stands for output
143 | 2. Ctrl + X, exits the nano program, X stands for exit
144 | 3. Ctrl + G, opens a help menu
145 |
146 |
147 | **Note:** *Similarly, there is vim which can be accessed by vi command but it is operated differently*
148 |
149 |
150 |
151 | ### Bash Profile file
152 | bash_profile is the name of file used to store environment settings. It is commonly called the "bash profile". When a session starts, it will load the contents of the bash profile before executing commands.
153 | ``` terminal
154 | $ cat ~/.bash_profile
155 | $ nano ~/.bash_profile
156 | ```
157 | 
158 |
159 | 1. The ~ represents the user's home directory.
160 | 1. The . indicates that this file hidden file. A dot is used for hidden file
161 | 1. The name ~/.bash_profile is important, since this is how the command line recognises the bash profile.
162 | 1. The command nano ~/.bash_profile opens up ~/.bash_profile in nano.
163 | 1. The text echo "Welcome, Jane Doe" creates a greeting in the bash profile, which is saved. It tells the command line to echo the string "Welcome, Jane Doe" when a terminal session begins.
164 | 1. The command source ~/.bash_profile activates the changes in ~/.bash_profile for the current session.
165 | ``` terminal
166 | $ source ~/.bash_profile
167 | ```
168 | * Instead of closing the terminal and needing to start a new session, source makes the changes available right away in the session we are in.
169 |
170 |
171 | **Note:** *Similarly, there is .bashrc file which is available in some computers. You can use anyone of them just make sure which file dominates.*
172 |
173 |
174 |
175 | ### Aliases
176 | You can create shortcuts using alias command for long and frequently used commands and then you can use the small keywords instead of writing a long command and of course you can separate multiple commands using semicolons(;) like in second example.
177 | * I frequently use second one to reach my desktop easily by only pressing f
178 | ``` terminal
179 | $ alias cls='clear'
180 | $ alias f='cd ~/Desktop/'
181 | ```
182 |
183 | ``` terminal
184 | $ alias hide='defaults write com.apple.finder CreateDesktop false; killall Finder'
185 | $ alias show='defaults write com.apple.finder CreateDesktop true; killall Finder'
186 | ```
187 | 
188 |
189 | * Using second command you can hide all your Desktop folders and files and no body will be able to see your stuff. You can undo this using third command. But this is only valid for Apple Mac users.
190 |
191 |
192 | **Note:**
193 | * **alias cls = 'clear' is wrong only cls='clear' will work.**
194 | * **You can save all your aliases into bash_profile file if you want to make them permanent.**
195 |
196 |
197 |
198 |
199 | ### Environment
200 | Each time we launch the terminal application, it creates a new session. The session immediately loads settings and preferences that make up the command line environment. We can configure the environment to support the commands and programs we create. This enables us to customise greetings and command aliases, and create variables to share across commands and
201 | programs.
202 |
203 |
204 |
205 | **env command**: The env command stands for "environment", and returns a list of the environment variables for the current user. Here, the env command returns a number of variables, including PATH, PWD, PS1, and HOME.
206 | ``` terminal
207 | $ env
208 | ```
209 | 
210 |
211 | You can also try
212 | ``` terminal
213 | $ env | grep PATH
214 | ```
215 | This will print the PATH environment vairable from the environment using grep command. I hope now you are able to use these commands simultaneously. *Congratulate yourself!!*.
216 |
217 | #### Environment Variables
218 | Environment variables are variables that can be used across commands and programs and hold information about the environment.
219 | Some of the environment variables are given below, rest you can explore on your own.
220 |
221 | 1. **USER variable**: export USER="Farhan" sets the environment variable USER to a name "Farhan". Usually the USER variable is set to the name of the Computer's owner.
222 | ``` terminal
223 | $ export USER="Farhan"
224 | $ echo $USER
225 | ```
226 | 
227 | * The line export makes the variable to be available to all child sessions initiated from the session you are in. This is a way to make the variable persist across programs.
228 | * At the command line, the command echo $USER prints the value of the variable.
229 |
230 |
231 | **Note that $ is always used when we are using an environmental**. Here, the command echo $USER prints the name set for the variable.
232 |
233 |
234 | 2. **PS1 variable**: PS1 is a variable that defines the makeup and style of the command prompt.
235 | ``` terminal
236 | $ export PS1="I am developer >> "
237 | I am developer >> ls
238 | ```
239 | export PS1="I am developer >> " will change the styling of your command prompt to this.
240 | 
241 |
242 |
243 | 3. **HOME variable**: The HOME variable is an environment variable that displays the path of the home directory.
244 | ``` terminal
245 | $ echo $HOME
246 | ```
247 | 
248 |
249 |
250 | 4. **PATH variable**: PATH is an environment variable that stores a list of directories separated by colons(:). Each directory contains scripts for the command line to execute. The PATH variable simply lists those directories that contain scripts.
251 | ``` terminal
252 | $ echo $PATH
253 | ```
254 | For example, many commands we've learned are scripts stored in the /bin directory.
255 | > This is the script that is executed when you type the pwd command. /bin/pwd.
256 |
257 |
258 | > This is the script that is executed when you type the ls command. /bin/ls
259 | 
260 |
261 | ## Some tips
262 | 
263 | * You can also use man command to know or gain information about any command including the flags that you can use with that command
264 | ``` terminal
265 | $ man cat
266 | ```
267 | * Single dot (.) in Unix or Linux is used for current directory
268 | ``` terminal
269 | $ ls .
270 | ```
271 | * Double dots (..) are used for one level up directory
272 | ``` terminal
273 | $ ls ../
274 | ```
275 |
276 |
--------------------------------------------------------------------------------
/screenshots/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/farhan787/LinuxCommandLine-Tools/1678db345b9e9640cfb7a39bf2513b43c82a2567/screenshots/.DS_Store
--------------------------------------------------------------------------------
/screenshots/alias.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/farhan787/LinuxCommandLine-Tools/1678db345b9e9640cfb7a39bf2513b43c82a2567/screenshots/alias.PNG
--------------------------------------------------------------------------------
/screenshots/bash_profile.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/farhan787/LinuxCommandLine-Tools/1678db345b9e9640cfb7a39bf2513b43c82a2567/screenshots/bash_profile.PNG
--------------------------------------------------------------------------------
/screenshots/cat.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/farhan787/LinuxCommandLine-Tools/1678db345b9e9640cfb7a39bf2513b43c82a2567/screenshots/cat.PNG
--------------------------------------------------------------------------------
/screenshots/cd.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/farhan787/LinuxCommandLine-Tools/1678db345b9e9640cfb7a39bf2513b43c82a2567/screenshots/cd.PNG
--------------------------------------------------------------------------------
/screenshots/cp.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/farhan787/LinuxCommandLine-Tools/1678db345b9e9640cfb7a39bf2513b43c82a2567/screenshots/cp.PNG
--------------------------------------------------------------------------------
/screenshots/env.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/farhan787/LinuxCommandLine-Tools/1678db345b9e9640cfb7a39bf2513b43c82a2567/screenshots/env.PNG
--------------------------------------------------------------------------------
/screenshots/grep.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/farhan787/LinuxCommandLine-Tools/1678db345b9e9640cfb7a39bf2513b43c82a2567/screenshots/grep.PNG
--------------------------------------------------------------------------------
/screenshots/home.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/farhan787/LinuxCommandLine-Tools/1678db345b9e9640cfb7a39bf2513b43c82a2567/screenshots/home.PNG
--------------------------------------------------------------------------------
/screenshots/linux-file-system.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/farhan787/LinuxCommandLine-Tools/1678db345b9e9640cfb7a39bf2513b43c82a2567/screenshots/linux-file-system.jpg
--------------------------------------------------------------------------------
/screenshots/ls.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/farhan787/LinuxCommandLine-Tools/1678db345b9e9640cfb7a39bf2513b43c82a2567/screenshots/ls.PNG
--------------------------------------------------------------------------------
/screenshots/mv_move.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/farhan787/LinuxCommandLine-Tools/1678db345b9e9640cfb7a39bf2513b43c82a2567/screenshots/mv_move.PNG
--------------------------------------------------------------------------------
/screenshots/mv_rename.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/farhan787/LinuxCommandLine-Tools/1678db345b9e9640cfb7a39bf2513b43c82a2567/screenshots/mv_rename.PNG
--------------------------------------------------------------------------------
/screenshots/path.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/farhan787/LinuxCommandLine-Tools/1678db345b9e9640cfb7a39bf2513b43c82a2567/screenshots/path.PNG
--------------------------------------------------------------------------------
/screenshots/pipe.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/farhan787/LinuxCommandLine-Tools/1678db345b9e9640cfb7a39bf2513b43c82a2567/screenshots/pipe.PNG
--------------------------------------------------------------------------------
/screenshots/ps1.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/farhan787/LinuxCommandLine-Tools/1678db345b9e9640cfb7a39bf2513b43c82a2567/screenshots/ps1.PNG
--------------------------------------------------------------------------------
/screenshots/pwd.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/farhan787/LinuxCommandLine-Tools/1678db345b9e9640cfb7a39bf2513b43c82a2567/screenshots/pwd.PNG
--------------------------------------------------------------------------------
/screenshots/sed.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/farhan787/LinuxCommandLine-Tools/1678db345b9e9640cfb7a39bf2513b43c82a2567/screenshots/sed.PNG
--------------------------------------------------------------------------------
/screenshots/sort.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/farhan787/LinuxCommandLine-Tools/1678db345b9e9640cfb7a39bf2513b43c82a2567/screenshots/sort.PNG
--------------------------------------------------------------------------------
/screenshots/uniq.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/farhan787/LinuxCommandLine-Tools/1678db345b9e9640cfb7a39bf2513b43c82a2567/screenshots/uniq.PNG
--------------------------------------------------------------------------------
/screenshots/user.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/farhan787/LinuxCommandLine-Tools/1678db345b9e9640cfb7a39bf2513b43c82a2567/screenshots/user.PNG
--------------------------------------------------------------------------------
/screenshots/wc.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/farhan787/LinuxCommandLine-Tools/1678db345b9e9640cfb7a39bf2513b43c82a2567/screenshots/wc.PNG
--------------------------------------------------------------------------------