Linux
Linux general commands

User & Group Management

Purpose Command
new group groupadd sambashare
new user useradd -m -g users -G sambashare -s /bin/bash unix_user
change password passwd unix_user
rename user usermod -l newUsername oldUsername and change home folder usermod -d /home/newHomeDir -m newUsername
change to root sudo -i
remove user deluser --remove-home username

User with sudo rights

useradd --create-home --gid users --shell /bin/bash userName
passwd userName
visudo -f /etc/sudoers.d/sudoers

# User privilege specification
userName    ALL=(ALL:ALL) ALL

Samba Management

Purpose Command
new user pdbedit -a -u samba_user
change password smbpasswd samba_user

File and Directory Handling

Find & Remove

specific files

find <path> -name '<file-name>' -delete

If something “more portable” needed then you’re better off with

find <directory name> -name '*.pyc' -exec rm {} \;

File Manipulation

search the line which begins with var feature server and replaces the whole line with var featureserver = "http://featureserver.org/fs"

sed -e 's%^var featureserver.*%var featureserver = "http://featureserver.org/fs"%g' featureserver.org/assets/js/map.js > ${tmp}/website/assets/js/map.js

template command is as follow, where the first character after s is used as separator and afterwards it comes a regex. Use -i to do an “in place” replacement (no need for pipe)

sed -ie 's/$search_for/$replace_with/g' $file

Folder size

-h
human readable file size
-s
sum all subfolders
du <directory>

Compression

tar -cvzf <file.tar.bz2> --exclude-vcs --exlude='*.svn' folder/

Extraction

tar -zxvf <file.tar.bz2>

Errors

When you get a error that the command is not found (e.g. -bash: $'\r': command not found) and you are sure everything is correct, then it has something to do with the file format or the characters.

Error: -bash: $'\r': command not found

Remove trailing \r character that causes this error:

sed -i 's/\r$//' filename

Option -i is for in-place editing, we delete the trailing \r directly in the input file. Thus be careful to type the pattern correctly.

Synchronization

Synchronization

:::bash
#! /bin/bash
rsync -av --delete <from> <to> > <log> &

Cloning

burning image to disk (also usb drives)

optional use bs=8192

dd if=<path>.iso of=<disk>

Job / Programs

Keep job running despite of a logout

nohup <command> &

System information

dmidecode -t [bios, system, baseboard, chassis, processor, memory, cache, connector, slot] | more

Packages

getting installed packages including version number

time dpkg -l | perl -lane 'print "$F[1] : $F[2]" if m/^ii/'
comments powered by Disqus