· 8 years ago · Feb 18, 2018, 01:20 AM
1LINUX
2
3FILE AND DIRECTORY COMMANDS
4# List all files in a long listing (detailed) format
5ls -al
6
7# List all files by name only
8ls
9
10# Display the present working directory
11pwd
12
13# Create a directory
14mkdir directory_name
15
16# Remove (delete) file
17rm file
18
19# Remove the directory and its contents recursively
20rm -r directory_name
21
22# Force removal of file
23rm -f file_name
24
25# Forcefully remove directory recursively
26rm -rf directory_name
27
28# Copy file1 to file2
29cp file1 file2
30
31# Copy source_directory recursively to destination. If destination exists, copy source_directory into destination,
32otherwise create destination with the contents of source_directory.
33cp -r source_directory destination
34
35# Rename or move file1 to file2. If file2 is an existing directory, move file1 into directory file2
36mv file1 file2
37
38# Create symbolic link to linkname
39ln -s /path/to/file linkname
40
41# Create an empty file.
42touch file
43
44# View the contents of file
45cat file
46
47#can run last command with sudo using
48sudo !!
49# can exit root from
50 su <user_name> ==> su supuni
51
52# Display the last 10 lines of file and "follow" the file as it grows.
53tail -f file
54example----
55tail -f prod.log ==> can view all logs
56tail -1000 prod.log ==> show last 1000 lines
57tail -1000 prod.log | grep CRITICAL (show only critical errors)
58
59#Remove process from always start when computer on
60#show all the upladed processes
61ls /etc/init.d/
62
63#remove it by
64sudo update-rc.d -f <process_name>.remove
65
66# start services and stop
67service <process_name> stop
68service <process_name> start
69-------------------------------------------------------------------------------
70PROCESS MANAGEMENT
71# Display your currently running processes
72ps
73
74# Display all the currently running processes on the system.
75ps aux
76
77# Display process information for processname
78ps aux | grep processname
79
80# Display cpu usage memory usage
81top
82
83# Kill process with process ID of pid
84kill pid
85
86
87INSTALL PROGRAMS TO UBUNTU SYSTEM
88
89#Update latest versions
90 npm install npm@latest -g
91
92#install vim
93yum install vim
94
95#adb install
96sudo apt-get install adb
97
98#install react-native
99sudo apt-get install react-native
100
101#How to repair ubuntu selection
102
1031. verify that secure-boot disabled
1042.Insert Ubuntu CD and try with Ubuntu cd
1053.open terminal
1064.sudo apt-add-repository ppa:yannubuntu/boot-repair
1075.sudo apt-get update
1086.sudo apt-get install -y boot-repair
1097.boot-repair
110
111--------------------------------------------------------------------
112 SSH LOGINS
113
114# Connect to host as user
115ssh user@host
116
117# Normal Method
118ssh -i <path to file> user@host_name
119ssh -i .ssh/id_rsa.pub ubuntu@siplo.lk
120-------------------------------------------------------------------------------
121
122FILE TRANSFERS
123# Secure copy file.txt to the /tmp folder on server
124scp file.txt server:/tmp
125
126# Copy *.html files from server to the local /tmp folder.
127scp server:/var/www/* .html /tmp
128 scp root@192.168.8.125:/usr/share/freeswitch/conf/vanilla/vars.xml /home/pi/
129local machine to server
130 scp /home/supuni/ubuntu/jitsi-images/ meetrix:/home/ubuntu
131
132# Copy all files and directories recursively from server to the current system's /tmp folder.
133scp -r server:/var/www /tmp
134-------------------------------------------------------------------------------
135
136DIRECTORY NAVIGATION
137# To go up one level of the directory tree.
138cd ..
139
140# Go to the $HOME directory
141cd
142
143# Change to the /etc directory
144cd /etc
145-------------------------------------------------------------------------------------------
146SYSTEM INFORMATION
147
148# Show the current date and time
149date
150
151# Show this month's calendar
152cal
153
154# Display USB devices
155lsusb -tv
156-----------------------------------------------------------------------------------
157 FILE PERMISSIONS
158
159
160 PERMISSION EXAMPLE
161
162 U G W
163 rwx rwx rwx chmod 777 filename
164 rwx rwx r-x chmod 775 filename
165 rwx r-x r-x chmod 755 filename
166 rw- rw- r-- chmod 664 filename
167 rw- r-- r-- chmod 644 filename
168
169# NOTE: Use 777 sparingly!
170
171 LEGEND
172 U = User
173 G = Group
174 W = World
175
176 r = Read
177 w = write
178 x = execute
179 - = no access
180----------------------------------------------------------------------------------
181NETWORKING
182
183# Display all network interfaces and ip address
184ifconfig -a
185
186# Send ICMP echo request to host
187ping ip_address
188
189-----------------------------------------------------------------------------------
190ARCHIEVES
191
192#Compress an Entire Directory or a Single File
193tar -czvf name-of-archive.tar.gz /path/to/directory-or-file
194 tar -cvf /tmp/freeswitch_conf.tar /etc/freeswitch
195
196- c: Create an archive.
197-z: Compress the archive with gzip.
198-v: Display progress in the terminal while creating the archive, also known as “verbose†mode. The v is always optional in these commands, but it’s helpful.
199-f: Allows you to specify the filename of the archive.
200
201#Extract an Archive
202tar -xzvf archive.tar.gz -C /tmp
203 tar -xvf /tmp/freeswitch_conf.tar /etc/freeswitch
204-----------------------------------------------------------------------------------
205SEARCH
206
207# Search for pattern in file
208grep pattern file
209
210# Search recursively for pattern in directory
211grep -r pattern directory
212
213# Find files and directories by name
214locate name
215
216# Find files in /home/john that start with "prefix".
217find /home/john -name 'prefix*'
218
219# Find files larger than 100MB in /home
220find /home -size +100M
221-------------------------------------------------------------------------------------------------------
222DISK USAGE
223
224# Show free and used space on mounted filesystems
225df -h
226
227# Display disks partitions sizes and types
228fdisk -l
229
230#can view image sizes
231identify <jpg_name>.jpg
232
233ImageMagick is a suite of command-line utilities for resizing, converting
234
235convert howtogeek.png howtogeek.jpg //converting between format
236convert howtogeek.png -quality 95 howtogeek.jpg //specify compression level
237convert example.png -resize 200x100 example.png //resize image
238convert example.png -resize 200x100! example.png // not considering ratio
239convert example.png -resize 200 example.png // consider only width
240convert example.png -resize x100 example.png // consider only height
241convert howtogeek.jpg -rotate 90 howtogeek-rotated.jpg // rotate image
242
243------------------------------------------------------------------------------------------------------------
244MYSQL
2451. Log into mysql:
246 mysql -u [username] -p;(will prompt for password)
247
248 data types (INTEGER,FLOAT, DECIMAL(i, j), CHAR(n), VARCHAR(n))
249 DATE:
250 • Made up of year-month-day in the format yyyy-mm-dd
251 TIME:
252 • Made up of hour:minute:second in the format hh:mm:ss
253 TIME(i):
254 • Made up of hour:minute:second plus i additional digits specifying fractions of a second
255 • format is hh:mm:ss:ii...i
256 TIMESTAMP:
257 • Has both DATE and TIME components
258
2592. Show all databases:
260 SHOW DATABASES;
261
2623. Access database:
263 mysql -u [username] -p [database](will prompt for password)
264
2654. Create new database:
266 CREATE DATABASE [database_name];
267 An error occurs if database exists, Check if the database is existing
268 DROP DATABASE IF EXISTS [database_name];
269 CREATE DATABASE [database_name];
270
271 CREATE DATABASE IF NOT EXISTS Department;
272
2735. Select database:
274 USE [database_name];
275
2766. Determine what database is in use:
277 SELECT DATABASE();
278
2797. Show all tables:
280 SHOW TABLES;
281
2828. Show table structure:
283 DESCRIBE [table_name];
284
2859. List all indexes on a table:
286 show index from [table];
287
28810. Create new table with columns:
289 CREATE TABLE DEPARTMENT
290 ( DNAME VARCHAR(10) NOT NULL,
291 DNUMBER INTEGER NOT NULL,
292 MGRSSN CHAR(9),
293 MGRSTARTDATE CHAR(9) );
294
29511. Adding a column:
296 ALTER TABLE EMPLOYEE ADD JOB VARCHAR(12);
297 The new attribute will have NULLs in all the tuples of the relation right after the command is executed; hence, the
298 NOT NULL constraint is not allowed for such an attribute
299
30012. Adding a column with an unique, auto-incrementing ID:
301 ALTER TABLE [table] ADD COLUMN [column] int NOT NULL AUTO_INCREMENT PRIMARY KEY;
302
30313. Inserting a record:
304 (Insert a tuple for a new EMPLOYEE for whom we only know the FNAME, LNAME, and SSN attributes)
305 INSERT INTO EMPLOYEE (FNAME, LNAME, SSN)
306 VALUES ('Richard', 'Marini', '653298653')
307
308 (Attribute values should be listed in the same order)
309 INSERT INTO EMPLOYEE
310 VALUES ('Richard','K','Marini', '653298653','30-DEC-92', '98 Oak Forest, Katy,TX', 'M',37000,'987654321', 4);
311
31214. MySQL function for datetime input:
313 NOW()
314
31515. Selecting records:
316 SELECT * FROM [table_name];
317
318 SELECT <attribute list>
319 FROM <table list>
320 WHERE <condition>
321
322 SELECT BDATE, ADDRESS
323 FROM EMPLOYEE
324 WHERE FNAME='John' AND MINIT='B’ AND LNAME='Smith'
325
32616. Explain records:
327 EXPLAIN SELECT * FROM [table];
328
32917. Selecting parts of records:
330 SELECT [column], [another-column] FROM [table];
331
33218. Counting records:
333 SELECT COUNT([column]) FROM [table];
334
33519. Counting and selecting grouped records:
336 SELECT *, (SELECT COUNT([column]) FROM [table]) AS count FROM [table] GROUP BY [column];
337
33820. Selecting specific records:
339 SELECT * FROM [table] WHERE [column] = [value]; (Selectors: <, >, !=; combine multiple selectors with AND, OR)
340
34121. Select records containing [value]:
342 SELECT * FROM [table] WHERE [column] LIKE '%[value]%';
343
34422. Select records starting with [value]:
345 SELECT * FROM [table] WHERE [column] LIKE '[value]%';
346
34723. Select records starting with val and ending with ue:
348 SELECT * FROM [table] WHERE [column] LIKE '[val_ue]';
349
35024. Select a range:
351 SELECT * FROM [table] WHERE [column] BETWEEN [value1] and [value2];
352
35325. Select with custom order and only limit:
354 SELECT * FROM [table] WHERE [column] ORDER BY [column] ASC LIMIT [value]; (Order: DESC, ASC)
355
35626. Updating records:
357 UPDATE [table] SET [column] = '[updated-value]' WHERE [column] = [value];
358
359 UPDATE PROJECT
360 SET PLOCATION = ‘Galle', DNUM = 5
361 WHERE PNUMBER=10
362
36327. Deleting records:
364 DELETE FROM [table] WHERE [column] = [value];
365
36628. Delete all records from a table (without dropping the table itself):
367 DELETE FROM [table];Â (This also resets the incrementing counter for auto generated columns like an id column.)
368
36929. Delete all records without deleting schema in a table:
370 truncate table [table];
371
37230. Removing table columns:
373 ALTER TABLE [table] DROP COLUMN [column];
374
37531. Deleting tables:
376 DROP TABLE [table];
377
37832. Deleting databases:
379 DROP DATABASE [database];
380
38133. Custom column output names:
382 SELECT [column] AS [custom-column] FROM [table];
383
38434. Export a database dump :
385 mysqldump -u [username] -p [database] > db_backup.sql
386
38735. Use --lock-tables=false option for locked tables.
388
38936. Import a database dump:
390 mysql -u [username] -p -h localhost [database] < db_backup.sql
391
39237. Logout: exit;
393
39438. To eliminate duplicate tuples in a query result
395 SELECT DISTINCT SALARY
396 FROM EMPLOYEE
397-----------------------------------------------------------------------------------------
398Aggregate functions
399
4001. Select but without duplicates:
401 SELECT distinct name, email, acception FROM owners WHERE acception = 1 AND date >= 2015-01-01 00:00:00
402
4032. Calculate total number of records:
404 SELECT SUM([column]) FROM [table];
405
4063. Count total number of [column] and group by [category-column]:
407 SELECT [category-column], SUM([column]) FROM [table] GROUP BY [category-column];
408
4094. Get largest value in [column]:
410 SELECT MAX([column]) FROM [table];
411
4125. Get smallest value:
413 SELECT MIN([column]) FROM [table];
414
4156. Get average value:
416 SELECT AVG([column]) FROM [table];
417
4187. Get rounded average value and group by [category-column]:
419 SELECT [category-column], ROUND(AVG([column]), 2) FROM [table] GROUP BY [category-column];
420
421-----------------------------------------------------------------------------------------------
422Users functions
423
4241. List all users:
425 SELECT User,Host FROM mysql.user;
426
4272. Create new user:
428 CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
429
4303. Grant ALL access to user for * tables:
431 GRANT ALL ON database.* TO 'user'@'localhost';
432
433-----------------------------------------------------------------------------------------------
434MySQL Mathematical Functions
435
4361. Count rows per group COUNT(column | *)
437
4382. Average value of group AVG(column)
439
4403. Minumum value of group MIN(column)
441
4424. Maximum value of group MAX(column)
443
4445. Sum values in a group SUM(column)
445
4466. Absolute value abs(number)
447
4487. Rounding numbers round(number)
449
4508. Largest integer not greater floor(number)
451
4529. Smallest integer not smaller ceiling(number)
453
45410. Square root sqrt(number)
455
45611. nth power pow(base,exponent)
457
45812. random number n, 0<n < 1 rand()
459
46013. sin (similar cos, etc.) sin(number)
461
462------------------------------------------------------------------------------------
463MySQL String Functions
464
4651. Compare strings strcmp(string1,string2)
466
4672. Convert to lower case lower(string)
468
4693. Convert to upper case upper(string)
470
4714. Left-trim whitespace (similar right) ltrim(string)
472
4735. Substring of string substring(string,index1,index2)
474
4756. Encrypt password password(string)
476
4777. Encode string encode(string,key)
478
4798. Decode string decode(string,key)
480
4819. Get date curdate()
482
48310. Get time curtime()
484
48511. Extract day name from date string dayname(string)
486
48712. Extract day number from date string dayofweek(string)
488
48913.Extract month from date string monthname(string)
490
491-----------------------------------------------------------------------------------
492
493#reset root password
494
495sudo /etc/init.d/mysql stop
496sudo mysqld_safe --skip-grant-tables &
497mysql -u root
498mysql> use mysql;
499mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
500mysql> flush privileges;
501mysql> quit
502
503sudo /etc/init.d/mysql stop
504sudo /etc/init.d/mysql start
505
506---------------------------------------------------------------------------------------------------------------
507
508GITHUB
5091.Adding an existing project to GitHub using the command line
510
5111.Create a new repository on GitHub
5122.Open Terminal
5133.Change the current working directory to your local project.
5144.git init
5155.git add .
5166.git commit -m "First commit"
5177.At the top of your GitHub repository's Quick Setup page, click to copy the remote repository URL.
5188.git remote add origin <remote_repository_URL>
519
520----------------------------------------------------------------------------------------------------
521
5222.Changing a remote's URL
523
524git remote -v
525git remote set-url origin <git_url>
526git remote -v // Verify new remote URL
527
528---------------------------------------------------------------------------------------------------
529
5303. Everyday Use
531
5321. shows you which files have been modified since the last commit
533 $ git status
534
5352. $ git add <filename>
536( if the file is untracked and you wish to add it to the project,
537 git-add does it automatically for you.)
538
5393. creates the new commit
540 $ git commit -m "commit_msg"
541
5424. can stored particular branch
543 $ git push origin <branch_name>
544
5455. getting the changes from the remote server, and merging them
546 into the local tree.
547 $ git pull
548 (If conflicts occured should resolved, can view by git diff
549 add file and again commit that file)
550
5516. reviewing history
552 $ git log
553
5547. show commit content
555 $ git show <commit_number>
556----------------------------------------------------------------------------------------------------
557git branch
558
5591. create a new branch
560 git branch <branch_name>
561
5622. checkout another branch
563 git checkout <branch_name>
564
5653.to delete a branch run from master branch
566 git branch -d <branch_name>
567
5684. merge branches run from master branch
569 git merge <branch_name>
570
571------------------------------------------------------------------------------------------------
572Revert a commit
573
574
575
576SYMFONY
577
578
579Composer
580
5811. Update all dependencies of current project
582composer update
583
5842. Install dependencies for current project with versions defined in composer.lock
585composer install
586
587----------------------------------------------------------------------------------
588Console
589
5901. List available commands and show the Symfony version
591php app/console
592
5932. Display help for given command
594php app/console help [command]
595
5963. Display all configured public services
597php app/console container:debug [--show-private] [service_name]
598
5994. Dump all assets to the filesystem
600php app/console assetic:dump
601
6025. doctrine:schema:update
603Update the database with its new schema. Use with --dump-sql and --force
604
605
606-----------------------------------------------------------------------------------
607Cache
608
609Clear the cached information
610php app/console cache:clear
611
612In Server
613php app/console cache:clear --env=prod
614
615(After clearing cache should set permission to execute following files)
616sudo chmod 777 -R app/logs app/cache
617
618-----------------------------------------------------------------------------------
619Bundle
620
621Install bundles web assets under a public web directory
622php app/console assets:install <target_dir> [--symlink] [--relative]
623
624-----------------------------------------------------------------------------------
625Routing
626
627Display current routes for application
628php app/console router:debug | grep [router_name]
629
630-----------------------------------------------------------------------------------
631Logger
632
633$logger = $this->get('logger');
634$logger->debug("===================================================================");
635
636
637JITSI
638
639JItsi locally setup in your computer---------------
640
6411.git clone <the link>
642
6432.sudo n lts (take the long term support version)
644
6453.npm install
646
6474.make
648
6495 ./node_modules/.bin/webpack-dev-server // start the server
650
6516. ./node_modules/.bin/node-sass css/main.scss css/all.bundle.css && ./node_modules/.bin/cleancss css/all.bundle.css >
652css/all.css ; rm css/all.bundle.css // compile css
653
654
655PM2
656
657PM2 is a production process manager for Node.js applications with a built-in load balancer.
658It allows you to keep applications alive forever, to reload them without downtime and to facilitate
659common system admin tasks.
660
661Install pm2
662npm install pm2@latest -g
663
664# Fork mode
665pm2 start app.js --name my-api # Name process
666
667# Listing
668pm2 list # Display all processes status
669
670# Logs
671
672pm2 logs [--raw] # Display all processes logs in streaming
673pm2 flush # Empty all log files
674pm2 reloadLogs # Reload all logs
675
676# Actions
677
678pm2 stop all # Stop all processes
679pm2 restart all # Restart all processes
680
681pm2 reload all # Will 0s downtime reload (for NETWORKED apps)
682
683pm2 stop 0 # Stop specific process id
684pm2 restart 0 # Restart specific process id
685
686pm2 delete 0 # Will remove process from pm2 list
687pm2 delete all # Will remove all processes from pm2 list
688
689-----------------------------------------------------------------------------------------------------------------
690
691Add Another Mail Account To Gmail
692
693gmail → setting → Accounts and Import → Add another email adress
694smtp.zoho.com
695
696zoho → settings → configure IMAP → click IMAP check box
697verify and paste confirmation code
698----------------------------------------------------------------------------------------------------------------------------
699FREEESWITCH
700
701#Freeswitch terminal restart
702fs_cli restart
703
704#shutdown
705fs_cli -x “shutdownâ€
706
707#run freeswitch
7081. sudo su
7092. go to bin ==> cd /usr/local/freeswitch/bin
7103. ./freeswitch
711
712#Backing up and restoring your Raspberry pi’s SD card
713df -h ==> show all the available space
714again insert SD card and run ==> df -h
715 /dev/mmcblk0p1
716 /dev/mmcblk0p2
717
718then terminal
719sudo dd if =/dev/sdb of=~/SDCardBackup.img
720
721----------------------------------------------------------------------------------------------------------------------------
722Vim
723
724#Delete Multiple Lines
725shift + v ==> Go to visual mode
726Select necessary lines
727delete
728
729#Copy terminal output into file
7301. triple-click the last line
7312. hit shift + home
7323. shift + click first line
7334. copy ctrl +shift + c
734You can then paste the content to other text document
735
736NANO
737
738#exit with save
739Ctrl +X ---→ y --→ enter
740-----------------------------------------------------------------------------------------------------------------------------
741Angular2
742
7431. Create Component Using Terminal
744 ng generate component <component_name>
745
746
747----------------------------------------------------------------------------------------------------------------------------
748REACT-NATIVE
749
750#Run android project
751react-native start
752react-native run-android
753-----------------------------------------------------------------------------------------------------------------------------
754
755IMPORTANT WEB PAGES
756
757#Get know your screen resolution
758whatismyscreenresolution.net