Category:Linux

From ElectroDragon
Jump to: navigation, search

Commands

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
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 list the user and group 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 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 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-package apt-get install, remove, update, remove --purage package apt-get install install package
System-package sudo dpkg -i debfile install *.deb package
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
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
- -

Command Examples

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

Packages

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

  • rsync -azv /var/opt/installation/inventory/ /root/temp/

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

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

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/

System

  • Change hostname permanently, you should change both for debian based system
/etc/hosts for DNS
/etc/hostname
  • make alias permanently, add the command at the end of the following file
nano ~/.bashrc

Disk Operation

  • fdisk -l check available disk
  • df -h check disk and also mounted on
  • lsblk list the mounted disk, or lsusb to check disk attached but may not mounted
  • mount normal disk: mount -t ntfs /dev/sda1 /mnt/ or mount -t auto /dev/sda1 /media/SSK
  • 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=C494B1E694B1DADE /media/SSK ntfs gid=root,uid=root,dmask=002,fmask=113 0 0

  • umask sets them to both files and directories, while fmask only applies to files and dmask to directories
  • 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

Background running or Daemon

  • nohup python main.py &
  • check -> ps ax | grep test.py

OS

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 9 pages are in this category, out of 9 total.