├── Commands.md
├── LICENSE
└── README.md
/Commands.md:
--------------------------------------------------------------------------------
1 |
Linux/Unix Commands
2 |
3 | ## Linux Commands used day to day
4 | - `acpi`- _to display battery status and other acpi information_
5 |
6 | - `apt-get` - _helps in handling packages in Linux_
7 |
8 | - `arch` - _used to print computer architecture_
9 |
10 | - `bc` - _used for command line calculator_
11 |
12 | - `cal` -_used to see the calendar of a specific month or a whole year_
13 |
14 | - `cc` - _it is used to compile C language codes and create executables_
15 |
16 | - `ccrypt` - _command line tool for encryption and decryption of data_
17 |
18 | - `man` - _used to give description of any linux command like this_ ```$ man ls```
19 |
20 | - `info` - _an alternative toobtain uder documentation for a given program is to invoke info instead of man ```$ info ls```
21 |
22 | - `mv` - _mv command is used to move or rename files_
23 |
24 | - `pwd` - _shows the present working directory_
25 |
26 | - `chmod` - _command sets the file permissions flags on a file or folder
27 |
28 | - `lsusb` - _command used to check usb port id
29 |
30 | - `lspci` - _command used to check all detailed information about all PCI buses and devices in the system
31 |
32 | ## Listing Files
33 | - `ls`
34 | - If you want to see the list of files on your UNIX or Linux system, use the `ls` command
35 | - `ls -l` or `ll`
36 | - If you want to organize the files in list
37 | - `ls -lh`
38 | - If you want to arrange the files in list and show their size
39 |
40 | ## Listing Hidden Files and Normal Files
41 | - `ls -al`
42 | - If you want ot see the list of all files with all hidden files in the Current directory system in Linux
43 | - `ls -lha`
44 | - If you want to organize files in list format with their sizes and see hidden files
45 |
46 | - `ls -l`
47 | -Displays long list view with detailed file information including file type, permissions, link count, owner, group, size, date and time
48 |
49 | - `ls -lt`
50 | -Lists all files sorted by date and time with the newest file first.
51 |
52 | - `ls -ltr`
53 | -Lists all files sorted by date and time with the oldest file first.
54 |
55 | - `ls -lh`
56 | -Displays all files in current directory with file sizes in human readable format(eg:1.6K,328M,2.4G)
57 |
58 | - `ls -a`
59 | - If you want to list all files including hidden files that start with "."
60 |
61 | - `ls -la`
62 | - Lists all files,including hidden files,in the current directory with detailed information.
63 |
64 | - `ls -F`
65 | - Displays all files in current directory with their file types.
66 |
67 | ## Creating & Viewing Files
68 | - To create a new file, use the command
69 | 1. `cat > filename`
70 | 2. Add content
71 | 3. Press `ctrl + d` to return to command prompt.
72 | - Files can also be quickly created using
73 | - ```echo "Hello World" > ./fileName.txt```
74 | - To view a file, use the command `cat filename`
75 |
76 | ## Searching for content in a file/ files in a directory
77 | - To search for a word in a file using terminal,use the command ```grep```
78 | - For eg., if you want to search for the word GNU in a file named ```GNU.txt```,type ``` grep GNU GNU.txt```
79 | - This will show all lines which have the word ```GNU``` in that file
80 | - To search over multiple files in a directory, use ```grep``` with ```-r``` flag, like ``` grep -r GNU .```. Here ```-r``` stands for recursive search and ```.``` specifies the search root to be the current directory.
81 |
82 | ## Searching for a file
83 | - `find . -name ".js" -print`: find all files with JS extnesion and print them on screen
84 | - `find . -type d -name "*tmp" -print`: print all directories ending with `tmp`
85 | - `find . -type f -exec ls -l {} \;`: use `ls -l` on all returned values
86 |
87 | ## Exiting the shell
88 | - `exit` (also aliased to `bye` or `quit` in some shell flavors)
89 |
90 | ## Get root access
91 | 1. To log in as a super user use one of the following commands in the terminal. You can actually use this command to log in as any user on the machine, but when left blank it will attempt to log in as root.\
92 | - `su -`
93 | - `sudo -i`
94 | - These commands will ask you for password.
95 | 2. To jump right into root, run\
96 | - `sudo su -`
97 | - Since there is no root password made after live install.
98 | 3. To run other commands as root temporarily, use the command\
99 | - `sudo` *`command`*
100 | - Replace the *command* above with your command. Eg: `sudo apt-get update`
101 |
102 | ## Updating, Installing and Listing packages
103 | The commands for installing and updating applications depend on the version of Linux you are using, specifically whether it's Debian- or RPM-based.
104 |
105 | * Debian Based systems
106 | - Update the list of available packages and their versions, but doen not install or upgrade any packages. use the command ```sudo apt update```
107 | - Install newer versions of installed packages,use the command ```sudo apt upgrade```
108 | - Install any required package,use ```sudo apt install 'your package name'```. Example: ```sudo apt install apache2```
109 |
110 | * RPM-based systems
111 | - Update all or specified packages,use ```sudo yum update```. Example for updating specific package: ```sudo yum update mysql```
112 | - Lists known and installed packages,use ```sudo yum list``` ```sudo yum list --installed```
113 | - Install requested package,use ```yum install```. Example: ```sudo yum -y install firefox```
114 | - On Fedora 22 and later, you can also use 'dnf' in place of 'yum'. dnf stands for dandified yum, and is just an updated version of yum. Syntax is very similar, Examples would be: ```sudo dnf update``` or ```sudo dnf install```. More info on this [here.](https://opensource.com/article/18/8/guide-yum-dnf)
115 | - On openSUSE, use ```zypper install PACKAGE_NAME``` and ```zypper remove PACKAGE_NAME``` to install or remove packages. To add an repo in openSUSE, ```sudo zypper addrepo ```. More info on this [here](https://doc.opensuse.org/documentation/leap/reference/html/book.opensuse.reference/cha.sw_cl.html)
116 |
117 | ## Download YouTube videos on Linux
118 |
119 | For this you need to install an utility called **youtube-dl**, which is a command-line program to download videos from YouTube.com and a few more sites. It requires the Python interpreter, version 2.6, 2.7, or 3.2+, and it is not platform specific. It should work on your Unix box, on Windows or on macOS. It is open source project. You can contribute [here.](https://github.com/ytdl-org/youtube-dl)
120 |
121 | To install it right away for all UNIX users (Linux, macOS, etc.), type:
122 |
123 | sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl
124 | sudo chmod a+rx /usr/local/bin/youtube-dl
125 |
126 | If you do not have curl, you can alternatively use a recent wget:
127 |
128 | sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl
129 | sudo chmod a+rx /usr/local/bin/youtube-dl
130 |
131 | It is very simple to use. Following are some example usages:
132 |
133 | ```bash
134 | # simplest example
135 | youtube-dl https://www.youtube.com/watch?v=Zuwa8zlfXSY
136 |
137 | # customize the filename of the output
138 | youtube-dl -o '%(title)s by %(uploader)s.%(ext)s' https://www.youtube.com/watch?v=Zuwa8zlfXSY
139 |
140 | # download from multiple urls
141 | youtube-dl
142 |
143 | # or use a file with list of urls
144 | youtube-dl -a url.txt
145 |
146 | ```
147 | If you are more interested, there are plenty of other options to be explored from [documentation page.](https://github.com/ytdl-org/youtube-dl)
148 |
149 | ## Monitering the temperature of your system
150 | "lm-sensors" is a set of tools to control and view sensors that may be present on your hardware. Included are several applications that run from the command line:
151 | - sensors: shows the current readings of all sensor chips.
152 | - sensord: daemon to periodically log sensor readings to syslog
153 | - fancontrol: calculates fan speeds from temperatures and sets the corresponding PWM outputs
154 | - pwmconfig: tests the PWM outputs of sensors and configures fancontrol
155 | - and more (see [lm-sensors documentation](https://wiki.archlinux.org/index.php/Lm_sensors) for details)`
156 |
157 | You can use it in the following way,
158 | ```
159 | ~$ sensors
160 |
161 | k8temp-pci-00c3
162 | Adapter: PCI adapter
163 | Core0 Temp: +59.0°C
164 | Core1 Temp: +58.0°C
165 | Core2 Temp: +60.0°C
166 | Core3 Temp: +55.0°C
167 |
168 | it8718-isa-0228
169 | Adapter: ISA adapter
170 | [...] # shortened
171 | ```
172 | ###To Free up memory cache and buffer
173 | sync; echo 1 > /proc/sys/vm/drop_caches
174 | sync; echo 2 > /proc/sys/vm/drop_caches
175 | sync; echo 3 > /proc/sys/vm/drop_caches
176 |
177 | ## Shutting down the machine
178 | - `shutdown -h now`
179 | -If you want to Shutdown the system and turn the power off immediately.
180 | - `shutdown -h +10`
181 | -If you want to Shutdown the system after 10 minutes.
182 | - `shutdown -r now`
183 | -If you want to Reboot the system using shutdown command.
184 |
185 |
186 | ## Moving between Directories
187 | - Exploring `cd`(change directory) command
188 |
189 | - `cd [directory_name]`
190 | - If you want to change directory to a particular directory,use this command. Eg: cd Documents
191 |
192 | - `cd dir/subdir/subsubdir`
193 | - If you want to move inside a directory from a directory,use this command. Eg: cd Documents/Hacktoberfest/linuxCommands
194 |
195 | - `cd /`
196 | - If you want to change directory to the root directory. Root directory is the first directory in your file system hierarchy.
197 |
198 | - `cd ~` or `cd`
199 | - If you want to change directory to the home directory.Generally known as $HOME,located at path /home//.
200 | Also, `cd` command can be used to do the same above operation.
201 |
202 | - `cd ..`
203 | - It is used to go one level back directory(i.e to parent directory of current directory).
204 |
205 | - `cd ../..`
206 | - It is used to go two levels back directory(i.e to parent's parent directory of current directory).
207 |
208 | - `cd -`
209 | - It is used to change back to the previous working directory. Eg: If `Documents` is present working directory and `Downloads` is previous working directory, this command takes you back to `Downloads` directory.
210 |
211 | - `cd "dir name"` or `cd dir\ name`
212 | - This command is used to navigate to a directory with white spaces.Instead of using double quotes we can use single quotes then also this command will work.Eg: `cd "linux commands"` or `cd linux\ commands` will move to 'linux commands' directory.
213 | ## Configure to mysql
214 | - 'mysql -u root -p'
215 | - enter the mysql password
216 |
217 | ## Import and Export database using cli
218 |
219 | ### Import
220 | `mysql -u root -p db-name < /path/to/databse/file.sql`
221 |
222 | ### Export
223 | `mysql -u root -p db-name > /path/to/new/database.sql`
224 |
225 | It will ask database password.
226 |
227 | ## Creating and Removing Directories
228 | * `mkdir` command is used for creating directories.
229 | - Creating a directory is pretty straightforward.
230 | `mkdir [dir-name]`
231 |
232 | - Creating a complete directory structure. (Non of the directories should already exist)
233 | `mkdir -p dir1/dir2/dir3`
234 | - Make `mkdir` emmit the details of operation.
235 | `mkdir -v [dir-name]`
236 |
237 | * `rmdir` command is used for removing empty directories.
238 | - Removing a directory is also pretty straightforward.
239 | `rmdir [dir-name]`
240 |
241 | - Make `rmdir` ignore non empty directories.
242 | BY default, the rmdir command throws an error if you try deleting a non-empty directory. However, if you want, you can suppress this behavior of rmdir using the `--ignore-fail-on-non-empty` option.
243 |
244 | `rmdir --ignore-fail-on-non-empty [dir-name]`
245 | - Remove parent directories along with the directory.
246 | `rmdir -p test/test-dir/`
247 |
248 | * `rm -r` command is used for removing non empty directories.
249 | - Removing a non empty directory is also pretty straightforward.
250 | `rm -r [dir-name]`
251 | This will present a prompt for approval to delete each of the files.
252 |
253 | - If you don't want such a prompt,
254 | `rm -rf [dir-name]`
255 | This will not present a prompt for approval to delete each of the files.
256 |
257 | ## Compress files on linux
258 |
259 | The following commands are used to compress files on linux. There are many ways to compress files in linux, the most common is **tar**
260 |
261 | * Compress
262 | - The following commands makes an archive named archive.tar containing file foo and bar present in the current directory.
263 | - ```tar -cf archive.tar foo bar```
264 | - This command lists all the files in an archive verbosely.
265 | - ```tar -tvf archive.tar```
266 | - The `tar` utility has many options which can be seen using
267 | - ```tar --help```
268 | * Decompress
269 | - We will again use the `tar` utility to decompress files. The following command is used to decompress the file named `yourfile.tar.gz`. This command is for the `.gz.` extention.
270 | - ```tar -zxvf yourfile.tar.gz```
271 | - If the file has the extention `.tar`, this command can be used.
272 | - ```tar -xvf yourfile.tar```
273 | - The above commands will extract to the current folder, to extract to another folder use the following commands.
274 | - ```tar -C /myfolder -zxvf yourfile.tar.gz```
275 | - ```tar -C /myfolder -xvf yourfile.tar```
276 |
277 | ## Creating users on linux
278 |
279 | The following commands are used to create users on linux. One method allows you to create a user at a time while another
280 | allows you to create users in bulk
281 |
282 | * Single User
283 | - The following command creates a new user account without any additional actions
284 | - ```useradd joe```
285 | - The following command creates a new user account and creates a home directory for that user
286 | based on the contents of /etc/skel
287 | - ```useradd -m joe```
288 | - This command will create the user with the home directory you specify
289 | - ```useradd -d /path/to/home/dir joe```
290 | * Multiple Users
291 | - The following command creates users based on a `:` delimited list of values. Each user
292 | is separated by a new line
293 | - The user is defined as follows `username:encrypted-password:uid:gid:home-dir:shell`
294 | - Only the first two fields are required for user creation and the password must be encrypted
295 | using the below command
296 | - ```mkpasswd --method=SHA-512```
297 | - You can leave the user without a password by placing an `x` in place of the encrypted
298 | password.
299 | - Once you set up your file create your users by typing
300 | - ```newusers the-file```
301 |
302 | ## Modifying users on linux
303 | - ```usermod -L username``` - If you want to lockout a user
304 | - ```usermod -U username``` - If you need to unlock a users account locked with the above
305 | command
306 | - ```passwd username``` - If you need to change a users password
307 | - ```usermod -d /path/to/dir username``` - If you need to change a users home directory
308 | - ```usermod -s /path/to/shell username``` - If you need to change a users shell
309 |
310 | ## Deleting a user on linux
311 | - `userdel username` - Deletes user
312 | - `userdel -r username` - Deletes user and their home directory and mail spool file
313 |
314 |
315 | ## Basic Commands
316 |
317 | ### `htop`
318 |
319 | - The `htop` command is used get information about the system such as CPU usage, RAM usage, Swap usage etc. It also give information regarding the uptime, average load and currently running tasks.
320 | - To use this utility, simply type `htop` and press enter.
321 |
322 | Syntax:
323 |
324 | ```
325 | $ htop
326 | ```
327 |
328 | ### `wget`
329 |
330 | - The `wget` command is one of the simplist commands in linux. It allows the user to fetch internet resources without having to open a browser.
331 | - ***Basic Use:***
332 |
333 | Syntax:
334 |
335 | ```
336 | $ wget url
337 | ```
338 |
339 | Example:
340 |
341 | - Suppose we want to download a cat photo stored on say `https://example.com/cat.png'. To do so, we'll use the following command.
342 | ```
343 | $ wget https://example.com/cat.png
344 | ```
345 | - This will download and save the file to the current directory with the name `cat.png`.
346 |
347 | ### `wc`
348 |
349 | - One of the most basic commands, `wc` allows the user to count the number of bytes, characters, words and lines of each given file or standard input and print the result.
350 |
351 | - ***Basic Use:***
352 |
353 | Syntax:
354 | ```bash
355 | $ wc filename # output: number_of_lines number_of_words number_of_characters /path/to/file
356 | ```
357 |
358 | Example:
359 | ```bash
360 | $ wc /proc/cpuinfo # output: 208 1232 6336 /proc/cpuinfo
361 | ```
362 |
363 | ### `touch`
364 |
365 | - `touch` is a simple command that allows the user to create an empty file. Note that with `touch`, you can only create the file and not edit it.
366 |
367 | - ***Basic Use:***
368 |
369 | Syntax:
370 | ```bash
371 | $ touch filename
372 | $ ls -l filename
373 | -rw-rw-rw- 1 current_user users 0 Oct 9 22:03 filename
374 | ```
375 |
376 | Example:
377 | Logged in as user ***linux_is_awesome***
378 | ```bash
379 | $ touch hello
380 | $ ls -l hello
381 | -rw-rw-rw- 1 linux_is_awesome users 0 Oct 9 22:03 hello
382 | ```
383 |
384 | ### `whoami`
385 |
386 | - `whoami` command displays the username of the current user.
387 |
388 | - ***Basic Use:***
389 |
390 | Syntax:
391 | ```bash
392 | $ whoami
393 | current_user
394 | ```
395 |
396 | Example:
397 | Logged in as user ***linux_is_awesome***
398 | ```bash
399 | $ whoami
400 | linux_is_awesome
401 | ```
402 |
403 | ### `grep`
404 | - `grep` is an extremely useful command to know in Linux.
405 | - It stands for “global regular expression print". Basically, it's used for pattern matching. `grep` processes text line by line and prints any lines which match a specified pattern.
406 |
407 | - ***Basic Use:***
408 | Syntax:
409 | ```bash
410 | $ grep [option(s)] pattern [file(s)]
411 | ``` Creating a test file for using `grep`:
412 | ```bash
413 | $ cat > grep_test.txt
414 | This is a test file. AAA, BBB, 123, CaSe ExAmPle.
415 | ```
416 |
417 | Example:
418 | ```bash
419 | $ grep AAA grep_test.txt
420 | This is a test file. AAA, BBB, 123, CaSe ExAmPle. # AAA will be highlighted in the output
421 |
422 | $ grep -i case grep_test.txt # ignore case while searching
423 | This is a test file. AAA, BBB, 123, CaSe ExAmPle. # CaSe will be highlighted in the output
424 | ```
425 | ### TO CHECK DISK SPACE USED AND AVAILAVBLE
426 | - COMMANDS
427 | $df (Table that lists for each device name on the system)
428 | $df -h (To see output in Human Readable Format)
429 | $df -m (Output in one-megabyte)
430 | $df -k (Output in one-kilobyte blocks)
431 |
432 | ### TO CHECK DISK SPACE USED BY SPECIFIED FILES AND FOR EACH SUB-DIRECTORY
433 | -COMMANDS
434 | $du (Names and space consumption of each of the directories including all subdirectories)
435 | $du -h (To see output in Human Readable Format)
436 |
437 | To find out /etc/ directory space usage :
438 | $du /etc/
439 | $du -h /etc/
440 |
441 | ### `echo`
442 |
443 | - `echo` display a line of text.
444 |
445 | - ***Basic Use:***
446 | Syntax:
447 | ```bash
448 | $ echo options string
449 | $ echo "hello world"
450 | hello worl
451 | ```
452 | Example:
453 | ```bash
454 | $ echo $USER
455 | carlan
456 | $ echo $HOME
457 | /home/carlan
458 | $ forename=carlan
459 | $ echo "${forename}"
460 | carlan
461 | $ echo -e "hello\nworld"
462 | hello
463 | world
464 | $ echo '${forename}'
465 | ${forename}
466 | $ echo "This is my home folder ${HOME}" > /tmp/myhomefolder.txt
467 | $ cat /tmp/myhomefolder.txt
468 | This is my home folder /home/carlan
469 | ```
470 |
471 |
472 |
473 | ### `diff`
474 | - `diff` is an extremely useful command to know in Linux and often used in GIT as well as `git diff`.
475 | - Compare FILES line by line
476 |
477 | - ***Basic Use:***
478 | Syntax: diff [OPTION]... FILES
479 | ```bash
480 | $ cat > diff_test_file1.txt
481 | This is a test file 1
482 | $ cat > diff_test_file2.txt
483 | This is a test file 2
484 | ```
485 | Example:
486 | ```bash
487 | $ diff diff_test_file1.txt diff_test_file2.txt
488 | 1c1
489 | < This is a test file 1
490 | ---
491 | > This is a test file 2
492 | ```
493 |
494 | ### `printf`
495 |
496 | `printf` command in Linux is used to display the given string, number or any other format specifier on the terminal window.
497 |
498 | It's just like echo, but on steroids.
499 |
500 | #### Syntax:
501 |
502 | `printf [-v var] format [arguments]`
503 |
504 | `Printf` can have format specifiers, escape sequences or ordinary characters.
505 |
506 | #### commonly used `printf` specifiers:
507 |
508 | | specifiers | Description |
509 | |------------|-------------|
510 | | `%s` | a string specifier for string output |
511 | | `%d` | an integer specifier for showing the integral values |
512 |
513 | #### Example:
514 |
515 | ```sh
516 | printf "%s" "Hello, World!"
517 | # > Hello, World!
518 | ```
519 |
520 | ```sh
521 | printf "%d\n" "213" "109"
522 | # > 213
523 | # > 109
524 | ```
525 |
526 | ### `tee`
527 | ```tee``` command reads the standard input and writes it to both the standard output and one or more files.
528 |
529 | It basically breaks the output of a program so that it can be both displayed and saved in a file, simultaneously
530 |
531 | ### Syntax:
532 |
533 | ```tee [OPTION]... [FILE]...```
534 |
535 | The most useful option is probably the ```-a``` switch, which appends to the specified files rather than overwriting them. ```tee``` also creates the files if they don't exist.
536 |
537 | ### Example:
538 |
539 | ```bash
540 | printf "Hello World" >> a.txt
541 | # Creates file a.txt (assuming it wasn't there) with content "Hello World"
542 | touch b.txt
543 | #Creates b.txt
544 | wc -w a.txt|tee -a b.txt
545 | # Output: 2 a.txt
546 | cat b.txt
547 | # Output: 2 a.txt
548 | #Run it again
549 | wc -w a.txt|tee -a b.txt
550 | # Output: 2 a.txt
551 | cat b.txt
552 | # Output: 2 a.txt (on 2 lines)
553 | ```
554 |
555 | **Multiple file example**:
556 |
557 | ```bash
558 | # Follow steps of previous example first
559 | touch c.txt
560 | wc -w a.txt|tee -a b.txt c.txt
561 | # Output: 2 a.txt
562 | cat b.txt
563 | # Output: 2 a.txt (on 3 lines)
564 | cat c.txt
565 | cat b.txt
566 | # Output: 2 a.txt
567 | ```
568 | ### `ssh`
569 | ```ssh``` command can be used for accessing remote server (remote login program)
570 |
571 |
572 | ### Syntax:
573 | ```ssh username@serverip```
574 |
575 | This command connects you to a server which has an IP address as `serverip` and username as `username`.
576 |
577 | :fire: For complete info hit `man ssh` in terminal
578 | ______
579 |
580 | ### `screen`
581 |
582 | ```screen``` -- a full-screen software program that can be used to multiplexes a physical console between several processes (typically interactive shells). It offers a user to open several separate terminal instances inside a one single terminal window manager.
583 |
584 | + Prerequisites
585 |
586 | ```bash
587 | apt-get install screen (On Debian based Systems)
588 | ```
589 | or
590 |
591 | ```bash
592 | yum install screen (On RedHat based Systems)
593 | ```
594 |
595 | ### ex: Create a screen
596 |
597 | `$ screen -S [NAME_of_screen]`
598 |
599 | + e.g `screen -S frodo`
600 |
601 | ### ex: Detach a screen (when already inside screen interactive shell)
602 |
603 | `press Ctrl-A and 'D'`
604 |
605 | you will see the output like this:
606 |
607 | `[detached from 711.frodo]`
608 |
609 | ### ex: List of current screen sessions
610 |
611 | `$ screen -ls`
612 |
613 | ```bash
614 | @ubuntu ~ $ screen -ls
615 | There are screens on:
616 | 711.frodo (10/01/2016 01:15:45 AM) (Detached)
617 | 2231.pts-0.ubuntu (06/06/2015 08:12:05 AM) (Detached)
618 | 2 Sockets in /var/run/screen/S-nightz
619 |
620 | ```
621 |
622 | ### ex: restore screen (e.g 711.frodo) to continue your works
623 |
624 | `$ screen -r 711`
625 |
626 |
627 | ### ex: Kill screen (when already inside screen interactive shell)
628 |
629 | `press Ctrl-A and 'k'`
630 |
631 | then the terminated prompt will be appeared as:
632 |
633 | ```bash
634 | Want to kill this window [Y/N] >
635 | ```
636 | _________________
637 |
638 | ### strace
639 |
640 | ```strace``` -- powerful command line tool for debugging and trouble shooting programs in Unix-like operating systems such as Linux. It captures and records all system calls made by a process and the signals received by the process
641 |
642 | - ```strace``` will fill your screen with continues output that shows system calls being made by the process, to end it, press **[Ctrl + C]**
643 |
644 | ### ex: trace Linux Command System Calls
645 |
646 | + e.g: tracing of all system calls made by the **`df`** command
647 |
648 | ```bash
649 | $ strace df -h
650 |
651 |
652 | execve("/bin/df", ["df", "-h"], [/* 50 vars */]) = 0
653 | brk(NULL) = 0x136e000
654 | access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
655 | mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f82f78fd000
656 | access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
657 | open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
658 | fstat(3, {st_mode=S_IFREG|0644, st_size=147662, ...}) = 0
659 | mmap(NULL, 147662, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f82f78d8000
660 | close(3) = 0
661 | access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
662 |
663 | ```
664 |
665 | #### Where:
666 |
667 | + **access** -- one of types of system call
668 | + **("/etc/ld.so.preload", R_OK)** -- system call argument
669 | + **-1 ENOENT** -- system call return value
670 |
671 | ### ex: trace Linux Process PID
672 |
673 | ```bash
674 | $ sudo strace -p [PID]
675 |
676 | example
677 |
678 | $ sudo strace -p 3569
679 |
680 | strace: Process 3569 attached
681 | restart_syscall(<... resuming interrupted poll ...>) = 1
682 | recvmsg(4, {msg_name(0)=NULL, msg_iov(1)=[{"U0!70
683 |
684 | ```
685 | _________________
686 |
687 | ## Network
688 |
689 | ### `ifconfig`
690 |
691 | - Used to configure network interface parameters and displays information about all network interfaces currently in operation.
692 |
693 | - `ifconfig -a`
694 | - Print out the configuration of all network interfaces on the system.
695 |
696 | - `ifconfig interface`
697 | - Print out the configuration of a specific interface.
698 |
699 | ### ex: ifconfig interface
700 | ```example
701 |
702 | $ ifconfig eth0
703 | ```
704 |
705 | - `sudo ifconfig interface up`
706 | - Enable an interface if it is disabled.
707 |
708 | ### ex: Enabling an interface
709 | ```
710 | example
711 |
712 | $ sudo ifconfig eth0 up
713 | ```
714 |
715 | - `sudo ifconfig interface down`
716 | - Disable an interface if it is enabled.
717 |
718 | ### ex: Disabling an interface
719 | ```
720 | example
721 |
722 | $ sudo ifconfig eth0 down
723 | ```
724 |
725 | ### `ping`
726 |
727 | - It is used to test the connectivity status between a source and destination computer/device over an IP network.
728 |
729 | ### ex: use ping
730 | ```bash
731 | $ ping ip
732 |
733 | example
734 |
735 | $ ping 192.168.1.254
736 | ```
737 |
738 | ### `whois`
739 |
740 | - whois is a simple tool that allows you to see information about a specific domain name or IP address. You can use it to see things like contact information, nameservers, and domain registration information.
741 |
742 | ### ex: install whois
743 | ```
744 | $ sudo apt install whois
745 | ```
746 |
747 | ### ex: use whois
748 | ```bash
749 | $ whois domain
750 |
751 | example
752 |
753 | $ whois www.github.com
754 | ```
755 |
756 | ### `netstat`
757 |
758 | - Netstat command allows you a simple way to review each of your network connections and open sockets.
759 |
760 | - `netstat -a`
761 | - List out all the current connections
762 |
763 | - `netstat -at`
764 | - List only TCP connections
765 |
766 | - `netstat -au`
767 | - List only UDP connections
768 |
769 | - `netstat -an`
770 | - Disable reverse dns lookup for faster output if you do not need to know the host name and just the ip address.
771 |
772 | - `netstat -s`
773 | - Print out network statistics like total number of packets received and transmitted by protocol type and so on.
774 |
775 | - `netstat -i`
776 | - Print out the information about the network interfaces.
777 |
778 | - `netstat -g`
779 | - Display the multicast group information for IPv4 and IPv6 protocols.
780 |
781 | ### `w`
782 |
783 | - w provides a quick summary of every user logged into a computer, what each user is currently doing, and what load all the activity is imposing on the computer itself.
784 |
785 | ### ex: using w
786 | ```
787 | example
788 |
789 | $ w
790 | ```
791 | ### ssh
792 | - SSH stands for secure shell. To login in to a system with user name `user` and `ip-10.85.85.85`,type:
793 | ```ssh user@10.85.85.85```
794 | - This shall allow you to access the terminal of the remote PC with the user account of ```user```
795 |
796 | ### ssh-keygen(Generation and Usage)
797 | - Inorder to avoid entering the password to remote servers/applications.
798 | - While ```git push```, we can avoid this scenario by adding a key to our GitHub.
799 | - Steps:
800 | ``` Scenario 1 using the existing key```
801 | 1. Check for existing keys.
802 | ```ls ~/.ssh```
803 | eg: default names:``` id_rsa.pub ``` ``` id_rsa ``
804 | Here id_rsa is the private key.
805 | Files ending with the .pub are the public key which is to be added to the ```authorized_keys`` on remote servers.
806 | For GitHub, go to Settings click on SSH and GPG keys
807 | 2. Choose SSH-keys, give it a name and the .pub file.
808 | ``` cat ~/.ssh/id_rsa.pub ``` copy and paste this to the key section.
809 |
810 | ``` Scenario 2 creating a new key ```
811 | 1. Using ssh-keygen we will create keys.
812 | ``` ssh-keygen -t rsa -b 4096 ```
813 | t-flag: for choosing encryption methods such as RSA,DSA,ECDSA.
814 | b-flag: for choosing no. of bits.
815 | with help of man command you can know more about ssh-keygen.
816 | 2. It will prompt for the name and location for the keys:
817 | default: ```/home/[user]/.ssh/id_rsa```
818 | You can choose this, if there is an existing key it will overwrite it.
819 | 3. Pick a relevant name: ```/home/[user]/.ssh/id_rsa_[github|Server A]```
820 | 4. It will ask for passphrase, you can avoid this or enter passphrase which will be asked whenever your using this key. Enter the same passphrase again to confirm it.
821 | 5. Thus you have created the keys(public and private). Sometimes you have to add the generated private key to cache by using ```ssh-add ~/.ssh/[filename]```
822 | 6. Copy the public key using cat command.
823 | eg:``` cat ~/.ssh/[file_name.pub] ```
824 | 7. Add this key to GitHub, by going to Settings and then click on SSH and GPG keys, give a name and paste it.
825 |
826 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 iamshm
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Linux/Unix Commands
2 | Operating Linux becomes easy if you know the right commands
3 |
4 |
5 | 
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | A community-built repository which includes most of the basic command lines.
15 |
16 |
17 |
18 | ## What is this repository for?
19 |
20 | This is list of many useful basic linux command lines.
21 |
22 | ## Who can contribute for this repository?
23 |
24 | Anyone. Absolutely anyone can contribute to this repository. Please check the rules below before you make pull requests.
25 |
26 | # CONTRIBUTION
27 |
28 | ## How to contribute?
29 |
30 | - Add an issue to this repository stating the use of that command line.
31 | - Fork this repository and give a star.
32 | - Try to provide examples for that command line.
33 | - Once go through the raw file of `Commands.md` to get the gist of formatting required.
34 | - Add it to the`Commands.md` file.
35 | - Create a Pull request
36 | - Feel free to improve the README.md
37 |
38 | ## Rules
39 | ### Please follow format used in `Commands.md`
40 | - Please do not spam pull request for the sake of Hacktoberfest.
41 | - No duplicate entries. Please check if the command is existing before you submit.
42 | - Star this repository to show appreciation towards public efforts.
43 |
--------------------------------------------------------------------------------