Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LINUX
- FILE AND DIRECTORY COMMANDS
- # List all files in a long listing (detailed) format
- ls -al
- # List all files by name only
- ls
- # Display the present working directory
- pwd
- # Create a directory
- mkdir directory_name
- # Remove (delete) file
- rm file
- # Remove the directory and its contents recursively
- rm -r directory_name
- # Force removal of file
- rm -f file_name
- # Forcefully remove directory recursively
- rm -rf directory_name
- # Copy file1 to file2
- cp file1 file2
- # Copy source_directory recursively to destination. If destination exists, copy source_directory into destination,
- otherwise create destination with the contents of source_directory.
- cp -r source_directory destination
- # Rename or move file1 to file2. If file2 is an existing directory, move file1 into directory file2
- mv file1 file2
- # Create symbolic link to linkname
- ln -s /path/to/file linkname
- # Create an empty file.
- touch file
- # View the contents of file
- cat file
- #can run last command with sudo using
- sudo !!
- # can exit root from
- su <user_name> ==> su supuni
- # Display the last 10 lines of file and "follow" the file as it grows.
- tail -f file
- example----
- tail -f prod.log ==> can view all logs
- tail -1000 prod.log ==> show last 1000 lines
- tail -1000 prod.log | grep CRITICAL (show only critical errors)
- #Remove process from always start when computer on
- #show all the upladed processes
- ls /etc/init.d/
- #remove it by
- sudo update-rc.d -f <process_name>.remove
- # start services and stop
- service <process_name> stop
- service <process_name> start
- -------------------------------------------------------------------------------
- PROCESS MANAGEMENT
- # Display your currently running processes
- ps
- # Display all the currently running processes on the system.
- ps aux
- # Display process information for processname
- ps aux | grep processname
- # Display cpu usage memory usage
- top
- # Kill process with process ID of pid
- kill pid
- INSTALL PROGRAMS TO UBUNTU SYSTEM
- #Update latest versions
- npm install npm@latest -g
- #install vim
- yum install vim
- #adb install
- sudo apt-get install adb
- #install react-native
- sudo apt-get install react-native
- #How to repair ubuntu selection
- 1. verify that secure-boot disabled
- 2.Insert Ubuntu CD and try with Ubuntu cd
- 3.open terminal
- 4.sudo apt-add-repository ppa:yannubuntu/boot-repair
- 5.sudo apt-get update
- 6.sudo apt-get install -y boot-repair
- 7.boot-repair
- --------------------------------------------------------------------
- SSH LOGINS
- # Connect to host as user
- ssh user@host
- # Normal Method
- ssh -i <path to file> user@host_name
- ssh -i .ssh/id_rsa.pub ubuntu@siplo.lk
- -------------------------------------------------------------------------------
- FILE TRANSFERS
- # Secure copy file.txt to the /tmp folder on server
- scp file.txt server:/tmp
- # Copy *.html files from server to the local /tmp folder.
- scp server:/var/www/* .html /tmp
- scp root@192.168.8.125:/usr/share/freeswitch/conf/vanilla/vars.xml /home/pi/
- local machine to server
- scp /home/supuni/ubuntu/jitsi-images/ meetrix:/home/ubuntu
- # Copy all files and directories recursively from server to the current system's /tmp folder.
- scp -r server:/var/www /tmp
- -------------------------------------------------------------------------------
- DIRECTORY NAVIGATION
- # To go up one level of the directory tree.
- cd ..
- # Go to the $HOME directory
- cd
- # Change to the /etc directory
- cd /etc
- -------------------------------------------------------------------------------------------
- SYSTEM INFORMATION
- # Show the current date and time
- date
- # Show this month's calendar
- cal
- # Display USB devices
- lsusb -tv
- -----------------------------------------------------------------------------------
- FILE PERMISSIONS
- PERMISSION EXAMPLE
- U G W
- rwx rwx rwx chmod 777 filename
- rwx rwx r-x chmod 775 filename
- rwx r-x r-x chmod 755 filename
- rw- rw- r-- chmod 664 filename
- rw- r-- r-- chmod 644 filename
- # NOTE: Use 777 sparingly!
- LEGEND
- U = User
- G = Group
- W = World
- r = Read
- w = write
- x = execute
- - = no access
- ----------------------------------------------------------------------------------
- NETWORKING
- # Display all network interfaces and ip address
- ifconfig -a
- # Send ICMP echo request to host
- ping ip_address
- -----------------------------------------------------------------------------------
- ARCHIEVES
- #Compress an Entire Directory or a Single File
- tar -czvf name-of-archive.tar.gz /path/to/directory-or-file
- tar -cvf /tmp/freeswitch_conf.tar /etc/freeswitch
- - c: Create an archive.
- -z: Compress the archive with gzip.
- -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.
- -f: Allows you to specify the filename of the archive.
- #Extract an Archive
- tar -xzvf archive.tar.gz -C /tmp
- tar -xvf /tmp/freeswitch_conf.tar /etc/freeswitch
- -----------------------------------------------------------------------------------
- SEARCH
- # Search for pattern in file
- grep pattern file
- # Search recursively for pattern in directory
- grep -r pattern directory
- # Find files and directories by name
- locate name
- # Find files in /home/john that start with "prefix".
- find /home/john -name 'prefix*'
- # Find files larger than 100MB in /home
- find /home -size +100M
- -------------------------------------------------------------------------------------------------------
- DISK USAGE
- # Show free and used space on mounted filesystems
- df -h
- # Display disks partitions sizes and types
- fdisk -l
- #can view image sizes
- identify <jpg_name>.jpg
- ImageMagick is a suite of command-line utilities for resizing, converting
- convert howtogeek.png howtogeek.jpg //converting between format
- convert howtogeek.png -quality 95 howtogeek.jpg //specify compression level
- convert example.png -resize 200x100 example.png //resize image
- convert example.png -resize 200x100! example.png // not considering ratio
- convert example.png -resize 200 example.png // consider only width
- convert example.png -resize x100 example.png // consider only height
- convert howtogeek.jpg -rotate 90 howtogeek-rotated.jpg // rotate image
- ------------------------------------------------------------------------------------------------------------
- MYSQL
- 1. Log into mysql:
- mysql -u [username] -p;(will prompt for password)
- data types (INTEGER,FLOAT, DECIMAL(i, j), CHAR(n), VARCHAR(n))
- DATE:
- • Made up of year-month-day in the format yyyy-mm-dd
- TIME:
- • Made up of hour:minute:second in the format hh:mm:ss
- TIME(i):
- • Made up of hour:minute:second plus i additional digits specifying fractions of a second
- • format is hh:mm:ss:ii...i
- TIMESTAMP:
- • Has both DATE and TIME components
- 2. Show all databases:
- SHOW DATABASES;
- 3. Access database:
- mysql -u [username] -p [database](will prompt for password)
- 4. Create new database:
- CREATE DATABASE [database_name];
- An error occurs if database exists, Check if the database is existing
- DROP DATABASE IF EXISTS [database_name];
- CREATE DATABASE [database_name];
- CREATE DATABASE IF NOT EXISTS Department;
- 5. Select database:
- USE [database_name];
- 6. Determine what database is in use:
- SELECT DATABASE();
- 7. Show all tables:
- SHOW TABLES;
- 8. Show table structure:
- DESCRIBE [table_name];
- 9. List all indexes on a table:
- show index from [table];
- 10. Create new table with columns:
- CREATE TABLE DEPARTMENT
- ( DNAME VARCHAR(10) NOT NULL,
- DNUMBER INTEGER NOT NULL,
- MGRSSN CHAR(9),
- MGRSTARTDATE CHAR(9) );
- 11. Adding a column:
- ALTER TABLE EMPLOYEE ADD JOB VARCHAR(12);
- The new attribute will have NULLs in all the tuples of the relation right after the command is executed; hence, the
- NOT NULL constraint is not allowed for such an attribute
- 12. Adding a column with an unique, auto-incrementing ID:
- ALTER TABLE [table] ADD COLUMN [column] int NOT NULL AUTO_INCREMENT PRIMARY KEY;
- 13. Inserting a record:
- (Insert a tuple for a new EMPLOYEE for whom we only know the FNAME, LNAME, and SSN attributes)
- INSERT INTO EMPLOYEE (FNAME, LNAME, SSN)
- VALUES ('Richard', 'Marini', '653298653')
- (Attribute values should be listed in the same order)
- INSERT INTO EMPLOYEE
- VALUES ('Richard','K','Marini', '653298653','30-DEC-92', '98 Oak Forest, Katy,TX', 'M',37000,'987654321', 4);
- 14. MySQL function for datetime input:
- NOW()
- 15. Selecting records:
- SELECT * FROM [table_name];
- SELECT <attribute list>
- FROM <table list>
- WHERE <condition>
- SELECT BDATE, ADDRESS
- FROM EMPLOYEE
- WHERE FNAME='John' AND MINIT='B’ AND LNAME='Smith'
- 16. Explain records:
- EXPLAIN SELECT * FROM [table];
- 17. Selecting parts of records:
- SELECT [column], [another-column] FROM [table];
- 18. Counting records:
- SELECT COUNT([column]) FROM [table];
- 19. Counting and selecting grouped records:
- SELECT *, (SELECT COUNT([column]) FROM [table]) AS count FROM [table] GROUP BY [column];
- 20. Selecting specific records:
- SELECT * FROM [table] WHERE [column] = [value]; (Selectors: <, >, !=; combine multiple selectors with AND, OR)
- 21. Select records containing [value]:
- SELECT * FROM [table] WHERE [column] LIKE '%[value]%';
- 22. Select records starting with [value]:
- SELECT * FROM [table] WHERE [column] LIKE '[value]%';
- 23. Select records starting with val and ending with ue:
- SELECT * FROM [table] WHERE [column] LIKE '[val_ue]';
- 24. Select a range:
- SELECT * FROM [table] WHERE [column] BETWEEN [value1] and [value2];
- 25. Select with custom order and only limit:
- SELECT * FROM [table] WHERE [column] ORDER BY [column] ASC LIMIT [value]; (Order: DESC, ASC)
- 26. Updating records:
- UPDATE [table] SET [column] = '[updated-value]' WHERE [column] = [value];
- UPDATE PROJECT
- SET PLOCATION = ‘Galle', DNUM = 5
- WHERE PNUMBER=10
- 27. Deleting records:
- DELETE FROM [table] WHERE [column] = [value];
- 28. Delete all records from a table (without dropping the table itself):
- DELETE FROM [table]; (This also resets the incrementing counter for auto generated columns like an id column.)
- 29. Delete all records without deleting schema in a table:
- truncate table [table];
- 30. Removing table columns:
- ALTER TABLE [table] DROP COLUMN [column];
- 31. Deleting tables:
- DROP TABLE [table];
- 32. Deleting databases:
- DROP DATABASE [database];
- 33. Custom column output names:
- SELECT [column] AS [custom-column] FROM [table];
- 34. Export a database dump :
- mysqldump -u [username] -p [database] > db_backup.sql
- 35. Use --lock-tables=false option for locked tables.
- 36. Import a database dump:
- mysql -u [username] -p -h localhost [database] < db_backup.sql
- 37. Logout: exit;
- 38. To eliminate duplicate tuples in a query result
- SELECT DISTINCT SALARY
- FROM EMPLOYEE
- -----------------------------------------------------------------------------------------
- Aggregate functions
- 1. Select but without duplicates:
- SELECT distinct name, email, acception FROM owners WHERE acception = 1 AND date >= 2015-01-01 00:00:00
- 2. Calculate total number of records:
- SELECT SUM([column]) FROM [table];
- 3. Count total number of [column] and group by [category-column]:
- SELECT [category-column], SUM([column]) FROM [table] GROUP BY [category-column];
- 4. Get largest value in [column]:
- SELECT MAX([column]) FROM [table];
- 5. Get smallest value:
- SELECT MIN([column]) FROM [table];
- 6. Get average value:
- SELECT AVG([column]) FROM [table];
- 7. Get rounded average value and group by [category-column]:
- SELECT [category-column], ROUND(AVG([column]), 2) FROM [table] GROUP BY [category-column];
- -----------------------------------------------------------------------------------------------
- Users functions
- 1. List all users:
- SELECT User,Host FROM mysql.user;
- 2. Create new user:
- CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
- 3. Grant ALL access to user for * tables:
- GRANT ALL ON database.* TO 'user'@'localhost';
- -----------------------------------------------------------------------------------------------
- MySQL Mathematical Functions
- 1. Count rows per group COUNT(column | *)
- 2. Average value of group AVG(column)
- 3. Minumum value of group MIN(column)
- 4. Maximum value of group MAX(column)
- 5. Sum values in a group SUM(column)
- 6. Absolute value abs(number)
- 7. Rounding numbers round(number)
- 8. Largest integer not greater floor(number)
- 9. Smallest integer not smaller ceiling(number)
- 10. Square root sqrt(number)
- 11. nth power pow(base,exponent)
- 12. random number n, 0<n < 1 rand()
- 13. sin (similar cos, etc.) sin(number)
- ------------------------------------------------------------------------------------
- MySQL String Functions
- 1. Compare strings strcmp(string1,string2)
- 2. Convert to lower case lower(string)
- 3. Convert to upper case upper(string)
- 4. Left-trim whitespace (similar right) ltrim(string)
- 5. Substring of string substring(string,index1,index2)
- 6. Encrypt password password(string)
- 7. Encode string encode(string,key)
- 8. Decode string decode(string,key)
- 9. Get date curdate()
- 10. Get time curtime()
- 11. Extract day name from date string dayname(string)
- 12. Extract day number from date string dayofweek(string)
- 13.Extract month from date string monthname(string)
- -----------------------------------------------------------------------------------
- #reset root password
- sudo /etc/init.d/mysql stop
- sudo mysqld_safe --skip-grant-tables &
- mysql -u root
- mysql> use mysql;
- mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
- mysql> flush privileges;
- mysql> quit
- sudo /etc/init.d/mysql stop
- sudo /etc/init.d/mysql start
- ---------------------------------------------------------------------------------------------------------------
- GITHUB
- 1.Adding an existing project to GitHub using the command line
- 1.Create a new repository on GitHub
- 2.Open Terminal
- 3.Change the current working directory to your local project.
- 4.git init
- 5.git add .
- 6.git commit -m "First commit"
- 7.At the top of your GitHub repository's Quick Setup page, click to copy the remote repository URL.
- 8.git remote add origin <remote_repository_URL>
- ----------------------------------------------------------------------------------------------------
- 2.Changing a remote's URL
- git remote -v
- git remote set-url origin <git_url>
- git remote -v // Verify new remote URL
- ---------------------------------------------------------------------------------------------------
- 3. Everyday Use
- 1. shows you which files have been modified since the last commit
- $ git status
- 2. $ git add <filename>
- ( if the file is untracked and you wish to add it to the project,
- git-add does it automatically for you.)
- 3. creates the new commit
- $ git commit -m "commit_msg"
- 4. can stored particular branch
- $ git push origin <branch_name>
- 5. getting the changes from the remote server, and merging them
- into the local tree.
- $ git pull
- (If conflicts occured should resolved, can view by git diff
- add file and again commit that file)
- 6. reviewing history
- $ git log
- 7. show commit content
- $ git show <commit_number>
- ----------------------------------------------------------------------------------------------------
- git branch
- 1. create a new branch
- git branch <branch_name>
- 2. checkout another branch
- git checkout <branch_name>
- 3.to delete a branch run from master branch
- git branch -d <branch_name>
- 4. merge branches run from master branch
- git merge <branch_name>
- ------------------------------------------------------------------------------------------------
- Revert a commit
- SYMFONY
- Composer
- 1. Update all dependencies of current project
- composer update
- 2. Install dependencies for current project with versions defined in composer.lock
- composer install
- ----------------------------------------------------------------------------------
- Console
- 1. List available commands and show the Symfony version
- php app/console
- 2. Display help for given command
- php app/console help [command]
- 3. Display all configured public services
- php app/console container:debug [--show-private] [service_name]
- 4. Dump all assets to the filesystem
- php app/console assetic:dump
- 5. doctrine:schema:update
- Update the database with its new schema. Use with --dump-sql and --force
- -----------------------------------------------------------------------------------
- Cache
- Clear the cached information
- php app/console cache:clear
- In Server
- php app/console cache:clear --env=prod
- (After clearing cache should set permission to execute following files)
- sudo chmod 777 -R app/logs app/cache
- -----------------------------------------------------------------------------------
- Bundle
- Install bundles web assets under a public web directory
- php app/console assets:install <target_dir> [--symlink] [--relative]
- -----------------------------------------------------------------------------------
- Routing
- Display current routes for application
- php app/console router:debug | grep [router_name]
- -----------------------------------------------------------------------------------
- Logger
- $logger = $this->get('logger');
- $logger->debug("===================================================================");
- JITSI
- JItsi locally setup in your computer---------------
- 1.git clone <the link>
- 2.sudo n lts (take the long term support version)
- 3.npm install
- 4.make
- 5 ./node_modules/.bin/webpack-dev-server // start the server
- 6. ./node_modules/.bin/node-sass css/main.scss css/all.bundle.css && ./node_modules/.bin/cleancss css/all.bundle.css >
- css/all.css ; rm css/all.bundle.css // compile css
- PM2
- PM2 is a production process manager for Node.js applications with a built-in load balancer.
- It allows you to keep applications alive forever, to reload them without downtime and to facilitate
- common system admin tasks.
- Install pm2
- npm install pm2@latest -g
- # Fork mode
- pm2 start app.js --name my-api # Name process
- # Listing
- pm2 list # Display all processes status
- # Logs
- pm2 logs [--raw] # Display all processes logs in streaming
- pm2 flush # Empty all log files
- pm2 reloadLogs # Reload all logs
- # Actions
- pm2 stop all # Stop all processes
- pm2 restart all # Restart all processes
- pm2 reload all # Will 0s downtime reload (for NETWORKED apps)
- pm2 stop 0 # Stop specific process id
- pm2 restart 0 # Restart specific process id
- pm2 delete 0 # Will remove process from pm2 list
- pm2 delete all # Will remove all processes from pm2 list
- -----------------------------------------------------------------------------------------------------------------
- Add Another Mail Account To Gmail
- gmail → setting → Accounts and Import → Add another email adress
- smtp.zoho.com
- zoho → settings → configure IMAP → click IMAP check box
- verify and paste confirmation code
- ----------------------------------------------------------------------------------------------------------------------------
- FREEESWITCH
- #Freeswitch terminal restart
- fs_cli restart
- #shutdown
- fs_cli -x “shutdown”
- #run freeswitch
- 1. sudo su
- 2. go to bin ==> cd /usr/local/freeswitch/bin
- 3. ./freeswitch
- #Backing up and restoring your Raspberry pi’s SD card
- df -h ==> show all the available space
- again insert SD card and run ==> df -h
- /dev/mmcblk0p1
- /dev/mmcblk0p2
- then terminal
- sudo dd if =/dev/sdb of=~/SDCardBackup.img
- ----------------------------------------------------------------------------------------------------------------------------
- Vim
- #Delete Multiple Lines
- shift + v ==> Go to visual mode
- Select necessary lines
- delete
- #Copy terminal output into file
- 1. triple-click the last line
- 2. hit shift + home
- 3. shift + click first line
- 4. copy ctrl +shift + c
- You can then paste the content to other text document
- NANO
- #exit with save
- Ctrl +X ---→ y --→ enter
- -----------------------------------------------------------------------------------------------------------------------------
- Angular2
- 1. Create Component Using Terminal
- ng generate component <component_name>
- ----------------------------------------------------------------------------------------------------------------------------
- REACT-NATIVE
- #Run android project
- react-native start
- react-native run-android
- -----------------------------------------------------------------------------------------------------------------------------
- IMPORTANT WEB PAGES
- #Get know your screen resolution
- whatismyscreenresolution.net
Add Comment
Please, Sign In to add comment