User Tools

Site Tools


Sidebar



linux

Table of Contents

Linux

add user to dialout group for usb serial port write access

sudo usermod -aG dialout <myuser>

important beginners info

find files recursively modified in the last 5 minutes

find -cmin -5

vagrantup

read lines from file

#!/bin/bash
while read url; do
   #do something with $url
done < file.txt

add user

useradd jsmith
passwd jsmith
mkdir /home/jsmith
chown jsmith:users /home/jsmith

List All Environment Variables

env

count number of files in directory

ls -1 | wc -l

rights

chmod +x filename   # user,group and others execute rights
chmod u+x filename  # user execute rights
chmod go-x filename # group and others no execute rights
chmod u+rwx,go+rw   # user read/write/execute, groups and others only read/write

more info: https://www.linode.com/docs/tools-reference/linux-users-and-groups

add ssh access for user

check /etc/passwd to see if the shell is set.

primary and supplementary groups

id -a <user>

The supplementary groups give access to resources, but any new files are created with primary group.

newgrp

You can change a users currently active primary group using the newgrp command.

see which groups a user belongs to

groups username

or check:

/etc/group

add user to group

usermod -g group username

less with color interpretation

less -r filename

install libpng

sudo apt-get install libpng++-dev

install autoconf2.59

sudo apt-get install autoconf2.59

nmap portscanner

nmap localhost

who

w
who
whoami

remove last line from known_hosts (on MacOSX)

sed -i '' -e '$ d' ~/.ssh/known_hosts 

hostname

/etc/hosts
/etc/sysconfig/network
/etc/HOSTNAME
hostname
hostname -f

mail

/var/log/maillog
postqueue -p

find lines not starting with #

grep -v '^#' filename

remove reoccurring lines from textfile

sort file.txt > sorted.txt
uniq sorted.txt > uniq.txt

recursive touch

find . -exec touch {} \;

hex characters to port

echo -e -n "\xFF\x01\x00\x04\x3F\x00" > /dev/tts/1

-e enable interpretation of backslash escapes
-n do not output the trailing newline

execute a script in the current shell

. .profile

terminal type / colors / characters

export TERM=xterm-256color

less

in less kun je zoeken door '/' te typen

copy mysql database from one server to another

mysqldump -u user -p db-name > db-name.out
scp db-name.out user@remote.box.com:/backup

on other server:

mysql -u user -p db-name < db-name.out

zip a folder excluding a subfolder

zip -r kadaster.zip kadaster -x kadaster/clouds**\*

login as different user

su -

list all files with full path

ls -lad $PWD/**

list of all running processes

ps auxw

see open ports per process

netstat -nlp

-n = no name lookup

see processes as a tree

pstree -a|less

get server date/time

date

set server date/time

sudo date -s 'Sun Feb 10 14:00:00 CET 2013'

chmod htaccess to make it writable by wordpress

chmod 666 .htaccess 

read

read -a VERSION -p "Version number: "
echo $VERSION

zip

zip -r file.zip folderToZip

get dir of script

BASEDIR=$(dirname $0)

cd to homedir

cd

cd back to previous folder

cd -

empty a textfile

: > clouds.log

log files

exim

see exim

broadcom wifi driver info

extra info over een PID

sudo strace -p 28976

color file listing

alias ls='ls -G

recursive find

find / -name laoscfg.ps

find string in files

#find . | xargs grep 'string' -sl
grep -r "string" .

follow tail of file and cut lines that are too long

tail -f filename | cut -c -$COLUMNS

robots.txt

# no search engine indexing
User-agent: *
Disallow: /

apache access_log

de apache access_log files per domein staan hier: /var/log/httpd/domains. Als je in deze map ls -altr uitvoert zie je welke bestanden het laatst gewijzigd zijn.

ftp

de ftp server logt hier: /var/log/proftpd/access.log

long file list sorted by time

ls -altr

see who's logged in

w

add /usr/sbin to path

add this to ~/.bash_profile

PATH=$PATH:$HOME/bin:/usr/sbin
export PATH

moving files starting with certain letter

mv [a-l]* ../directory2

find folders over 1GB

du -h / | grep ^[0-9.]*G

free space on disk

df -h

size of folder

disk usage human readable format

du -h folder/

taskmanager in the terminal

top or htop

get the folder in which a script resides

$(dirname $0)

edit desktop system monitor in crunchbang

~/.conkyrc

don't see characters when typing in terminal

stty -echo

or

stty echo

list files

Force output to be one entry per line.

ls -1

(-1 = 'number one')

[test@server korea]$ ln -s ../clouds.mov clouds.mov
[test@server korea]$ ln -s ../seasons.mov seasons.mov
[test@server korea]$ ln -s ../oneday.mov oneday.mov

ps & grep

grep -x matches exact line

ps ax -o cmd | grep -x 'php crawler.php'

empty a textfile

echo "" > clouds.log

find location of executable

type php

or

which php

gives:

php is /usr/local/bin/php

or

type ls
ls is aliased to `ls --color=tty'

nohup

Keep a process running after closing your ssh connection (ignore the SIGHUP):

nohup php crawler.php > foo.out 2> foo.err < /dev/null &

AVR / avrdude etc

Zie Arduino

list open files

lsof

ugly way to rename files in a folder to a sequence

put this in a .sh script.

counter=0
for file in *.jpg
do
counter=`echo "$counter + 1" | bc`
mv "$file" $counter.jpg
done

other way rename files to sequence depending on file count in folder

for file in folderA/*.png
do
  counter=`ls -1 folderB/ | wc -l | tr -d ' '`
  mv $file folderB/$counter.png
done

remove files older than 7 days

find /home/user/*.jpg  -mtime +7 -exec rm -f {} \;

Tips

Een hoop linux tips en trucks zijn aan bod gekomen tijdens OpenToko 20 over Linux

get the name and version of your linux distribution

lsb_release -d -s -c

handig tooltje om chmod getallen/letters uit te rekenen

reset file rights recursively

find . -type f -print | xargs chmod 644

reset folder rights recursively

find . -type d -print0 | xargs -0 chmod 755

Install font on crunchbang

sudo mv fontname.ttf /usr/share/fonts/truetype

Verder

gksudo gedit /boot/grub/menu.lst

(kdesu heeft hetzelfde effect?)

ls

list with one column

export COLUMNS=1
ls

useradd

Als ie useradd bijvoorbeeld niet kan vinden of iets anders essentieels kan dat komen omdat soms /usr/sbin niet in het zoekpad staat.

restart ssh deamon

see ssh

.htaccess

.AIR bestanden als binary laten downloaden in .htaccess:

 AddType application/vnd.adobe.air-application-installer-package+zip .air 

GIT

See git

Display problems / tips

  • Laptop beeldscherm knippert / flikkert in Ubuntu. Mogelijke oplossing: Probeer bij Administration/Screen and Graphics de 'Intel Experimental mode' te veranderen in i810.
  • start screen and graphic preferences:
displayconfig-gtk

Terminal

  • find an application's location:
whereis firefox
  • find a file's location:
locate menu.lst
  • reboot the system:
reboot
  • to tar a folder (with all subfolders and files):
tar czf backup.tgz thefolder
  • to untar a file:
tar xvzf file.tar.gz
  • search for a phrase in all files:
grep something *
  • search for a phrase in all files (recursive):
find . | xargs grep -s phrase
  • to start ubuntu without GUI empty '/etc/X11/default-display-manager'. If you want to start it from the shell type 'gdm'
  • What to do when 'locate' gives the following error 'can not open `/var/lib/mlocate/mlocate.db': No such file or directory'?
sudo updatedb
  • cat - Concatenates files, or standard input, to standard output:
cat newmpeg.txt >> daily.txt
  • Alle processen weergeven met hun PID's
ps -A
  • zoekt naar naam binnen de actieve processen
ps -C naam
  • een proces beeindigen:
sudo kill 5943
  • copy a directory:
cp -r /home/hope/files/* /home/hope/backup
  • show last system messages:
tail /var/log/messages
  • tail and keep watching (follow)
tail -f foo.out
  • get computer name / hostname
hostname

Installing software or libraries

  • You can use 'sudo apt-get install thunderbird' for installing software like thunderbird or any other program.
  • You can use 'sudo apt-build install libfreetype6' for installing a library. You can also use apt-get for that by saying: 'apt-get build-dep libfreetype6'
  • Use 'sudo dpkg -i filename.deb' to install a download .deb file.
  • Install RPM packages:
rpm -i software-2.3.4.rpm
  • of gebruik:
alien -i filename.rpm
  • In case of the following message “error while loading shared libraries: libstdc++-libc6.2-2.so.3: cannot open shared object file: No such file or directory” while installing/running something install the glibc library:
sudo apt-get build-dep glibc
  • 7-Zip installeren op Ubuntu
sudo apt-get install p7zip

Shell scripts

  • .sh extensie
  • execute a script in a terminal:
xterm -e /home/fileToExecute

Networking

  • “If you want to mount your NFS and samba file systems on ubuntu client machines you need to use the /etc/fstab file (short for filesystem table) keeps track of filesystems that you want to mount in static locations.”
  • You can use NFS for this with adding the share to /etc/exports on sharing computer. You can then mount to that from the client computer by creating an empty folder (ie. /mnt/testfolder) and then say:
mount 192.1680.104:/home/rick/srcfolder /mnt/testfolder
  • Na een wijziging in het /etc/networking/interfaces moet er een restart worden gegeven
sudo /etc/init.d/networking restart
  • Het instellen kan ook met ifconfig.
sudo ifconfig eth0 192.168.1.50 netmask 255.255.255.0 up
  • Networkadapter down:
ifdown eth1
  • Networkadapter up:
ifup eth1
  • For permanent changes in your network address change your network configuration file '/etc/network/interfaces'. more info

Arduino

Scite

C++

  • Time time; time.fileNameTag()

Hardware / USB

  • zoeken naar usb apparaten met 'ph' in de naam. (-vvvv is extra verbose)
lsusb -vvvv | grep ph

*list all devices?

ls /dev/

Advanced

  • To disable gdm, from Gnome click System/Administration/Services and unclick Graphical Logic Manager (gdm)

Video

  • Exporteer de eerste 9 files uit een AVI naar losse jpg's: mplayer test.avi -vo jpeg -ao null -frames 9
  • Speel test.avi af in een x11 venster, maar het kan ook bijv. een video-out zijn: mplayer test.avi -vo x11

Swap Control + Command on Linux on Mac

xmodmap -e 'keycode 133=Control_L'
xmodmap -e 'keycode 37=Super_L'
xmodmap -e 'keycode 134=Control_R'
xmodmap -e 'keycode 109=Super_R'

using wine

Use wine to run Windows programs on linux.

sudo apt-get install wine
winecfg
sudo usermod -aG dialout <myuser>
sudo ln -sf /dev/ttyUSB0 ~/.wine/dosdevices/com1 
sudo ln -sf /dev/ttyACM0 ~/.wine/dosdevices/com2 
unzip Minibloq.v0.8.Beta.zip
cd Minibloq.v0.8.Beta
wine MinibloqRun.exe

changing .htaccess to get rid of doku.php

RewriteEngine on
 
RewriteBase /
 
RewriteRule ^_media/(.*)              lib/exe/fetch.php?media=$1  [QSA,L]
RewriteRule ^_detail/(.*)             lib/exe/detail.php?media=$1  [QSA,L]
RewriteRule ^_export/([^/]+)/(.*)     doku.php?do=export_$1&id=$2  [QSA,L]
RewriteRule ^$                        doku.php  [L]
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteRule (.*)                      doku.php?id=$1  [QSA,L]

Using multiple monitors for in Ubuntu

gksudo nvidia-settings

install other window manager

how to kill the screen command

Ctrl+A, Ctrl+\
more tips http://ss64.com/osx/screen.html

replace characters

tr '\n' ' ' < doit.sh> out.sh && ./out.sh
linux.txt · Last modified: 2016/04/05 11:53 by rick