Category:Linux

From ElectroDragon
(Redirected from Nano Editor)
Jump to: navigation, search

Commands

Category Command Description example example description


File/Folder cd change directory
  • cd ..
  • cd /
  • cd .
-
File/Folder cat print file content to screen - -
File/Folder touch change file to current system time, or create new file - -
File/Folder mkdir make directory mkdir -m 700 electrodragon -m for mode 700
File/Folder tailf diplay the last 10 lines of the file tailf /srv/www/logs/www*access.log -
File/Folder pwd list current folder pwd -
File/Folder cp copy file cp -r folder /home/
File/Folder rm -rf remove the file or folder, r=? f=force -
File/Folder
  • ls -l
  • ls -a
list the user and group -a include all files ls -l
  • drwxrwxr-x 1 root root 8192 Nov 10 03:18 SSK
  • 3th root = user, 4th root =group, SSK folder name
  • -a show all files and folders
  • -l show in long mode
  • -R Recursively
File/Folder mv move or rename files and folders mv /usr/lib/* /zone

File/Folder Right

Basic

root@www:~/sh# ls -al
total 32
drwxr-xr-x  4 root root 4096 Dec 13 06:26 .
drwx------ 10 root root 4096 Dec 13 05:56 ..
-rwxr-xr-x  1 root root 1226 Dec 13 05:48 backup.sh
drwxr-xr-x  3 root root 4096 Dec 13 05:42 bk
drwxr-xr-x  8 root root 4096 Dec 13 06:04 .git
-rwxr-xr-x  1 root root  561 Dec 13 06:03 loadmonitor.sh
-rwxr-xr-x  1 root root    0 Dec 13 06:26 mem.sh
-rwxr-xr-x  1 root root  778 Dec 13 06:00 nginx_log.sh
-rwxr-xr-x  1 root root  280 Dec 13 05:48 uptime.sh

For line drwxr-xr-x 3 root root 4096 Dec 13 05:42 bk

  • d is directory, rwx is write/read/run right, 1st group for owner, 2 for group, 3 other users
Category Command Description example example description


File/Folder Right chown change folder owner and group
  • chown -R oracle:oinstall /home/pi
  • chown root:debian-transmission SSK
  • oracle is user, oinstall is group
  • set user root and group debian-transmissoin for folder SSK
File/Folder Right chmod change folder/file permission chmod -R 700 /opt/oracle 700 is the permission, R means folder and files, recursive
File/Folder Right usermod -a -G Add the user to the supplementary group(s). Use only with the -G option. usermod -a -G pi debian-transmission add debian* to pi group
File/Folder Right Usermod -G add user to a group usermod -G root pi add user pi to root group
File/Folder Right
  • id
  • whoami
  • groups: groups <user>
  • passwd
  • su switch user
  • sudo get root right
  • check user in which group
  • groups root
  • root : root indiecity debian-transmission
File/Folder Right chgrp change group
  • chgrp debian-transmission /mnt/usbel/Torrents/mytrasnmission/incomplete
  • chgrp debian-transmission /mnt/usbel/Torrents/mytrasnmission/complete
change folder group

User and Group

  • userdel username

Net

Category Command Description example example description
User right groupadd or groupdel add/del new group groupadd group1 -
User right alias
  • set alias name for command
  • add alias on boot: ~/.bashrc for single user
  • or /etc/bashrc or /etc/bash.bashrc for all user (ubuntu, lubuntu)
  • reboot to make it work.
alias p="pwd" or p='pwd'
Net ping ping ip address ping 192.168.0.1
Net ifconfig show network info ifconfig
Net wget download a file from internet


System

Category Command Description example example description
System-package apt-get install, remove, update, remove --purage package apt-get install install package
System-package sudo dpkg -i debfile install *.deb package


System su switch user su
System lsusb, lsmod list usb, modules - -
System dmesg Boot info - -
System crontab -e run programme periodically
  • 0 0 * * * rm -rf /tmp/motion/*.* # rm all the files in motion folder at 0:0
  • 0 */2 * * * /sbin/service httpd restart # restart httpd every two hours
-
System help help command - -
System man show manual man update-rc.d -
System ps -x show current process - -
System top system status - -
System hostname show/edit hostname hostname moon change hostname to "moon", also need to change /etc/hosts
System ps show process
  • ps -A | grep ssh*
  • ps -ef | grep mosquitto
check if service ssh on or off
System free -m
  • check free memory
  • #total: Total memory size;
  • #used: memory has been used;
  • #free: free memory;
  • #shared: shared memory size;
  • #buffers: used for buffer memory;
  • #cached: used for cache memory
- -

Disk

Category Command Description example example description
System-disk df check the size of disk df -h -h human read
System-disk du check size of folders du -sh /* -h human read -s conclusion

ZIP

Category Command Description example example description
File/Folder tar zip or unzip
  • tar –cvf jpg.tar *.jpg // pack all *.jpg to zip file jpg.tar
  • tar –cvzf jpg.tar.gz *.jpg // pack all *.jpg to zip file jpg.tar.gz
  • tar –cvjf jpg.tar.bz2 *.jpg // pack all *.jpg to zip file jpg.tar.bz2
  • -c: create zip file
  • -x:unzip zip file
  • -z:make gzip type gz file
  • -j:make bz2 type bz2 file
  • -v:verbose display process
  • -f: last option and followed by file name

Screen

  • Screen, sync SSH to Serial of RPI -> Install first sudo apt-get install screen -> screen /dev/ttyAMA0/ 115200

Packages

Nano

Install

ubuntu@ubuntu:~/c_enviroment/sample$ sudo apt-get install nano

A simple tutorial on how to use nano is: http://www.howtogeek.com/howto/42980/the-beginners-guide-to-nano-the-linux-command-line-text-editor/

One thing you may notice with this sketch, it compiles to the command line. This example shows how you can pass parameters to the sketch when calling it from the command line. This is optional as you will see in some of the other sketches, but does add some benefit to writing sketches to run on the pcDuino.

Commands

use Ctrl + O to save file use Ctrol + X to quit

More info can see on this page.

Common

  • Vi: type i to edit, type esc to exit edit mode, type :x to save editing
  • screen
Name Type available in description
neo4j Example Example
Napkin Example Example
JRuby Example Example
Java coding Example
ssh network Example
git coding Example
lsof Example Example
libc6-armel Example Example
Bash common Example
Busybox Example Example
cpulimit system Example
Transmission network openwrt
Shadowsocks network openwrt
mjpeg streamer video Example
Linux Motion video Example
Nano editor Example
opkg system Example
perl coding Example
vsftpd network Example
wget network Example
yaaw network Example
Htop system Example monitor system status
Psensor system Example monitor CPU status
apache2 internet Example apache internet server
nginx internet Example widely used internet server, maybe better than apache2
Php5 internet Example lanuage
mysql internet Example database
  • matchbox-keyboard florence sudo
  • apt-get install gdebi
  • sudo apt-get install synaptic

rSync file

Basic syntax of rsync command - rsync options source destination Sufffix

Header text Header text Header text
Example -v verbose
Example -r copies data recursively (but don’t preserve timestamps and permission while transferring data
Example -a archive mode, archive mode allows copying files recursively and it also preserves symbolic links, file permissions, user & group ownerships and timestamps
Example -z compress file data
Example -h human-readable, output numbers in a human-readable format
Example -z compress during transfer
Example -H, --hard-links keep the hard links
Example -S, --sparse sparse file special treatment to save DST space

Examples

Type Header text Header text
Basic
  • rsync -avSH /home/coremail/ /cmbak/
  • rsync -azv /var/opt/installation/inventory/ /root/temp/
copy local file from /home/coremail to /cmbak
Example Example Example
Example Example Example

Open windows software

  • install app win: apt-get install wine


Proxy

SS client

  • apt-get install shadowsocks
  • sslocal -c ss.json

Proxy - ProxyChains

  • proxychains > tsocks

Proxy - Polipo

  • Install polipo: apt-get install polipo
  • config /etc/polipo/config
proxyAddress = "0.0.0.0"
socksParentProxy = "127.0.0.1:1080"
socksProxyType = socks5
chunkHighMark = 50331648
objectHighMark = 16384
serverMaxSlots = 64
serverSlots = 16
serverSlots1 = 32
  • restart it: /etc/init.d/polipo restart
  • restart and try:
export http_proxy="http://127.0.0.1:8123/"
curl www.google.com
  • proxychains: /etc/proxychains.conf
  • tsocks: sudo nano /etc/tsocks.conf

Find IP in LAN:

  • install nmap: sudo apt-get install nmap
  • nmap -sn 192.168.1.0/24

or use netdiscover

  • sudo apt-get install netdiscover
  • sudo netdiscover -r 192.168.1.0/24 -i wlan0
  • change wlan0 to eth0

Send udp data to a IP

  • sendip -p ipv4 -is 192.168.1.81 -p udp -us 5070 -ud 5060 -d "Hello" -v 192.168.1.81
  • Refer to ESP Light

Media

  • media play with omxplayer, command: omxplayer example.mp3
  • to force output : omxplayer -o hdmi example.mp3
  • or: omxplayer -o local example.mp3
  • Use lxmuisc or VLC: apt-get install lxmusic
  • Omx GUI player TBOplayer


Use Minidlna

sudo apt-get install minidlna
  • edit connf for minidlna /etc/minidlna.conf
port=8200
media_dir=/media/
friendly_name=dlna

restart it

sudo /etc/init.d/minidlna force-reload

opkg package management

  • list-installed
  • remove
  • update
Openwrt opkg configuration.png

System Configue

Linux System Configure File

Header text Header text Note
cat /var/log/kern.log kernal log -
cat /proc/cpuinfo cpu info -
/etc/hosts hosts file
nano /etc/passwd edit users
  • test:x:503:503::/home/test:/bin/bash
  • set the user: login name, password, ID, groupID, comment paragraph, main directory, shell, etc
nano /etc/group edit groups
  • debian-transmission:x:117:root,pi
  • user root and pi are in group debian-transmission

Set Path

  • Set path in ~/.bashrc, or ~/.bash_profile
  • Add line for esp: export PATH=$PATH:$HOME/esp/xtensa-esp32-elf/bin
  • Or use alias: alias get_esp32="export PATH=$PATH:$HOME/esp/xtensa-esp32-elf/bin"
  • echo $PATH: output: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/he/esp/xtensa-esp32-elf/bin
  • verify: xtensa-esp32-elf-gcc -v

Set System Auto Start

  1. ’‘’init.d‘’‘ directory names within directory put the startup script for each service, such as sshd, httpd etc.
  2. ‘’‘rcX.d’‘’ directory name, followed by the X stands for each run level. Each service within the directory has links to the startup script file in the init.d, according to the file name link to the start-up state. K said they did not start at the beginning of the service, S starts showing links rc.local file to start the service, referring to the /etc/rc.d/
  3. ’‘’rc.local‘’‘ After the system is initialized and services are ready, the final execution of a script, you can put some simple scripts which
  • Methods /etc/rc.d/rc.local or /etc/rc.local
  • Methods update-rc.d: this can run it as service, /etc/init.d/

Disk Operation

Main Header text Header text
check available disk fdisk -l Example
check disk and also mounted on df -h Example
list the mounted disk lsblk Example
list usb disck lsusb
mount disk
  • mount -t ntfs /dev/sda1 /mnt/
  • mount -t auto /dev/sda1 /media/SSK

Mount Disk

  • Install ntfs-3g format: apt-get install ntfs-3g
  • Error cause ((device sda1): load_system_files(): $LogFile is not clean. Mounting read-only. Mount in Windows.)
  • mount on start, first run: sudo blkid

you will see

/dev/mmcblk0p1: SEC_TYPE="msdos" LABEL="boot" UUID="15CD-3B79" TYPE="vfat"
/dev/mmcblk0p2: UUID="13d368bf-6dbf-4751-8ba1-88bed06bef77" TYPE="ext4"
/dev/sda1: LABEL="SSK" UUID="C494B1E694B1DADE" TYPE="ntfs"
  • edit fstab: sudo nano /etc/fstab
  • insert the ntfs type: UUID=DA9C8D0E9C8CE5FB /media/disk ntfs gid=root, uid=root, dmask=002, fmask=113 0 0
  • which means <file system> <location> <type> <gid?> <uid?> <dmask to directories> <fmask applies to files> <?> <?>


  • you have to format it to ext3 or ext4 format firstly, use commoand mkfs.ext3
  • change group and write permission that is the same process above
  • operation not permitted

MISC

Set Command -
Hosts DNS /etc/hosts for DNS -
hostname /etc/hostname -
Alias nano ~/.bashrc -
Run on daemon
  • nohup python main.py &
  • check -> ps ax | grep test.py

Set password for Ubuntu or Lubuntu

  • sudo passwd -> enter current password, and enter new password for root
  • su root -> use the passwod just set can login, can now set

OS

Grub

  • sudo vi /etc/default/grub
  • GRUB_CMDLINE_LINUX="" -> GRUB_CMDLINE_LINUX="text"
  • sudo update-grub
  • sudo systemctl set-default multi-user.target, and you can revert it later by -> sudo systemctl set-default graphical.target

Debian Installation

  • Download CD1 and start install, use network install too to install KDE or gnome graphic desktop

Toolchain

Normal on PC

  • gcc: gcc -o helloword helloword.c

Openwrt

  • openwrt compiler: /openwrt/staging_dir/toolchain_mispel_...../bin/mispel-openwrt-linux-gcc -o helloword hellworld.c
  • to fix error - environment error'STAGING_DIR'not defined, run - export STAGING_DIR=/openwrt/staging_dir/
  • to set openwrt complier absoulte directory run - nano /etc/environment, add directory path after ":", run - source environment to make it work, finall command will be mispel-openwrt-linux-gcc

Tools

  • FileZilla
  • WinScp
  • SecureCRT
  • Xshell

reference

Pages in category "Linux"

The following 7 pages are in this category, out of 7 total.